Closed qiaobaochen closed 2 months ago
The bRPC server is asynchronous at its core, a "sync service" is just a service calling "done->Run()" before the service callback ends. You should look at interfaces of the DB client first:
The bRPC server is asynchronous at its core, a "sync service" is just a service calling "done->Run()" before the service callback ends. You should look at interfaces of the DB client first:
- If the db client has async interfaces (allowing you to pass a callback to be called when db access is done), you could call server's done->Run() in the callback. It's also possible to wrap the async DB client into a bthread-synchronous interfaces.
- If the db client blocks (underlying pthread) until the db access is done, and the DB access is expected to last long(e.g. several seconds), you may run the DB client in separate pthreads. Creating extra bthreads in bRPC server does not help, because all bthreads are mapped to the same pool of pthread workers used by bRPC.
that's very clear, thanks a lot!
Hi, I am beginner in brpc, I decide to use brpc as a database proxy in our scenario, after I read the doc of brpc, I still cannot decide use async server or sync server in our situation.
detail:
servers get data from file or database (IO-bound service), and send data to client side through brpc.
I was wondering that if I start a background bthread
bthread_start_background
and run file-io requrest, is this bthread be blocked? and most important that is this pthread (which bthread is on) will be blocked ?thanks