Real time with Rails

I am looking for a good way to use it in real time for my users in a Rails application (Phusion Passenger Server). Each channel may be different depending on the user, and I expect that each new element will be executed every 20-60 seconds. A periodic ajax request doesn't seem like the best way to do this for me.

I heard about a comet, and I thought about something like this: - Using a long XMLHttpRequest poll to wait for ping from the server - As soon as the server sends a ping request, the last elements with ajax - Run another XMLHttpRequest

Is there something wrong with this? Are there any simpler and better ways to do this?

Thanks, S.

+4
source share
2 answers

As for web applications (and Rails applications), in real time it is just an illusion. A long survey is a very close approximation. Unfortunately, it is not very suitable for Rails. Especially since the Passenger.

A lengthy survey requires a constant open connection for each user that does not scale on servers that were not designed to handle it (for example, Apache). Unfortunately, in fact, there are many servers designed for long-term scalability that go well with Rails. You can try the Shooting-Star server, but I really don't know how its performance compares with Passenger for your standard queries.

My personal opinion on a lengthy survey is a solution that needs a problem.

Indeed, you should ask yourself the following questions:

  • Are these updates with a high enough priority that they cannot wait 40 seconds?
  • What happens if updates are not received immediately?
  • Can my users focus on my application so much that waiting 15 seconds will negatively affect their experience?
  • What percentage of user attention does my application attract under normal use?
  • How long does it take to respond to an update?
  • Do you really need to be in real time?

Some of these questions ask other questions differently, but this kind of thing is necessary with such subjective questions.

I think you see what I get: real-time updates are very nice, but never needed. If you are working on something that the consequence of the inability to respond to real-time updates is the end of the world. You really should not develop it as a web application at all.

If you still mean real-time updates, you can check out Juggernaut . But this is a Flash based solution.

+4
source

Friendfeed built the Tornado server in Python, which they have open.

We examined a number of XMPP options that are pretty hard to configure before moving on to nginx_http_push_module . Durable GET HTTP requests connect to this, and the rails application pushes requests back to nginx. Nginx also proxies dynamic requests to the mogrels cluster. We have jQuery running, which opens a connection and then re-opens it on the server when it receives a message, or when there is an error. Thus, we can achieve almost real time updates in the style of Comet.

This blog post in the nginx module with an example ruby should help you get started (you need to compile nginx). Now we are developing it in development and plan to use it in production, if it is not unreliable, so good.

+4
source

All Articles