c++ - Connecting to remote services from multiple threaded requests -


i have boost asio application many threads, similar web server, handling hundreds of concurrent requests. every request need make calls both memcached , redis (via libmemcached , redispp respectively). best practice in situation make separate connection both redis , memcached each thread (effectively tripling open sockets on server, 3 per request)? or there way me build static object, single memcached/redis connection, , allow threads share single connection? i'm bit confused when comes thread safety of this, , needs asynchronous between threads, blocking each thread's individual request (so each thread has linear progression, many threads can in different places in own progression @ given time). make sense?

thanks much!

since memcached have syncronous protocol should not write next request before got answer prevous. so, no other thread can chat in same memcached connection. i'd prefer make thread-local connection if work in "blocking" mode.

or can make work in "async" manner: make pool of connections, pick connection (and lock it). after request done, return pool.

also, can make request queue , process in special thread(s) (using multigets , callbacks).


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -