|
|
@ -93,7 +93,7 @@ function BenchmarkClient(server_targets, channels, histogram_params, |
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < channels; i++) { |
|
|
|
for (var i = 0; i < channels; i++) { |
|
|
|
var host_port; |
|
|
|
var host_port; |
|
|
|
host_port = server_targets[i % server_targets.length].split(':') |
|
|
|
host_port = server_targets[i % server_targets.length].split(':'); |
|
|
|
var new_options = _.assign({hostname: host_port[0], port: +host_port[1]}, options); |
|
|
|
var new_options = _.assign({hostname: host_port[0], port: +host_port[1]}, options); |
|
|
|
new_options.agent = new protocol.Agent(new_options); |
|
|
|
new_options.agent = new protocol.Agent(new_options); |
|
|
|
this.client_options[i] = new_options; |
|
|
|
this.client_options[i] = new_options; |
|
|
@ -149,25 +149,34 @@ BenchmarkClient.prototype.startClosedLoop = function( |
|
|
|
if (self.running) { |
|
|
|
if (self.running) { |
|
|
|
self.pending_calls++; |
|
|
|
self.pending_calls++; |
|
|
|
var start_time = process.hrtime(); |
|
|
|
var start_time = process.hrtime(); |
|
|
|
var req = self.request(client_options, function(res) { |
|
|
|
function finishCall(success) { |
|
|
|
var res_data = ''; |
|
|
|
if (success) { |
|
|
|
res.on('data', function(data) { |
|
|
|
|
|
|
|
res_data += data; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
res.on('end', function() { |
|
|
|
|
|
|
|
JSON.parse(res_data); |
|
|
|
|
|
|
|
var time_diff = process.hrtime(start_time); |
|
|
|
var time_diff = process.hrtime(start_time); |
|
|
|
self.histogram.add(timeDiffToNanos(time_diff)); |
|
|
|
self.histogram.add(timeDiffToNanos(time_diff)); |
|
|
|
|
|
|
|
} |
|
|
|
makeCall(client_options); |
|
|
|
makeCall(client_options); |
|
|
|
self.pending_calls--; |
|
|
|
self.pending_calls--; |
|
|
|
if ((!self.running) && self.pending_calls == 0) { |
|
|
|
if ((!self.running) && self.pending_calls == 0) { |
|
|
|
self.emit('finished'); |
|
|
|
self.emit('finished'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var req = self.request(client_options, function(res) { |
|
|
|
|
|
|
|
var res_data = ''; |
|
|
|
|
|
|
|
res.on('data', function(data) { |
|
|
|
|
|
|
|
res_data += data; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
res.on('end', function() { |
|
|
|
|
|
|
|
JSON.parse(res_data); |
|
|
|
|
|
|
|
finishCall(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
req.write(JSON.stringify(argument)); |
|
|
|
req.write(JSON.stringify(argument)); |
|
|
|
req.end(); |
|
|
|
req.end(); |
|
|
|
req.on('error', function(error) { |
|
|
|
req.on('error', function(error) { |
|
|
|
|
|
|
|
if (error.code === 'ECONNRESET' || error.code === 'ETIMEDOUT') { |
|
|
|
|
|
|
|
finishCall(false); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
self.emit('error', new Error('Client error: ' + error.message)); |
|
|
|
self.emit('error', new Error('Client error: ' + error.message)); |
|
|
|
self.running = false; |
|
|
|
self.running = false; |
|
|
|
}); |
|
|
|
}); |
|
|
|