On Tue, Jun 20, 2017 at 6:16 PM, R A <[email protected]> wrote:

> To clarify, I use unary calls.  I have a client that connects to multiple
> backend servers.  If any of these servers slow down, the requests will
> start buffering in StreamBufferingEncoder indefinitely (once beyond
> MAX_CONCURRENT_STREAMS).  I want to be able to identify such a scenario
> and mark the downstream server unavailable (temporarily) similar to a
> circuit breaker logic, if greater than X number of streams are buffered for
> that particular server.  That way a slowness in one server doesn’t affect
> requests being sent to other servers in the client.
>

I don't think depending on the buffering is best here; if a server doubled
its MAX_CONCURRENT_STREAMS or used MAX_INT, then you would still want to
abort RPCs after a point. Instead, it sounds like you should just limit the
number of concurrent calls per Channel to something that you find
"reasonable". That can be done via an interceptor.

AtomicInteger count = ...;
public blah interceptCall(blah) {
  return new LimitingClientCall(next.newCall(blah));
}

class LimitingClientCall extends ForwardingClientCall {
  public blah start(listener) {
    num = count.incrementAndGet();
    if (num <= LIMIT) {
      // good case; easy case
      super.start(new SimpleForwardingListener(listener) {
        onClose() {
          count.decrementAndGet();
          super.onClose();
        }
      });
    }
    // bad case
    count.decrementAndGet();
    // cancel not strictly necessary since call wasn't started, but a good
idea
    super.cancel("Exceeded limit", null);
     // Throw away all future method calls; assumes delegate() returns
'delegate'
    delegate = new NoopClientCall();
    // Doing this last since it can do anything, which may include throwing
    listener.onClose(Status.CANCELLED.withDescription("Exceeded limit"));
  }
}

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CA%2B4M1oPd%2BZRSKxc_x9p58hUM8mdVu%2BpoCJVUGmN8gQ%2B_vVD83w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to