views:

80

answers:

3

Hi there

we're using memcache in several of our Rails applications. Now I was wondering: Is there a way to get a list of all objects stored in memcache including the amount of data each value occupies?

E.g.:

key       | memory(Bytes) |   %
-----------------------------------
foo_key   | 15013         |   0.3
bar_key   | 2201          |   0.05

Couldn't find anything in the docs...

Thanks

Matt

+5  A: 

No, we have no intention of supporting such functionality.

Currently, all memcached operations are O(1) (that includes flush). Having an operation that gives you a list of keys can't satisfy that constraint. It would require locks that will be held for the duration of the request, and give you information that may be inaccurate at the very moment you see it.

It's the kind of thing people ask for frequently, but nobody has ever presented a use case where a) they needed it and b) they were using memcached in a way that wasn't harmful to their environment.

Think Heisenberg uncertainty principal meets ephemeral storage.

Dustin
Thanks, Dustin. We're just curious to see which Rails app takes which amount of memory in memcache and how we might optimize it. All that outside of the app, of course. Thanks for your post!
Matt
Memory for a particular application comes and goes in memcached. The app taking up most memory can change throughout the day. The one that's the most active is likely to be using more memory than the one that's the least active. It's pretty easy to get rails to log access so you can at least get a feel. Watch eviction stats and you'll know whether it even matters.
Dustin
(and sorry for spelling principle wrong)
Dustin
A: 

No. It's a cache, not a database. If you have to do things like that, you'll be better off with something else than Memcached.

See the FAQ for further information

af
A: 

Memcached has never acted much like a database, being able to query for a specified set of rows and such.

If you want a memory based database, you could go with MySQL and create MEMORY tables. They function purely in memory, bypassing the slow disk-based accesses to give you higher performance.

EstelS