0

I am not sure what are the advantages for using Faye or some other push system and not use Ajax for it.

Specifically I mean for implementing chat and notification functionality.

If I make a chat message model, and in my post ( which has many chat messages) , in the post page I can use Ajax to refresh the messages and I get the chat functionality.

Am I missing something on Faye or with Ajax? Is it more efficient?

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
  • Faye can use websockets (two way, always on connection). Ajax is request/response (one way, one time connection). – Kris Aug 30 '12 at 16:22

1 Answers1

5

Faye is establishing a connection that the server can push data to the client with. With Ajax the client must request data and if it doesn't know that new data is available (which is the case in a chat client) then it must poll periodically for new content.

Is it more efficient? If the chat system sees enough traffic that your poll period is getting new data every time, probably not. If, on the other hand, you have an idle chat room then all of that polling is going to be chewing up resources that could be avoided by having the server push the data.

The flip side of this is that you are keeping a connection open with the server. This could work against you if you have a large number of idle clients. Because of this, it would be context sensitive as to which approach is better, or perhaps even a hybrid approach (opening a Faye connection for active use and then idling out to Ajax polling on an infrequent basis).

Godeke
  • 16,131
  • 4
  • 62
  • 86
  • Thanks. So Ajax is best used for minor updates or stuff that the client polls on them and push is best for major updates that might have a lot of clients needing that information? – Nick Ginanto May 24 '12 at 03:59
  • I think the short form is that Ajax is best when the update times are driven by a client's actions (interactions with the UI) and Faye has an advantage when the server may do unpredictable things that the UI really needs to reflect immediately. I could see major updates being accessed via Ajax (polling for update existence first, then pulling the update), as long as the *timeliness* isn't the critical concern. I have seen Ajax scripts set to poll every second: this is something I would contemplate using Faye for instead because I'm effectively emulating an open connection anyway. – Godeke May 25 '12 at 22:40