google / google/tarpc

Best way to handle blocking service methods?

Open
#190 15 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
3.7k
Forks
230
PR merge metrics
No merged PRs in 30d

Description

Some of my service's method need to access the db, which means they would block the current thread. Does that mean I should use the `SyncService` instead of `FutureService`?

But then how can I scale to hundreds of simultaneous rpc calls without spawning equally many threads?

Or should I use `FutureService`, but then how could I process any other rpc calls in parallel with a blocking call (e.g. while one call waits on the db)?

What's the best way to handle this?

Is there a way to combine both approaches like in actix where some actors (here rpc methods) are sync and some are async, and both can be part of the same service, because the sync actors (methods) are executed on a threadpool?

If I manually spawn multiple `FutureService`s in different threads, a blocking call in one thread would still block the other calls happening in the same thread at that time.. And they couldn't all listen on the same port, right? So what's the best way to do this? :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.