Best practices for creating / retaining / reusing clients?
AttilaTheFun opened this issue · 2 comments
Hi! I was wondering what the best practices are with regards to when I should create new clients vs. recycle existing ones? Also I'm assuming all clients should generally share one EventLoopGroup.
Should I create one client per GRPC service and reuse the same client for subsequent or parallel requests to that service?
Or should I create one client per request, and discard them once the request succeeds / fails? (Ignoring the streaming case where it might be longer lived.)
And if I do create a client per request, do I need to retain it myself until the request completes? Or will it remain in memory long enough to call the completion handler?
Thanks!
Hi! I was wondering what the best practices are with regards to when I should create new clients vs. recycle existing ones? Also I'm assuming all clients should generally share one EventLoopGroup.
Clients are reasonably expensive to create and are intended to be long-lived objects so create as few as possible. If a client isn't being used (i.e. there are no RPCs in progress) its connection will be torn down after a period of inactivity. When you next use that client a new connection will automatically be established. Clients can share an EventLoopGroup
and in the vast majority of cases that EventLoopGroup
only needs a single EventLoop
.
Should I create one client per GRPC service and reuse the same client for subsequent or parallel requests to that service?
Yes
Awesome, thanks!