Monday 15 September 2014

javascript - High Latency with NodeJS -


This problem is especially related to nodjetsu, but other VPSs seem to have similar effects. I have a real-time game that is using socket.io, and one thing I have noticed is that sometimes the server will wait for an excessive amount before responding. If many requests are sent during that time frame, then they behave like they all have been queued and processed at once. I suspect that it is briefly correlated with the presence of other users on shared hardware (as is the case with any VPS).

However, to test it (and make sure that it was not my reason the code of the game), I made a case for the minimum test:

  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 ()], // current time Res.header ("access-control-permission-origin", "*") Res.header ("Access-Control-Allow- Res .header ("Access-Control-Allow-Headers", "X-Requested-With") Res End (JSON.stringify ([date.now (), "Result" .toString ()]); // http; perf function's http parallel}} server.listen (process.env.port || 6655, function () {console.log ('now listening')}) Code>  

I had a simple empty HTML page which was socket.io This time, a perf event and time, how long it took to callback fire, and it still shows the same thing:

 graph showing interval spike

Note that bar length shows the square root of the amount of time, not the linear quantity.

When instead of relying on the socket. Io, I use the XHR measurement timing similar to the current reaction, the result is very similar, very low latency The classes (although the website with the required high baseline, are required) and seem to be anything unusual spike that pile.

The strange thing is that if you open it in multiple browser windows and in different browsers, between different browsers (and the fact that it is completely absent or is too short on some servers) The relationship starts, which seems to be a server-side event, though there are latency spikes for some browsers, but not the other, and two chrome windows that are of the same session are virtually accurate duplicates, Which states that it happens at some local level (per computer or per browser, networking wise).

From left to right: chrome secret, chrome (regular), firefox, chrome (regular)

 charts on four windows

Anyway, this is confusing me for months and I really want to understand why this is happening and how to fix it .

I believe that you have checked in the case of CPU or RAM.

The only thing that can slow the node in a "surprising" way is a garbage collector - try to run your node with - trace * , to see it For what is going on. (See node-v8-option .)

I personally believe that you do not find anything from that because - and this is just my feeling - the issue Else is somewhere

With that complete delay of 500ms multiplication, I think you have a packet loss that you can check with ifconfig , if this is a common problem and then Tcpdump and see if they retransmit.

No comments:

Post a Comment