agentkeepalive
The nodejs's missing keep alive
http.Agent
. Support http
and https
.
Install
$ npm install agentkeepalive
Usage
var http = ;var Agent = ; var keepaliveAgent = maxSockets: 10 maxFreeSockets: 10 keepAlive: true keepAliveMsecs: 30000 // keepalive for 30 seconds; var options = host: 'cnodejs.org' port: 80 path: '/' method: 'GET' agent: keepaliveAgent; var req = http; req;req; ;
https
Support var https = ;var HttpsAgent = HttpsAgent; var keepaliveAgent = ;// https://www.google.com/search?q=nodejs&sugexp=chrome,mod=12&sourceid=chrome&ie=UTF-8var options = host: 'www.google.com' port: 443 path: '/search?q=nodejs&sugexp=chrome,mod=12&sourceid=chrome&ie=UTF-8' method: 'GET' agent: keepaliveAgent; var req = https; req;req; ;
Benchmark
run the benchmark:
cd benchmarksh start.sh
Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz
node@v0.8.9
50 maxSockets, 60 concurrent, 1000 requests per concurrent, 5ms delay
Keep alive agent (30 seconds):
Transactions: 60000 hitsAvailability: 10000 %Elapsed time: 2970 secsData transferred: 1488 MBResponse time: 003 secsTransaction rate: 202020 trans/secThroughput: 050 MB/secConcurrency: 5984Successful transactions: 60000Failed transactions: 0Longest transaction: 015Shortest transaction: 001
Normal agent:
Transactions: 60000 hitsAvailability: 10000 %Elapsed time: 4653 secsData transferred: 1488 MBResponse time: 005 secsTransaction rate: 128949 trans/secThroughput: 032 MB/secConcurrency: 5981Successful transactions: 60000Failed transactions: 0Longest transaction: 045Shortest transaction: 000
Socket created:
[proxy.js:120000] keepalive, 50 created, 60000 requestFinished, 1200 req/socket, 0 requests, 0 sockets, 0 unusedSockets, 50 timeout
{" <10ms":662," <15ms":17825," <20ms":20552," <30ms":17646," <40ms":2315," <50ms":567," <100ms":377," <150ms":56," <200ms":0," >=200ms+":0}
----------------------------------------------------------------
[proxy.js:120000] normal , 53866 created, 84260 requestFinished, 1.56 req/socket, 0 requests, 0 sockets
{" <10ms":75," <15ms":1112," <20ms":10947," <30ms":32130," <40ms":8228," <50ms":3002," <100ms":4274," <150ms":181," <200ms":18," >=200ms+":33}
Authors
Below is the output from git-summary
.
$ git summary
project : agentkeepalive
repo age : 1 year, 3 months
active : 17 days
commits : 36
files : 26
authors :
34 fengmk2 94.4%
2 Will White 5.6%
Ordered by date of first contribution.
License
(The MIT License)
Copyright (c) 2012 - 2013 fengmk2 fengmk2@gmail.com;
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.