Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not call grpc_init() for per-call-completion-queues created by a C++ sync server #10348

Merged
merged 6 commits into from
Mar 30, 2017

Conversation

sreecha
Copy link
Contributor

@sreecha sreecha commented Mar 29, 2017

Issue: #9261

Before this PR, every C++ CompletionQueue object creation ended up calling grpc_init which acquires a mutex g_init_mu to increment the number of grpc-init invocations.

This is ok if the number of completion queues being created was small. However, in case of C++ Synchronous server, a completion queue is create for every call. This ends up making g_init_mu one of top created mutexes in sync servers.

This PR makes calling grpc_init optional when creating C++ CompletionQueue objects. It is always set to true by default but if a C++ CompletionQueue is being created by passing a grpc_completion_queue * pointer i.e the following constructor (which is what Sync C++ server calls when creating a per-call completion queue), it is okay to NOT call grpc_init.

class CompletionQueue : private GrpcLibraryCodegen {
 ..
  explicit CompletionQueue(grpc_completion_queue* take);
..
}

This change is safe because if we got a grpc_completion_queue * structure, we MUST have already called grpc_init().

Benchmark results
I added a new benchmark BM_CreateDestroyCpp2 (didn't previously include it as a part of the PR because I thought it is trivial - but on a second thought, i think it is a good idea :))

Locks are down from 3 to 1

On master (with BM_CreateDestroyCpp2 temporarily ported):

sreek@sreek-dev:~/workspace/grpc (master) $ bins/counters/bm_cq --benchmark_filter=BM_CreateDestroyCpp2
Run on (12 X 3501 MHz CPU s)
2017-03-29 10:54:34
Benchmark                     Time           CPU Iterations
-----------------------------------------------------------
BM_CreateDestroyCpp2        215 ns        215 ns    3230778 locks/iter:3 atm_cas/iter:0 atm_add/iter:3 allocs/iter:1

On this PR branch:

sreek@sreek-dev:~/workspace/grpc (init-free-cq) $ bins/counters/bm_cq --benchmark_filter=BM_CreateDestroyCpp2
Run on (12 X 3501 MHz CPU s)
2017-03-29 10:56:15
Benchmark                     Time           CPU Iterations
-----------------------------------------------------------
BM_CreateDestroyCpp2        160 ns        160 ns    4413813 locks/iter:1 atm_cas/iter:0 atm_add/iter:3 allocs/iter:1

}

private:
bool grpc_init_called;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Member variable should end with underscore

@vjpai
Copy link
Member

vjpai commented Mar 29, 2017

Beside the minor comment above, this seems LGTM-able. Can you put benchmark results about this into this PR description?

@sreecha
Copy link
Contributor Author

sreecha commented Mar 29, 2017

@vjpai, Did the changes you requested. PTAL

Copy link
Member

@vjpai vjpai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sreecha
Copy link
Contributor Author

sreecha commented Mar 30, 2017

gRPC_interop_pull_requests failure is a known issue: #9011
(Bazel Full Build & Tests suite is not fully implemented yet and we are ignoring those failures)

@sreecha sreecha merged commit bea4966 into grpc:master Mar 30, 2017
@sreecha sreecha deleted the init-free-cq branch March 30, 2017 20:18
@lock lock bot locked as resolved and limited conversation to collaborators Jan 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants