socket utilization in node.js
DESCRIPTION
TRANSCRIPT
![Page 1: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/1.jpg)
SOCKET UTILIZATION IN NODE.JSAkhilesh Gupta
@agupta03
![Page 2: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/2.jpg)
Inefficient use of TCP sockets: Is HTTP keep-alive working?
![Page 3: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/3.jpg)
Node’s HTTP module supports keep-alive
![Page 4: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/4.jpg)
But there is a catch!
![Page 5: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/5.jpg)
TCP Connection kept alive only if PENDING requests in agent queue
![Page 6: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/6.jpg)
If requests go out one-by-one Connection closed each time
![Page 7: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/7.jpg)
High QPS/Low Latency
High time-wait sockets
Eventual node CRASH
Houston, we’ve had a problem here!
![Page 8: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/8.jpg)
NPM Libraries to the rescue!
![Page 9: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/9.jpg)
ceejbot/keep-alive-agent
mikeal/request : forever module
TBEDP/agentkeepalive
![Page 10: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/10.jpg)
TUNING UP YOUR F-35!
Monitor time_wait sockets !
“If you can’t measure it, you can’t fix it”
![Page 11: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/11.jpg)
TUNING UP YOUR F-35!
maxSockets !
Concurrent sockets agent can have open/host
![Page 12: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/12.jpg)
TUNING UP YOUR F-35!
idleTimeout !
Time for which connection is unused before it is discarded
![Page 13: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/13.jpg)
THE ENGINEERING HAPPINESS GRAPH
![Page 14: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/14.jpg)
Normal agent:
Transactions: 60000 hits!Availability: 100.00 %!Elapsed time: 46.53 secs!Data transferred: 14.88 MB!Response time: 0.05 secs!Transaction rate: 1289.49 trans/sec!Throughput: 0.32 MB/sec!Concurrency: 59.81!Successful transactions:60000!Failed transactions: 0!Longest transaction: 0.45!Shortest transaction: 0.00
Keep alive agent (30 seconds):
Transactions: 60000 hits!Availability: 100.00 %!Elapsed time: 29.70 secs!Data transferred: 14.88 MB!Response time: 0.03 secs!Transaction rate: 2020.20 trans/sec!Throughput: 0.50 MB/sec!Concurrency: 59.84!Successful transactions:60000!Failed transactions: 0!Longest transaction: 0.15!Shortest transaction: 0.01
![Page 15: Socket Utilization in Node.js](https://reader034.vdocuments.us/reader034/viewer/2022052504/54c65a0c4a7959e9438b45c5/html5/thumbnails/15.jpg)
TUNING UP YOUR F-35!
Upgrade to Node 0.5.3+ !
Agent holds sockets for any number of hosts