aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Michael Lumish <mlumish@google.com>2017-04-04 17:05:22 -0700
committerGravatar GitHub <noreply@github.com>2017-04-04 17:05:22 -0700
commit500e361826cb52a6d8db6839dc209dcf3266df0f (patch)
treed5a874b030510ff98a9f8a7a86e5181cbf40a3d2 /src
parent494a81c8a4c8ea1d5a420deaf98d7406fd4d6c18 (diff)
parentc64601421b7a4072909386c2e79285fe4b487d9f (diff)
Merge pull request #10416 from murgatroid99/node_performance_tests
Node performance tests and improvements
Diffstat (limited to 'src')
-rw-r--r--src/node/ext/byte_buffer.cc39
-rw-r--r--src/node/ext/byte_buffer.h4
-rw-r--r--src/node/ext/slice.cc5
-rw-r--r--src/node/performance/benchmark_server.js8
-rw-r--r--src/node/performance/generic_service.js11
-rw-r--r--src/node/performance/worker_service_impl.js23
6 files changed, 56 insertions, 34 deletions
diff --git a/src/node/ext/byte_buffer.cc b/src/node/ext/byte_buffer.cc
index 7d6fb19860..a99b96bea5 100644
--- a/src/node/ext/byte_buffer.cc
+++ b/src/node/ext/byte_buffer.cc
@@ -45,6 +45,7 @@
namespace grpc {
namespace node {
+using Nan::Callback;
using Nan::MaybeLocal;
using v8::Function;
@@ -62,7 +63,11 @@ grpc_byte_buffer *BufferToByteBuffer(Local<Value> buffer) {
}
namespace {
-void delete_buffer(char *data, void *hint) { delete[] data; }
+void delete_buffer(char *data, void *hint) {
+ grpc_slice *slice = static_cast<grpc_slice *>(hint);
+ grpc_slice_unref(*slice);
+ delete slice;
+}
}
Local<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
@@ -75,31 +80,15 @@ Local<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
Nan::ThrowError("Error initializing byte buffer reader.");
return scope.Escape(Nan::Undefined());
}
- grpc_slice slice = grpc_byte_buffer_reader_readall(&reader);
- size_t length = GRPC_SLICE_LENGTH(slice);
- char *result = new char[length];
- memcpy(result, GRPC_SLICE_START_PTR(slice), length);
- grpc_slice_unref(slice);
- return scope.Escape(MakeFastBuffer(
- Nan::NewBuffer(result, length, delete_buffer, NULL).ToLocalChecked()));
+ grpc_slice *slice = new grpc_slice;
+ *slice = grpc_byte_buffer_reader_readall(&reader);
+ grpc_byte_buffer_reader_destroy(&reader);
+ char *result = reinterpret_cast<char *>(GRPC_SLICE_START_PTR(*slice));
+ size_t length = GRPC_SLICE_LENGTH(*slice);
+ Local<Value> buf =
+ Nan::NewBuffer(result, length, delete_buffer, slice).ToLocalChecked();
+ return scope.Escape(buf);
}
-Local<Value> MakeFastBuffer(Local<Value> slowBuffer) {
- Nan::EscapableHandleScope scope;
- Local<Object> globalObj = Nan::GetCurrentContext()->Global();
- MaybeLocal<Value> constructorValue = Nan::Get(
- globalObj, Nan::New("Buffer").ToLocalChecked());
- Local<Function> bufferConstructor = Local<Function>::Cast(
- constructorValue.ToLocalChecked());
- const int argc = 3;
- Local<Value> consArgs[argc] = {
- slowBuffer,
- Nan::New<Number>(::node::Buffer::Length(slowBuffer)),
- Nan::New<Number>(0)
- };
- MaybeLocal<Object> fastBuffer = Nan::NewInstance(bufferConstructor,
- argc, consArgs);
- return scope.Escape(fastBuffer.ToLocalChecked());
-}
} // namespace node
} // namespace grpc
diff --git a/src/node/ext/byte_buffer.h b/src/node/ext/byte_buffer.h
index 55bc0ab377..e8c4ac90bd 100644
--- a/src/node/ext/byte_buffer.h
+++ b/src/node/ext/byte_buffer.h
@@ -50,10 +50,6 @@ grpc_byte_buffer *BufferToByteBuffer(v8::Local<v8::Value> buffer);
/* Convert a grpc_byte_buffer to a Node.js Buffer */
v8::Local<v8::Value> ByteBufferToBuffer(grpc_byte_buffer *buffer);
-/* Convert a ::node::Buffer to a fast Buffer, as defined in the Node
- Buffer documentation */
-v8::Local<v8::Value> MakeFastBuffer(v8::Local<v8::Value> slowBuffer);
-
} // namespace node
} // namespace grpc
diff --git a/src/node/ext/slice.cc b/src/node/ext/slice.cc
index 98a80b3d2f..104dd9e22c 100644
--- a/src/node/ext/slice.cc
+++ b/src/node/ext/slice.cc
@@ -37,7 +37,6 @@
#include <grpc/support/alloc.h>
#include "slice.h"
-#include "byte_buffer.h"
namespace grpc {
namespace node {
@@ -93,9 +92,9 @@ Local<Value> CreateBufferFromSlice(const grpc_slice slice) {
Nan::EscapableHandleScope scope;
grpc_slice *slice_ptr = new grpc_slice;
*slice_ptr = grpc_slice_ref(slice);
- return scope.Escape(MakeFastBuffer(Nan::NewBuffer(
+ return scope.Escape(Nan::NewBuffer(
const_cast<char *>(reinterpret_cast<const char *>(GRPC_SLICE_START_PTR(*slice_ptr))),
- GRPC_SLICE_LENGTH(*slice_ptr), SliceFreeCallback, slice_ptr).ToLocalChecked()));
+ GRPC_SLICE_LENGTH(*slice_ptr), SliceFreeCallback, slice_ptr).ToLocalChecked());
}
} // namespace node
diff --git a/src/node/performance/benchmark_server.js b/src/node/performance/benchmark_server.js
index 6abde2e17a..7158af775a 100644
--- a/src/node/performance/benchmark_server.js
+++ b/src/node/performance/benchmark_server.js
@@ -88,6 +88,13 @@ function streamingCall(call) {
});
}
+function makeUnaryGenericCall(response_size) {
+ var response = zeroBuffer(response_size);
+ return function unaryGenericCall(call, callback) {
+ callback(null, response);
+ };
+}
+
function makeStreamingGenericCall(response_size) {
var response = zeroBuffer(response_size);
return function streamingGenericCall(call) {
@@ -129,6 +136,7 @@ function BenchmarkServer(host, port, tls, generic, response_size) {
this.port = server.bind(host + ':' + port, server_creds);
if (generic) {
server.addService(genericService, {
+ unaryCall: makeUnaryGenericCall(response_size),
streamingCall: makeStreamingGenericCall(response_size)
});
} else {
diff --git a/src/node/performance/generic_service.js b/src/node/performance/generic_service.js
index ce09cc4336..c936ac30bc 100644
--- a/src/node/performance/generic_service.js
+++ b/src/node/performance/generic_service.js
@@ -34,8 +34,17 @@
var _ = require('lodash');
module.exports = {
+ 'unaryCall' : {
+ path: '/grpc.testing.BenchmarkService/UnaryCall',
+ requestStream: false,
+ responseStream: false,
+ requestSerialize: _.identity,
+ requestDeserialize: _.identity,
+ responseSerialize: _.identity,
+ responseDeserialize: _.identity
+ },
'streamingCall' : {
- path: '/grpc.testing/BenchmarkService',
+ path: '/grpc.testing.BenchmarkService/StreamingCall',
requestStream: true,
responseStream: true,
requestSerialize: _.identity,
diff --git a/src/node/performance/worker_service_impl.js b/src/node/performance/worker_service_impl.js
index 38888a7219..fa864f9925 100644
--- a/src/node/performance/worker_service_impl.js
+++ b/src/node/performance/worker_service_impl.js
@@ -89,6 +89,7 @@ module.exports = function WorkerServiceImpl(benchmark_impl, server) {
default:
call.emit('error', new Error('Unsupported PayloadConfig type' +
setup.payload_config.payload));
+ return;
}
switch (setup.load_params.load) {
case 'closed_loop':
@@ -103,6 +104,7 @@ module.exports = function WorkerServiceImpl(benchmark_impl, server) {
default:
call.emit('error', new Error('Unsupported LoadParams type' +
setup.load_params.load));
+ return;
}
stats = client.mark();
call.write({
@@ -137,8 +139,27 @@ module.exports = function WorkerServiceImpl(benchmark_impl, server) {
switch (request.argtype) {
case 'setup':
console.log('ServerConfig %j', request.setup);
+ var setup = request.setup;
+ var resp_size, generic;
+ if (setup.payload_config) {
+ switch (setup.payload_config.payload) {
+ case 'bytebuf_params':
+ resp_size = setup.payload_config.bytebuf_params.resp_size;
+ generic = true;
+ break;
+ case 'simple_params':
+ resp_size = setup.payload_config.simple_params.resp_size;
+ generic = false;
+ break;
+ default:
+ call.emit('error', new Error('Unsupported PayloadConfig type' +
+ setup.payload_config.payload));
+ return;
+ }
+ }
server = new BenchmarkServer('[::]', request.setup.port,
- request.setup.security_params);
+ request.setup.security_params,
+ generic, resp_size);
server.on('started', function() {
stats = server.mark();
call.write({