long polling vs streaming for about 1 update/second
Asked Answered
P

6

7

is streaming a viable option? will there be a performance difference on the server end depending on which i choose? is one better than the other for this case?

I am working on a GWT application with Tomcat running on the server end. To understand my needs, imagine updating the stock prices of several stocks concurrently.

Phototypography answered 3/7, 2009 at 18:12 Comment(0)
M
6

Do you want the process to be client- or server-driven? In other words, do you want to push new data to the clients as soon as it's available, or would you rather that the clients request new data whenever they see fit, even though that might not be once/second? What is the likelyhood that the client will be able to stick around to wait for an answer? Even though you expect the events to occur once/second, how long does it take between a request from a client and the return from the server? If it's longer than a second, I'd expect you to lean towards pushing the events to the clients, though the other way around, I'd expect polling to be okay. If the response takes longer than the interval, then you're essentially streaming anyway, since there's a new event ready by the time the client receives the last one, so the client could essentially poll continually and always receive events - in this case, streaming the data would actually be more lightweight, since you're removing the connection/negotiation overhead from the process.

I would suspect that server load to be higher for a client-based (pull) subscription, instead of a streaming configuration, since the client would have to re-negotiate the connection each time, instead of leaving a connection open, but each open connection in a streaming model would require server resources as well. It depends on what the trade-off is between how aggressive your negotiation process is vs. how much memory/processing is required for each open connection. I'm no expert, though, so there may be other factors.

UPDATE: This guy talks about the trade-offs between long-polling and streaming, and he seems to say that with HTTP/1.1, the connection re-negotiation process is trivial, so that's not as much of an issue.

Mieshamiett answered 7/7, 2009 at 17:34 Comment(2)
Hey rwmnau, the link you provided is illuminating. To answer your questions, I would like to push data to the users as soon as it is available.Phototypography
If you're looking to push data to the users as soon as you can, then I think the choice has to be streaming, since that will maintain a push-based connection. With a pull setup, you're waiting for the clients to ask, but with push, they'll have the data as soon as you give it to them. Let me know what you end up picking and why!Mieshamiett
W
4

It doesn't really matter. The connection re-negotiation overhead is so slim with HTTP1.1, you won't notice any significant performance differences one way or another.

The benefits of long-polling are compatibility and reliability - no issues with proxies, ports, detecting disconnects, etc.

The benefits of "true" streaming would potentially be reduced overhead, but as mentioned already, this benefit is much, much less than it's made out to be.

Personally, I find a well-designed comet server to be the best solution for large numbers of updates and/or server-push.

Wurth answered 1/4, 2010 at 3:45 Comment(0)
M
2

Certainly, if you're looking to push data, streaming would seem to provide better performance, if your server can handle the expected number of continuous connections. But there's another issue that you don't address: Are you internet or intranet? Streaming has been reported to have some problems across proxies, much as you'd expect. So for a general purpose solution, you would probably be better served by long poll - for an intranet, where you understand the network infrastructure, streaming is quite likely a simpler, better performance solution for you.

Mommy answered 10/7, 2009 at 18:38 Comment(0)
O
2

The StreamHub GWT Comet Adapter was designed exactly for this scenario of streaming stock quotes. Example here: GWT Streaming Stock Quotes. It updates the stock prices of several stocks concurrently. I think the implementation underneath is Comet which is essentially streaming over HTTP.

Edit: It uses a different technique for each browser. To quote the website:

There are several different underlying techniques used to implement Comet including Hidden iFrame, XMLHttpRequest/Script Long Polling, and embedded plugins such as Flash. The introduction of HTML 5 WebSockets in to future browsers will provide an alternative mechanism for HTTP Streaming. StreamHub uses a "best-fit" approach utilizing the most performant and reliable technique for each browser.

Ochs answered 13/8, 2009 at 17:4 Comment(0)
D
1

Streaming will be faster because data only crosses the wire one way. With polling, the latency is at least twice.

Polling is more resilient to network outages since it doesn't rely on a connection being kept open.

I'd go for polling just for the robustness.

Differentia answered 13/7, 2009 at 18:21 Comment(2)
I'd like to clarify that my question is regarding long polling and not traditional polling. Also, NIO should be a given.Phototypography
You're right, NIO breaks the thread per connection restriction, alleviating thread requirement.Differentia
G
1

For live stock prices I would absolutely keep the connection open, and ensure user alert/reconnection on disconnect.

Gwyn answered 5/8, 2009 at 20:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.