vmodule data, that would be private per thread
Mikhail T.
mi+thun at aldan.algebra.com
Wed Oct 24 15:26:19 CEST 2012
I need to cache and reuse some data in each thread -- to avoid
lock-contention. It does not seem like PRIV_VCL and PRIV_CALL offer
that, so, what I am doing, is this:
1. init_function creates static version of the data once and
initializes thread key with pthread_key_create()
2. each worker functions attempts to extract its thread's copy of the
data with pthread_getspecific()
3. if the pthread_getspecific() returned NULL (first call in this
thread), new memory is allocated and recorded with pthread_setspecific()
Once loaded, the memory is not -- and needs not -- be freed until
varnishd is restarted. This seems to work, however:
* I see twice as many new-memory allocations as the top limit on the
number of worker-threads: I run varnishd with -w 4,7 argument, but,
when I hit it with ab, 14 lines indicating creation of a new copy of
data are logged (with 14 different thread-IDs).
* I'm wondering, if there is already Varnish API, that would hide
these pthread_* manipulations...
Any ideas? Thank you!
-mi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20121024/5f58160f/attachment.html>
More information about the varnish-misc
mailing list