Description
What I did:
- Set up a simple example server -- code and logs can be found in this gist
- Point a browser at it with a console open -- I'll see it sending kittens but not much else
- Open more browsers. For every new client I open, I'll get an extra puppy back for every kitten sent.
What I'd expect:
An unimpeded flow of pets, really. I feed it kittens, I get back puppies.
What actually happens:
-
For 1 ~ 5 clients, everything is peachy. I'm getting 4 puppies for every 5 kittens, which is a pretty sweet deal.
-
Beyond 5 active clients, however, things start blocking. In the browser, I see kittens being sent, but it takes about 20 seconds before I get any puppies back. I'll often get 101+ in one go.
On the server side, I get the metrics every ten seconds, but not the usual debug output between two of those blocks.
-
Bringing the number of clients back to 5 immediately speeds up the kitten and puppy transport.
This can be observed in the
node.log
in the gist. There's also a v8.log that I ran through the tick-processor.
All things not being equal:
-
If I don't force polling and use websockets, I get wonderful throughput (tried 26 clients).
-
With FlashSocket, I get throughput although my browser somewhat dies from Too Much Flash (didn't dare to go beyond 7 clients).
-
Using volatile or not doesn't seem to make one bit of difference: beyond 5 tabs, stuff starts lagging.
-
Lowering 'polling duration' to 10 decreases the wait for puppies to, surprisingly, 10-ish seconds.
-
Removing the forced polling and using 2 browsers, one that uses websockets and one that doesn't... hey, that's interesting.
Using just the non-websockets browser exhibits the usual behaviour (problems beyond 5 tabs), but opening up 1 tab in the websockets-capable browser, the puppies suddenly start flowing again. It might be somewhat irregular -- at 1 websocket and 10 non-websocket tabs, I might see 10 puppies most of the times, sometimes a couple more, sometimes a couple less -- but most of the time it's allright, and at least the puppies keep coming.
Environment:
Node.js 0.4.9, Socket.io freshly pulled from the master repo, running on a Linux box. CPU load is not, at any point, a problem. Browsers were Chrome and Firefox 3, on a different machine in the local network.
Conclusion:
It seems to me it's an issue with the polling mechanism. Strangely enough it goes away if there's a websockets connection tagging along.