Hi,

The way my service works is the client will establish a bidi stream. The 
server then sends a message, from which the client will send n-messages 
back. During the time when the client is streaming back messages, there can 
be many messages (potentially thousands), so during that time, I want to be 
careful to saturate the server with messages. I've been able to do this by 
blocking via while( ! requestStream.isReady()) { ... sleep ... } in my 
client's onNext() handler, then send the messages, but I notice that the 
CPU runs high. I tried to do something clever with having the client send 
all of it's messages to a BlockingQueue, and then have the onReady() 
handler take from the queue and send to the requestStream, but that 
deadlocks, because I think the the onReady callback and the client's 
onNext() are the same thread? So basically what I'd really like to have, is 
a callback that is managed by something that is not CPU intensive, and when 
triggered, my client can send whatever messages its accumulated over the 
last time isReady() was true. I hope that makes sense!

On Tuesday, January 2, 2018 at 11:48:28 AM UTC-5, Eric Gribkoff wrote:
>
> If you're just wanting the client to send one request every time it 
> receives a response, you can typically ignore #isReady() and let the 
> automatic flow-control handle things. If you need to do something more 
> complicated, like manually handling flow control, 
> CallStreamObserver#setOnReadyHandler will let you register a callback when 
> the #isReady() state changes from false to true. You can see an example 
> using this in the manual flow control client example code, 
> https://github.com/grpc/grpc-java/blob/c9b02db276403db4794c6e5ffc78b46889cd4ce8/examples/src/main/java/io/grpc/examples/manualflowcontrol/ManualFlowControlClient.java#L70
> .
>
>
>
> On Sun, Dec 31, 2017 at 7:07 PM, Matt Mitchell <[email protected] 
> <javascript:>> wrote:
>
>> Hi,
>>
>> I'm using onReady() to initialize my client connection (a long lived bidi 
>> connection) and then using isReady() like:
>>
>> public void onNext(MyMessage msg) {
>>   while( ! requestStream.isReady() ){ sleep-for-som-short-time }
>>   requestStream.request(1);
>>   requestStream.onNext(msg);
>> }
>>
>> Which seems to work fine, but it also causes high CPU usage. Is there a 
>> better way to handle sending messages from the client to server without 
>> looping + sleeping like this?
>>
>> Thanks,
>> - Matt
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> 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/ad2ee22e-9b55-42f5-905c-1928ea274468%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/grpc-io/ad2ee22e-9b55-42f5-905c-1928ea274468%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/daf05964-52b7-4ea6-85b5-b6031628528d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to