question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simplify implementation of back-pressure in StreamObserver-based stub

See original GitHub issue

Pending API changes can allow reactive/async pattern for interacting with flow control and applying back pressure: https://github.com/grpc/grpc-java/pull/1545/files

In many cases, automatic back-pressure in generated stubs could be very useful – e.g. having calls to StreamObserve#onNext(T) block instead of queueing.

It’s been pointed out that this could cause deadlock for bidi-streaming operations, so perhaps we can just not expose this functionality for bidi-streaming calls?

It may also be worth pointing out that most other runtimes (wrapped languages and Go) already expose streams via blocking operations and already require that apps be aware of and work-around possible deadlock issues resulting therefrom. So maybe providing similar mechanisms in Java is fine, with said caveats.

Another possible alternative could possibly be done in an extension/add-on instead of in GRPC. For example, wrapping streaming requests and responses with RxJava Observables may further simplify the async case enough to make the synchronous (and possibly-deadlock-prone) case unnecessary.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:32 (19 by maintainers)

github_iconTop GitHub Comments

2reactions
OlegDokukacommented, May 28, 2019

@ulfjack. Please, consider using RSocket which supports backpressure correctly - http://rsocket.io/

Cheers.

2reactions
carl-mastrangelocommented, Feb 6, 2017

@stephenh Yes, you app threads, as provided to executor() when you set up your Channel / Server. If you stall all your threads, none of them will be able to take more traffic. The pushback logic probably needs to live outside gRPC code, and not inline as in your example above. If you are calling the stubs from your own threads (not on the executor you gave to the channel) then you are probably fine blocking.

IE is actually a “collaborative” feature. You have to want an IE in the reciever, and also have to intentionally interrupt another thread (such as on Future.cancel(true)). The trouble comes from code you may not own interrupting your code. If you aren’t expecting an IE, its better to just let it propagate.

@cbornet There are two levels of FC: wire and API. The gRPC API is message based, which is converted to byte based in the library. I agree, this is not well covered anywhere. One effect that is not obvious is that unary calls generally don’t honor the message flow control, but do honor the byte flow control. That means it is still easy to overload your sender if you don’t pay attention to isReady, because they will buffer up in memory. One day I will write a comprehensive guide on how this works, but that’s extremely time consuming and thus hasn’t been a priority.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Backpressure explained — the resisted flow of data through ...
Backpressure explained — the resisted flow of data through software. Backpressure (or back pressure) is something nearly every software engineer ...
Read more >
Backpressure routing - Wikipedia
Backpressure routing considers the situation where each job can visit multiple service nodes in the network. It is an extension of max-weight scheduling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found