I'm trying to build a Rust web framework using Actix that needs to query HBase backend. We have chosen to use the Thrift code generator to generate the APIs with this file. However we are having some troubles figuring out how to pass the connection to our web-tier query functions. The official Actix way is to use an extractor that extracts the application state, in this case an HBase connection. More specifically, we are able to create objects of type THBaseServiceSyncClient, which is the application data we wish to pass around that keeps an open connection to HBase and allows us to do queries.
The official way is to clone this data, for each running thread. The first issue we encountered is that, this type does not implement the Clone
trait. We were able to implement our own Clone
function, only to realize that it also does not implement the DerefMut
trait. This is slightly harder, and cannot be circumvented due to the function definitions in the API linked above. The usual way to go about doing this, is to wrap the object with a Mutex
. We have experimented with that, and it performed very poorly. The contention was way too high, and we simply cannot have one global connection for all the threads to use.
We researched how other popular databases connections are handled in Rust. We realize that a thread_pool
is usually used, where a pool of active connections is kept, and a manager keeps track of the alive/dead connections and spins up more if needed. We found this r2d2
crate, which claims to provide a generic connection pool for Rust. Unfortunately there is no thrift support, and we experimented by implementing our very simple pool manager similar to the mysql variant here. The result was very underwhelming. The throughput was not nearly what we need, and a lot of the time is wasted on the pool manager, according to some simple flamegraph
profiling.
Is there some more obvious ways to achieve this goal that we're missing here? I'm wondering if anyone has experienced similar issues and can provide some inside as to what's the best way to go about doing this. Much appreciated.