Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

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.

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top