google/tarpc

Recommended way for connection pooling?

Opened this issue · 4 comments

Is there any recommended way to do connection pooling with tarpc? There doesn't seem to be an example for doing such.

I tried to use the common connection pools for databases(deadpool and bb8) and with simulating a 100ms sleep it seems to take 1 second to fulfill requests instead of closer to 100ms. There is no issue when I run it as a single OnceCell static connection without pooling, I get 106ms which seems closer to correct

I can get around the 1 second loading issue from connection pooling by increasing the max connection count but I don't think having thousands of connections is ideal. So the workaround I did was to create a Vec<Arc>connections, and then set the max pool size to thousands and just clone the Arc based on AtomicUsize. And use StubbornTcpStream to handle the reconnects

That seems to work better and get me 117ms, but still quite a bit of a penalty. I am rather new to Rust so wanted to be sure I'm not doing anything wrong and requesting in general if it would be possible to get an example for connection pooling properly with tarpc.

Thanks for the suggestion! I'd love to have an example with connection pooling. However, I haven't used connection pools in rust, so I probably am not best suited to it. I'd happily accept a PR with such an example, though!

pool may not need impl in tarpc. some library have transport layer pool.

@fly3366 - Can you provide an example that doesn't get impacted by large performance regression vs without pooling?

I think @fly3366's point was that connection pooling is a good feature to have, and that it should live in the transport layer. Most of the tarpc framework is generic over the transport layer. If there are connection pool libraries already available (e.g. on crates.io), there could potentially be a crate that makes those libraries accessible to tarpc services.