Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

agentkeepalive

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

agentkeepalive - npm Package Compare versions

Comparing version 0.0.1 to 0.0.3

benchmark/result.md

33

benchmark/proxy.js

@@ -16,19 +16,31 @@ /*!

var maxSockets = parseInt(process.argv[2], 10) || 10;
var agentKeepalive = new Agent({
maxSockets: 10,
maxSockets: maxSockets,
maxKeepAliveTime: 30000,
});
var agentHttp = new http.Agent({
maxSockets: 10
maxSockets: maxSockets
});
agentHttp.createSocketCount = 0;
agentHttp.__createSocket = agentHttp.createSocket;
agentHttp.createSocket = function (name, host, port, localAddress, req) {
agentHttp.createSocketCount++;
return agentHttp.__createSocket(name, host, port, localAddress, req);
};
setInterval(function () {
console.log('keepalive, %s requests, %s sockets, %s unusedSockets',
agentKeepalive.requests['localhost:1984'] && agentKeepalive.requests['localhost:1984'].length,
agentKeepalive.sockets['localhost:1984'] && agentKeepalive.sockets['localhost:1984'].length,
agentKeepalive.unusedSockets['localhost:1984'] && agentKeepalive.unusedSockets['localhost:1984'].length
var name = 'localhost:1984';
console.log('[proxy.js] keepalive, %d created, %s requests, %s sockets, %s unusedSockets',
agentKeepalive.createSocketCount,
agentKeepalive.requests[name] && agentKeepalive.requests[name].length || 0,
agentKeepalive.sockets[name] && agentKeepalive.sockets[name].length || 0,
agentKeepalive.unusedSockets[name] && agentKeepalive.unusedSockets[name].length || 0
);
console.log('no keepalive, %s requests, %s sockets',
agentHttp.requests['localhost:1984'] && agentHttp.requests['localhost:1984'].length,
agentHttp.sockets['localhost:1984'] && agentHttp.sockets['localhost:1984'].length
console.log('[proxy.js] normal , %d created, %s requests, %s sockets',
agentHttp.createSocketCount,
agentHttp.requests[name] && agentHttp.requests[name].length || 0,
agentHttp.sockets[name] && agentHttp.sockets[name].length || 0
);

@@ -62,2 +74,3 @@ }, 2000);

client.on('error', function (err) {
console.log('error ' + req.url + ':' + err.message);
res.statusCode = 500;

@@ -70,3 +83,3 @@ res.end(err.message);

client.abort();
}, 1000);
}, 2000);

@@ -73,0 +86,0 @@ }).listen(1985);

@@ -23,4 +23,4 @@ /*!

};
count++;
console.log(count + ' ' + req.url);
// count++;
// console.log(count + ' ' + req.url);
res.end(JSON.stringify(result));

@@ -27,0 +27,0 @@ }, timeout);

@@ -31,2 +31,3 @@ /*!

function Agent(options) {
options = options || {};
http.Agent.call(this, options);

@@ -37,4 +38,8 @@

// if set `maxKeepAliveTime = 0`, will disable keepalive feature.
self.maxKeepAliveTime = parseInt(options.maxKeepAliveTime, 10) || 60000;
self.maxKeepAliveTime = parseInt(options.maxKeepAliveTime, 10);
if (isNaN(self.maxKeepAliveTime)) {
self.maxKeepAliveTime = 60000;
}
self.unusedSockets = {};
self.createSocketCount = 0;

@@ -112,2 +117,8 @@ // override the `free` event listener

Agent.prototype.createSocket = function (name, host, port, localAddress, req) {
var s = http.Agent.prototype.createSocket.call(this, name, host, port, localAddress, req);
this.createSocketCount++;
return s;
};
Agent.prototype.__removeSocket = function (s, name) {

@@ -114,0 +125,0 @@ if (this.sockets[name]) {

{
"name": "agentkeepalive",
"version": "0.0.1",
"version": "0.0.3",
"description": "Missing keepalive http.Agent",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -8,2 +8,4 @@ agentkeepalive

jscoverage: [**100%**](http://fengmk2.github.com/coverage/agentkeepalive.html)
## Install

@@ -55,2 +57,32 @@

## [Benchmark](https://github.com/TBEDP/agentkeepalive/blob/master/benchmark/result.md)
run the benchmark:
```bash
cd benchmark
sh start.sh
```
50 maxSockets, 60 concurrent, 1000 requests per concurrent, 5ms delay
Keep alive agent:
```
Transaction rate: 2214.02 trans/sec
```
Normal agent:
```
Transaction rate: 1138.30 trans/sec
```
Socket created:
```
[proxy.js] keepalive, 50 created, 0 requests, 50 sockets, 50 unusedSockets
[proxy.js] normal , 52555 created, 0 requests, 0 sockets
```
## License

@@ -60,3 +92,3 @@

Copyright (c) 2011-2012 fengmk2 <fengmk2@gmail.com>;
Copyright (c) 2012 fengmk2 <fengmk2@gmail.com>;

@@ -63,0 +95,0 @@ Permission is hereby granted, free of charge, to any person obtaining

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc