Background
I use a Tornado-like server with support for long-polls. Each web pages a user clicks around to sets up a long poll to the server like this:
$.ajax({
type: 'GET',
url: "/mylongpollurl/",
dataType: 'application/json',
success: function(json) {
// I do stuff here
},
error: function(xhr, errText, ex) {
// If timeout I send a new long-poll request
}
});
Problem
I will now rely on data that I get from Fiddler monitoring all requests made from my browser (FF at the moment).
- Page 1 is loaded and the long poll request is made, now idling at server side.
- I click a link to page 2 and that page is loaded and setting up a long poll request, BUT the long poll request from page 1 is still idling at server side (according to Fiddler).
This means that I will stack all long poll calls when clicking around the page, thus end up with lots of active connections on the server (or are they maybe sharing connection?)
My thoughts
- As it's a Tornado-like server (using epoll) it can handle quite a lot of connections. But this fact is not to exploit in my opinion. What I mean is that I prefer not to have a timeout on the server for this case (were the client disappears).
- I know those stand alone pages better uses a common head and only swap content via ajax calls but this design we use today was not my call...
- The best way to solve this would probably be to have the connection reused (hard to pull off I think) or closed as soon as the browser leaves the page (you click to another page).
Thanks
-- MyGGaN