node.js - why latency varies in web socket when it's a static connection? -


as http creates connection again , again each data transferred on network, web sockets static , connection made once , stay until transmission done...but if web sockets static why latency differs each data packet..???

the latency test app have created shows me different time lag.. advantage of web socket being static connection or if common issue in web sockets ??

do need create buffer control flow of data because data transmission in continous..? latecy increases when data transmission continous?

there no overhead establish new connection statically open web socket (as connection open , established), when you're making request half way around world, networking takes time there's latency when you're talking server half way around world.

that's how networking works.

you near immediate response server on own lan , further away server gets (in terms of network topology) more routers each packet transit through, more total delay there is. witnessed in earlier question related topic, when tracert location server location, saw lot of different hops each packet has traverse. time each 1 of these hops adds , busy routers may each add small delay if aren't instantly processing packet.

the latency between when send packet , response 2x packet transit time plus whatever server takes respond plus perhaps tiny little overhead tcp (since it's reliable protocol, needs acknowledgements). cannot speed transit time unless pick server closer or somehow influence route packet takes faster route (this not under control once you've selected local isp use).

no amount of buffering on end decrease roundtrip time server.

in addition, more hops in network there between client , server, more variation may 1 moment next in transit time. each 1 of routers packet traverses , each 1 of links travels on has own load, congestion, etc... varies time. there minimum transit time ever observe (it never faster x), many things can influence on time make slower in moments. there case of isp taking router offline maintenance puts more load on other routers handling traffic or route between hops going down temporary, slower , longer route substituted in place. there literally hundreds of things can cause transit time vary moment moment. in general, won't vary lot 1 minute next, can vary through day or on longer periods of time.


you haven't said whether relevant or not, when have poor latency on given roundtrip or when performance important, want minimize number of roundtrips wait for. can couple of ways:

1. don't sequence small pieces of data. slowest way send lots of data send little bit of data, wait response, send little more data, wait response, etc... if had 100 bytes send , sent data 1 byte @ time waiting response each time , roundtrip time x, you'd have 100x total time send data. instead, collect larger piece of data , send @ once. if send 100 bytes @ once, you'd have total delay of x rather 100x.

2. if can, send data parallel. explained above pattern of send data, wait response, send more data, wait response slow when roundtrip time poor. if data can tagged such stands on own, can send data in parallel without waiting prior responses. in above example, slow send 1 byte, wait response, send next byte, wait response. but, if send 1 byte, send next byte, send next byte , times later process response, much, better throughput. obviously, if have 100 bytes of data, may send @ once, if data arriving real time, may want send out arrives , not wait prior responses. whether can depends entirely upon data protocol between client , server.

3. send bigger pieces of data @ time. if can, send bigger chunks of data @ once. depending upon app, may or may not make sense wait data accumulate before sending it, if have 100 bytes of data, try send @ once rather sending in smaller pieces.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -