Shared db pool
Alex Khmara
alex.khmara at gmail.com
Sun Mar 17 14:21:56 PDT 2013
My task involves many worker threads, each of them uses Curl instance to
do one or several requests and one Mysql connection instance to store
data and do some aggregations. ALso sometimes these threads do other work
that don't require these resources.
So I want to make two pools (one for Curl and one for Mysql connections),
so that number of DB connections (or Curl instances) will be lower than
number of threads, so I cannot just use DataPool.WorkerLocalStorageRange.
So I'm trying to create shared pool. And there arises question:
if I have this code:
class SharedPool {
...
Mysql* get() {
...
return cast(Mysql*) connections[freeIndex];
}
...
Mysql*[] connections;
}
shared SharedPool pool;
when I will get syncronization overhead: only on access to SharedPool or
on every access to Mysql instance?
What I really want - is to NOT have any shared-related code after getting
some Mysql instance and before returning it to pool, so Mysql instances
must be essentially non-shared. Is it possible?
More information about the Digitalmars-d-learn
mailing list