This problem pertains specifically to Nodejitsu, but similar effects seem to happen on other VPSes. I have a real time game using socket.io, and one thing I've noticed is that occasionally the server will wait an inordinate amount of time before responding. If multiple requests are sent during that timeframe, they behave as if they've all been queued up and processed at once. I suspect it's vaguely correlated to the presence of other users on the hardware shared (as is the case with any VPS).
Anyway, to test this out (and make sure that it wasn't due to my game's code), I built a minimal test case:
express = require('express')
http = require('http')
app = express()
server = http.Server(app)
io = require('socket.io').listen(server)
io.sockets.on('connection', function(sock){
sock.on('perf', function(data, cb){
cb([Date.now()]); //respond with the current time
})
})
app.get('/', function(req, res){
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Methods", "HEAD,GET,PUT,POST,DELETE")
res.header("Access-Control-Allow-Headers", "X-Requested-With")
res.end(JSON.stringify([Date.now().toString()])); //http equivalent of perf function
})
server.listen(process.env.PORT || 6655, function(){
console.log('listening now')
})
I had a simple blank HTML page with socket.io which would periodically send a perf
event and time how long it took for the callback to fire. And it still shows the same thing:
Note that the bar length represents the square root of the amount of time, not the linear quantity.
When instead of relying on socket.io, I use XHR to do a similar measurement of the current response time, the result is pretty similar, a lot of low latency responses (though with a higher baseline than websockets, as expected) and some occasional spikes that appear to pile up.
The odd thing is that if you open it up in multiple browser windows and different browsers, there seems to be a correlation between the different browsers (and the fact that it's totally absent or significantly less frequent on some servers) which seems to imply that it's a server side phenomenon. However, there are latency spikes that happen for some browsers but not others, and the two Chrome windows which are of the same session appear to be virtually exact duplicates, which suggests that it's something that happens locally (per computer, or per browser, networking wise).
From Left to Right: Chrome Incognito, Chrome (regular), Firefox, Chrome (regular)
Anyway, this has been confusing me for months and I'd really like to understand what is causing it and how to fix it.