From d7b440f7265c1873aa3d4483bce6ec502a44e5e9 Mon Sep 17 00:00:00 2001 From: Neil Bertram Date: Tue, 8 May 2012 16:01:29 +1200 Subject: [PATCH 1/3] Migrate to new HTTP API and limit to one HTTP socket per Client to force the use of keepalives --- lib/soda/client.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/lib/soda/client.js b/lib/soda/client.js index 52fc76b..7daa4d5 100755 --- a/lib/soda/client.js +++ b/lib/soda/client.js @@ -83,8 +83,13 @@ Client.prototype.session = function(fn){ Client.prototype.command = function(cmd, args, fn){ this.emit('command', cmd, args); - // HTTP client - var client = http.createClient(this.port, this.host); + if (!this.agent) { + // Create a dedicated HTTP agent pool for this client, limited to one socket. + // This means all Selenium commands are sent on one socket with keepalives, rather than + // a new socket created for each request, as we never reach the maxSockets default of 5 otherwise. + this.agent = new http.Agent(); + this.agent.maxSockets = 1; + } // Path construction var path = this.commandPath(cmd, args); @@ -96,18 +101,26 @@ Client.prototype.command = function(cmd, args, fn){ // See also: http://jira.openqa.org/browse/SRC-50 if (path.length > 2048 && (this.host + path ).length > 2083) { postData = this.commandPath(cmd, args).replace('/selenium-server/driver/?', ""); - req = client.request('POST' - , path - , { Host: this.host + (this.port ? ':' + this.port : '') - , 'Content-Length': postData.length + req = http.request({ + host: this.host, + port: this.port, + method: 'POST', + path: path, + agent: false, // use new socket for each POST + headers: { + 'Content-Length': postData.length , 'Content-Type': 'application/x-www-form-urlencoded' + } }); - req.write(postData); - } else { - req = client.request('GET' - , path - , { Host: this.host + (this.port ? ':' + this.port : '') }); + } else { + req = http.request({ + host: this.host, + port: this.port, + method: 'GET', + path: path, + agent: this.agent, + }); } req.on('response', function(res){ From 607c0f497513c573137e916677db1e99b0e6e299 Mon Sep 17 00:00:00 2001 From: Neil Bertram Date: Thu, 10 May 2012 16:14:32 +1200 Subject: [PATCH 2/3] Provide support for max-duration --- lib/soda/sauce.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/soda/sauce.js b/lib/soda/sauce.js index b96bd47..71c8b10 100644 --- a/lib/soda/sauce.js +++ b/lib/soda/sauce.js @@ -48,7 +48,8 @@ var SauceClient = exports = module.exports = function SauceClient(options) { options.browser = options.browser || process.env.SAUCE_BROWSER || 'firefox'; options.username = options.username || process.env.SAUCE_USERNAME; options['access-key'] = options['access-key'] || process.env.SAUCE_ACCESS_KEY; - + options.['max-duration'] = options['max-duration'] || 300; + // Allow users to specify an empty browser-version options['browser-version'] = options['browser-version'] == undefined ? (process.env.SAUCE_BROWSER_VERSION || '') From 175f8118d89ed6db63eb1acab1c774f36a562a6b Mon Sep 17 00:00:00 2001 From: Neil Bertram Date: Thu, 10 May 2012 16:20:22 +1200 Subject: [PATCH 3/3] Fix typo --- lib/soda/sauce.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/soda/sauce.js b/lib/soda/sauce.js index 71c8b10..eb1da2e 100644 --- a/lib/soda/sauce.js +++ b/lib/soda/sauce.js @@ -48,7 +48,7 @@ var SauceClient = exports = module.exports = function SauceClient(options) { options.browser = options.browser || process.env.SAUCE_BROWSER || 'firefox'; options.username = options.username || process.env.SAUCE_USERNAME; options['access-key'] = options['access-key'] || process.env.SAUCE_ACCESS_KEY; - options.['max-duration'] = options['max-duration'] || 300; + options['max-duration'] = options['max-duration'] || 300; // Allow users to specify an empty browser-version options['browser-version'] = options['browser-version'] == undefined