From baa9cd57c29789548e8679ba1f880fe065a7fe47 Mon Sep 17 00:00:00 2001 From: Gustavo Henke Date: Tue, 9 Sep 2014 13:47:09 -0300 Subject: [PATCH] perf(plook): use custom HTTP agent By using a custom HTTP agent, we are able to increase the maxSockets. This allows for much greater performance when doing ApacheBench tests, for example. --- lib/plook.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/plook.js b/lib/plook.js index 84aa091..b9308cb 100644 --- a/lib/plook.js +++ b/lib/plook.js @@ -34,6 +34,10 @@ function Plook( root ) { return new Plook(); } + // Create a custom socket for when getting files + this._agent = new https.Agent(); + this._agent.maxSockets = 10; + Object.defineProperty( this, "_cache", { value: root instanceof Plook ? root._cache : LRU({ max: 500 @@ -193,6 +197,7 @@ Plook.prototype.get = function( name, version, file, etag ) { promise = this.findURLs( name, version, file ).call( "map", function( reqUrl ) { var options = url.parse( reqUrl ); + options.agent = plook._agent; options.headers = { "if-none-match": etag };