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

rpc/grpc: Perform read-write message operations with timeout #366

Merged
merged 2 commits into from
Dec 28, 2021

Conversation

alexvanin
Copy link
Contributor

Remote gRPC server may not return or accept data for a while. gRPC solves this issue with timeout in context. However, the context is used for entire gRPC method invocation. Unfortunately the duration of requests with streams can't be estimated easily.

To solve this issue we can specify timeouts for every message read and write. Single message has size limit so timeout can be related to that.

@codecov
Copy link

codecov bot commented Dec 24, 2021

Codecov Report

Merging #366 (fc3ed00) into master (fb33a6e) will decrease coverage by 0.04%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #366      +/-   ##
==========================================
- Coverage   61.74%   61.69%   -0.05%     
==========================================
  Files          66       66              
  Lines       10043    10051       +8     
==========================================
  Hits         6201     6201              
- Misses       2900     2908       +8     
  Partials      942      942              
Impacted Files Coverage Δ
rpc/client/connect.go 0.00% <0.00%> (ø)
rpc/client/options.go 60.00% <0.00%> (-8.58%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b17921...fc3ed00. Read the comment docs.

carpawell
carpawell previously approved these changes Dec 27, 2021
func (w *streamWrapper) withTimeout(closure func() error) error {
ch := make(chan error, 1)
go func() {
ch <- closure()
Copy link
Contributor

Choose a reason for hiding this comment

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

We should close(ch) after this.

return w.withTimeout(w.ClientStream.CloseSend)
}

func (w *streamWrapper) withTimeout(closure func() error) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you checked the performance impact of this for small messages? E.g. object.Put uses stream.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried it on unary object.Head. Without business logic (no signature checks and metabase access, pure gRPC communication over localhost), there is a 13-15% overhead. It is worst case scenario, so I expect it will be much less noticeable in deploy environment.

goos: linux
goarch: amd64
pkg: github.com/nspcc-dev/neofs-node/cmd/example/client
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
BenchmarkHeadRequests
BenchmarkHeadRequests-8   	            9391	    112575 ns/op
BenchmarkHeadRequestsWithDeadline
BenchmarkHeadRequestsWithDeadline-8   	    8246	    127810 ns/op

fyrchik
fyrchik previously approved these changes Dec 27, 2021
…timeout

Remote gRPC server may not return or accept data for a while. gRPC
solves this issue with timeout in context. However, the context is
used for entire gRPC method invocation. Unfortunately the duration
of requests with streams can't be estimated easily.

To solve this issue we can specify timeouts for every message read
and write. Single message has size limit so timeout can be related
to that.

Signed-off-by: Alex Vanin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants