Forum OpenACS Development: Re: caching ns_sets

Collapse
6: Re: caching ns_sets (response to 1)
Posted by Tom Jackson on

Jeff,

That is interesting, I use ns_set -persist in a startup script in AOLserver3.4, and it seems to work fine in all threads. I think I use it in init.tcl, so maybe it happens before thread creation?

Of course you still have to use the old ns_share, or new nsv_* to use it later on.

If I had to write this code over again, I would use nsv_array instead of ns_set, unless I needed multiple values per key.

If ns_set is always thread local, that seems like a mistake if the -persist flag is to be of any use. Ns_set offers some unique features, and is almost as fast as nsv arrays, at least for small to medium set sizes. But maybe the problem is one structure accessed by multiple threads with no protection?

If you are going to be looping over the set members, nsv is still efficient, because you can make an copy of the array so you only lock a mutex once pre copy.

Maybe the cacheing procedures could create an array, bulk copy that array to an nsv_array in a single step, and then return a copy of this nsv_array when needed.