views:

2713

answers:

8

I am working on a simple notification service that will be used to deliver messages to the users surfing a website. The notifications do not have to be sent in real time but it might be a better user experience if they happened more frequently than say every 5 minutes. The data being sent to and from the client is not very large and it is a straight forward database query to retrieve the data.

In reading other conversations on the topic it would appear that an AJAX push can result in higher server loads. Since I can tolerate longer server delays is it worth while to have the server push notifications or to simply poll.

It is not much harder to implement the push scenario and so I thought I would see what the opinion was here.

Thanks for your help.

EDIT: I have looked into a simple AJAX Push and implemented a simple demo based on this article by Mike Purvis. The client load is fairly low at around 5k for the initial version and expected to stay that way for quite some time.

A: 

I would implement a poll just because it sounds simpler to write, and keeping it simple is very valuable.

matt b
+1  A: 

Not sure if you have taken a look at some of the COMET implementations out there (is that what you mean by AJAX push).

If the user is surfing the site, won't that in effect be requesting information from the server that this notification can piggy-back on?

Lou Franco
A: 

Because using a push requires an open HTTP connection to be maintained between your server and each client, I'd go for poll as well - not only is that going to consume a lot of server resources but it's also going to be significantly more tricky to implement as matt b mentioned.

My experience with polling is that if you have a frequent enough polling interval on a busy enough site your web server logs can get flooded with poll requests real quickly.

mmacaulay
+1  A: 

I haven't tried it myself, but some say COMET works and is easier than you think. There's also a Ruby on Rails plug-in called Juggernaut that I've heard talked about highly. Again, I haven't used it, so YMMV, but my understanding is that it takes far fewer resources compared to polling. I believe (can someone confirm?) that COMET is how MacRumorsLive.com delivers live blogging of WWDC Stevenotes.

Andrew Hedges
+1  A: 

It's impossible to say whether polling will be more expensive then pushing without knowing how many clients you'll have. I'd recommend polling because:

  • It sounds like you want to update data about once per minute. Unless notifications are able to arrive at a much faster rate than that, pushing would mean you're keeping an HTTP connection open but seeing very little activity on it.
  • Polling is built on top of existing HTTP conventions, so any server that talks to web browsers is already ready to respond to ordinary Ajax requests. A Comet– or Flash socket–based solution has different requirements; you'll need something like cometd on the server side and a client-side library that groks server-side push.

So if you needed something heavy-duty to manage a torrent of data and a crapload of clients, I'd recommend Comet. But that doesn't seem to be the case.

savetheclocktower
A: 

Thank you everyone for your responses. I have decided to go with the polling solution but to wrap it all within a utility library so that if they want to change it later it is easier.

smaclell
+1  A: 

Both have diferent requirements and address diferent scenarios.

If you need realtime updates, like in an online chat, push is a must.

But, if the refresh period is big, as it is in your case (5 minutes), then pool is the appropriate solution. Push, in this case, will require a lot of resource from both the client and the server.

Tip! try to make the page that checks the pool fast and clean, so it doesn't consumes a lot of resources in the server in each request. What I usually do is to keep a flag in memory (like in a session variable) that says if the pool is empty or not... so, I only do havy look in the pool only if it is not empty. When the pool is empty, which is most of the time, the page request runs extremely fast.

Daniel Silveira
Mmm interesting. Thank you for the suggestion, I will probably give it a shot.
smaclell
+5  A: 

Definitely use push its much cooler. If you just want simple notifications I would use something like StreamHub Push Server to do the heavy-lifting for you. Developing your own Ajax Push functionality is an extremely tricky and rocky road - you have to get it working in all browsers and then handle firewalls and proxies killing keep-alive connections etc... Why re-invent the wheel. Also, it has a similarily low footprint of less than 10K so it should suit if that is a priority for you.

Supertux
+1 for not developing it yourself
Kevin Monk