From 57f64ba4b20f855912d9a0657c75ac3c96ea3194 Mon Sep 17 00:00:00 2001 From: zeliard Date: Mon, 27 Apr 2015 14:56:34 +0900 Subject: [PATCH 1/2] merge from upstream (grpc) master --- README.md | 6 ++++++ ext/completion_queue_async_worker.cc | 22 ++++++++++++++++++++-- ext/completion_queue_async_worker.h | 5 +++++ package.json | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b1d2310e..6e493415 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,12 @@ This requires `node` to be installed. If you instead have the `nodejs` executabl 2. Follow the instructions in the `INSTALL` file in the root of that repository to install the C core library that this package depends on. 3. Run `npm install`. +If you install the gRPC C core library in a custom location, then you need to set some environment variables to install this library. The command will look like this: + +```sh +CXXFLAGS=-I/include LDFLAGS=-L/lib npm install [grpc] +``` + ## Tests To run the test suite, simply run `npm test` in the install location. diff --git a/ext/completion_queue_async_worker.cc b/ext/completion_queue_async_worker.cc index cd7acd1d..4e57121a 100644 --- a/ext/completion_queue_async_worker.cc +++ b/ext/completion_queue_async_worker.cc @@ -43,6 +43,8 @@ namespace grpc { namespace node { +const int max_queue_threads = 2; + using v8::Function; using v8::Handle; using v8::Object; @@ -51,6 +53,9 @@ using v8::Value; grpc_completion_queue *CompletionQueueAsyncWorker::queue; +int CompletionQueueAsyncWorker::current_threads; +int CompletionQueueAsyncWorker::waiting_next_calls; + CompletionQueueAsyncWorker::CompletionQueueAsyncWorker() : NanAsyncWorker(NULL) {} @@ -67,17 +72,30 @@ grpc_completion_queue *CompletionQueueAsyncWorker::GetQueue() { return queue; } void CompletionQueueAsyncWorker::Next() { NanScope(); - CompletionQueueAsyncWorker *worker = new CompletionQueueAsyncWorker(); - NanAsyncQueueWorker(worker); + if (current_threads < max_queue_threads) { + CompletionQueueAsyncWorker *worker = new CompletionQueueAsyncWorker(); + NanAsyncQueueWorker(worker); + } else { + waiting_next_calls += 1; + } } void CompletionQueueAsyncWorker::Init(Handle exports) { NanScope(); + current_threads = 0; + waiting_next_calls = 0; queue = grpc_completion_queue_create(); } void CompletionQueueAsyncWorker::HandleOKCallback() { NanScope(); + if (waiting_next_calls > 0) { + waiting_next_calls -= 1; + CompletionQueueAsyncWorker *worker = new CompletionQueueAsyncWorker(); + NanAsyncQueueWorker(worker); + } else { + current_threads -= 1; + } NanCallback *callback = GetTagCallback(result->tag); Handle argv[] = {NanNull(), GetTagNodeValue(result->tag)}; callback->Call(2, argv); diff --git a/ext/completion_queue_async_worker.h b/ext/completion_queue_async_worker.h index 0ddb5b4c..5d52bbb1 100644 --- a/ext/completion_queue_async_worker.h +++ b/ext/completion_queue_async_worker.h @@ -73,6 +73,11 @@ class CompletionQueueAsyncWorker : public NanAsyncWorker { grpc_event *result; static grpc_completion_queue *queue; + + // Number of grpc_completion_queue_next calls in the thread pool + static int current_threads; + // Number of grpc_completion_queue_next calls waiting to enter the thread pool + static int waiting_next_calls; }; } // namespace node diff --git a/package.json b/package.json index fc3ca1f1..6c0953a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grpc", - "version": "0.6.1", + "version": "0.6.2", "author": "Google Inc.", "description": "gRPC Library for Node", "homepage": "http://www.grpc.io/", From f35d735d69f2f5af45d7fbd3b617ee6cf30de090 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 29 Apr 2015 13:07:12 -0700 Subject: [PATCH 2/2] Exposed server address string in stub --- src/client.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client.js b/src/client.js index fad369c2..b2b79e8b 100644 --- a/src/client.js +++ b/src/client.js @@ -488,6 +488,7 @@ function makeClientConstructor(methods) { callback(null, metadata); }; } + this.server_address = address; this.channel = new grpc.Channel(address, options); }