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

Keeping gogoprotobuf codec fast and thread safe #878

Closed
rohitsaboo opened this issue Sep 2, 2016 · 3 comments
Closed

Keeping gogoprotobuf codec fast and thread safe #878

rohitsaboo opened this issue Sep 2, 2016 · 3 comments
Assignees

Comments

@rohitsaboo
Copy link

/cc @awalterschulze

Hi grpc-go team,

It would be great to have your advice on the best way to proceed keeping gogoprotobuf codec both efficient and thread safe.

The generated grpc stubs call grpc/call.go:Invoke, grpc/call.go:sendRequest, and grpc/rpc_util.go:encode, in that order. A custom codec may be simultaneously called from different go routines. I assume grpc expects codecs to be thread-safe. Therefore, using a static memory buffer inside a codec can result in thread-safety issues.

Not having to allocate and deallocate buffers greatly increases efficiency in Golang. In C++, grpc provides arena support which partially ameliorates this issue. Without going down the arena route, one way could be that gogoprotobuf keeps a "free list" that is recycled, but that is effectively doing memory management oneself and goes against Golang's principles.

How would you suggest doing this while managing to attain both objectives?

Thanks,
Rohit

@menghanl
Copy link
Contributor

Closing stale issue.
And https://github.com/golang/protobuf/ would be a better place to discuss issues on protobuf.

@awalterschulze
Copy link

Uhm I don't think its stale, we are still waiting on your reply?

@menghanl menghanl reopened this Jun 19, 2017
@dfawley dfawley self-assigned this Jun 19, 2017
@dfawley
Copy link
Member

dfawley commented Aug 23, 2017

Sorry for the delay in response.

For now, this is not possible given the current API. However, we will be investigating changing this as part of #1455 -- one idea is to see if the codec implements "Free([]byte)", and if so, call that when we are done with the buffer it returned.

@dfawley dfawley closed this as completed Aug 23, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Sep 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants