Altering queries?

K J sanbat at gmail.com
Fri Sep 21 06:02:52 UTC 2007


>
>  I just did some hand-wavy math on that:
>
>
>  >>> import random
> >>> r=random.Random()
> >>> import sets
> >>> s=sets.Set([r.randint(1, 10000000) for x in range(30000)])
> >>> len(s)
> 29950
> >>> len(','.join([str(i) for i in s]))
> 236301
> >>> import zlib
>  >>> compressed=zlib.compress(','.join([str(i) for i in s]), 9)
> >>> len(compressed)
> 109568
>
>
> So, a user with about 30k friends with numeric IDs fairly even distributed
> from 1 to 10,000,000 (my average ID was 4,979,961, min was 236, max was
> 9,999,931) would take a little over 100k of cache when comma separated and
> compressed.
>
>
> I would expect the normal case to be much smaller.
>

Great analysis!

Thinking further on this issue though, gives me more questions...

Storing a list of a user's friends in a Memcache array, then getting them
back in and searching through them... while it avoids the database
altogether, wouldn't it be sorta slow?  For instance, every time a user
visits user B's profile page, the system would need to iterate through this
array and see if they are connected.

In this case would it be just better to have a heap mysql database and query
that instead?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20070921/764ef51c/attachment.html


More information about the memcached mailing list