GRPC threading model

93 views
Skip to first unread message

vicva...@gmail.com

unread,
Mar 1, 2018, 3:53:15 PM3/1/18
to grpc.io

Hi Guys,

Can someone please answer a few questions about GRPC threading model?

If I create a ManagedChannel thusly:

NettyChannelBuilder builder =  NettyChannelBuilder.forAddress( host, port );
builder.eventLoopGroup( new NioEventLoopGroup(2) );
builder.executor( new ThreadPoolExecutor( 1, 1, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>( 10000 ));

1) The 2 EventLoop threads will be used to process data from the network?
2) The single user thread will be used for callbacks from grpc layer to my application layer?


Now if I change my ManagedChannel to:

NettyChannelBuilder builder =  NettyChannelBuilder.forAddress( host, port );
builder.eventLoopGroup( new NioEventLoopGroup(2) );
builder.directExecutor();

1) Will one of the event loop threads will do the work of user thread?
2) When I try this scenario, I see that a thread called [grpc-default-executor-0]  is created. What does this thread intended to do?

Thanks

Carl Mastrangelo

unread,
Mar 1, 2018, 4:11:18 PM3/1/18
to grpc.io
Answers inline


On Thursday, March 1, 2018 at 12:53:15 PM UTC-8, vicva...@gmail.com wrote:

Hi Guys,

Can someone please answer a few questions about GRPC threading model?

If I create a ManagedChannel thusly:

NettyChannelBuilder builder =  NettyChannelBuilder.forAddress( host, port );
builder.eventLoopGroup( new NioEventLoopGroup(2) );
builder.executor( new ThreadPoolExecutor( 1, 1, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>( 10000 ));

1) The 2 EventLoop threads will be used to process data from the network?
2) The single user thread will be used for callbacks from grpc layer to my application layer?


Now if I change my ManagedChannel to:

NettyChannelBuilder builder =  NettyChannelBuilder.forAddress( host, port );
builder.eventLoopGroup( new NioEventLoopGroup(2) );
builder.directExecutor();

1) Will one of the event loop threads will do the work of user thread?

Yes.  The upside is that latency is less, (by about 25us) due to not needing a thread hop.   The downside is that if you block in your application work load, you run the risk of deadlock or very high latency for other RPCs.
 
2) When I try this scenario, I see that a thread called [grpc-default-executor-0]  is created. What does this thread intended to do?

That may be DNS resolver, as DNS resolution is a blocking operation in java (we would love for this to be fixed!)
 

Thanks

vic.si...@gmail.com

unread,
Mar 2, 2018, 1:09:51 PM3/2/18
to grpc.io
Got it, thank you!
Reply all
Reply to author
Forward
0 new messages