Hello!
On Tue, Jan 27, 2015 at 9:56 PM, Shivakumar Gokaram wrote:
> We have a use case to get all the values from shared directory and then
> clear the shared dictionary. There are many approaches to this
>
> 1. Iterate through the Dictionary and issues a get. Then at the end execute
> flush_all and flush_exipred to wipe out the dictionary.
>
By "interate through the dictionary", you mean using the get_keys()
method to obtain all the keys and then use your Lua loop to get() each
key?
If yes, be careful about a race condition that new writes (from other
nginx workers) might happen between your get_keys() and flush_*()
calls since in that case, those new writes' data will get lost.
Also, do not use this approach when you have a large number of keys in
your shdict store, because it'll be VERY expensive for the get_keys()
method.
> 2. Iterate through the Dictionary and then issue a get. After the get also
> issue a delete.
>
Manual delete() calls upon every element is much less efficient than flush_*().
>
> I want to know what is the best approach from a performance aspect. Does the
> flush_all and flush methods optimized or are these similar to iterating over
> each elements.
>
Yes, flush_* also iterates through all the elements but iterating in C
is more efficient than iterating in Lua even when the Lua loop is JIT
compiled fully.
Regards,
-agentzh