Hello!
On Thu, Dec 25, 2014 at 8:11 AM, Brian Akins wrote:
> Using shdict is fine for a lot of data. 10gb is not that much. However,
> counting the keys x time per second using get_keys is not a good approach as
> it loads all the keys into RAM.
Yes, get_keys(0) loads *all* the key contents from the shm zone into
the Lua GC-managed memory, which means creating a *lot* of Lua strings
and a *huge* Lua table for for counting the number of keys, which is
completely waste of resources, and can easily exceed the limit in
LuaJIT's GC-memanged memory (as having said, 1GB on x64).
Abusing get_keys() is very bad. That's also why I was hesitate to add
this to shdict in the first place.
For the original poster's use case, one should either maintain the
count with a special key itself, or just use external tools based on
systemtap or dtrace. As I've said, we could add a count() method to
shdict to count all the non-expired key-value pairs though it is still
an O(n) operation (but without importing any data from shdict into the
Lua space). Well, patches welcome.
It's not easy to make it O(1) because we have to take into account key
expiration.
Regards,
-agentzh