I would imagine when you start seeing more evictions in your stats than you expect, you know your cache is full.&nbsp; I&#39;d say anything else is over-complicating it.<br><br><div><span class="gmail_quote">On 5/25/07, <b class="gmail_sendername">
Ben Hartshorne</b> &lt;<a href="mailto:memcache@green.hartshorne.net">memcache@green.hartshorne.net</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
OK, so the best I can come up with is to insert a new record every x<br>minutes (say, 60), choose what threshold you expect or care about<br>records not getting flushed due to overflowing the cache, wait that<br>long, and then check the record and see if it&#39;s still there, verifying
<br>that your cache has not been blown.&nbsp;&nbsp;This seems rather crude, and only<br>tells you when you have already lost your cache, not when you are<br>getting close to doing so (though you can double your time threshold and<br>
hope that&#39;s good enough).<br><br>So for example, I am interested in making sure a record persists for 6<br>hours.&nbsp;&nbsp;I double that time to give a bit of a threshold so as to get<br>some warning.&nbsp;&nbsp;I insert 12 records, one every hour.&nbsp;&nbsp;After all have been
<br>inserted, I check the 12th record before resetting it.&nbsp;&nbsp;If it&#39;s still<br>there, my cache has enough space that records can last 12 hours.&nbsp;&nbsp;If<br>it&#39;s gone, I can step through them to determine how much of the cache
<br>had to be freed to make room for the current data.<br><br>Has anybody done this?&nbsp;&nbsp;Maybe as a nagios plugin?<br><br>This procedure does raise a question though, about the details of which<br>records are dropped when the cache becomes full.&nbsp;&nbsp;When the cache becomes
<br>full, how is it determined which records to drop?&nbsp;&nbsp;Oldest access time?<br>Oldest insert time?&nbsp;&nbsp;Largest record?&nbsp;&nbsp;I&#39;m kinda hoping it&#39;s oldest<br>access time, because that makes the most sense for our environment
<br>(since popular records will stay in the cache longer than unpopular<br>records).&nbsp;&nbsp;:)<br><br>Thanks,<br><br>-ben<br><br><br>On Thu, May 24, 2007 at 12:49:54PM -0700, Ben Hartshorne wrote:<br>&gt; Hi,<br>&gt;<br>&gt; I am trying to evaluate the schedule for expanding our cache.&nbsp;&nbsp;We have
<br>&gt; several different types of data all getting thrown into one large<br>&gt; central cache (made up of 1 instance on each of 4 machines).&nbsp;&nbsp;Some of it<br>&gt; is transient (caching &#39;popular&#39; data for 5 minutes) and some of it is
<br>&gt; more permanent (1wk expiration time).&nbsp;&nbsp;All data is backed by permanent<br>&gt; storage for cache misses.&nbsp;&nbsp;On cache miss, the data is repopulated into<br>&gt; memcache from permanent storage.<br>&gt;<br>&gt; My problem - the &#39;stats&#39; command has a metric &#39;curr_items&#39; that reports
<br>&gt; the current number of items stored.&nbsp;&nbsp;However, when a piece of data<br>&gt; expires, that counter is not decremented until you issue a &#39;get&#39; on the<br>&gt; data and fail.<br>&gt;<br>&gt; In order to cache &#39;popular&#39; data, all data of that type is cached,
<br>&gt; assuming that the popular ones will be hit and updated within the<br>&gt; expiration time, and so remain in the cache, while the unpopular data<br>&gt; will just expire and nobody cares.<br>&gt;<br>&gt; The problem with the curr_items stat is that if I ever get a cache miss
<br>&gt; on the transient data, I immediately fetch it from the database and<br>&gt; stick it back in the cache, causing the curr_items to decrement and then<br>&gt; increment again.&nbsp;&nbsp;Data that is unpopular is stored (causing an
<br>&gt; increment) but never retrieved, so the curr_items never decrements.&nbsp;&nbsp;The<br>&gt; effect is a monotomically increasing number in curr_items until it tops<br>&gt; out (at 2352883, though I&#39;m not sure what&#39;s special about that number).
<br>&gt;<br>&gt; Because of the different types of data and the changing popularity of<br>&gt; data, cache hit percentage is not a good proxy for telling me when my<br>&gt; cache has filled up.<br>&gt;<br>&gt; At the moment, I am pretty sure the cache is not full because the more
<br>&gt; persistent data (1wk expiry time) usually sticks around, though I don&#39;t<br>&gt; have a good metric to prove that, it seems to be the case.<br>&gt;<br>&gt; How do I tell when my cache is full and I need to add the 5th server?&nbsp;&nbsp;I
<br>&gt; tried watching the memory utilization as reported by the OS but it is<br>&gt; also monotomically increasing until it tops out at the limit given to<br>&gt; memcache (7GB, in this case).<br>&gt;<br>&gt;<br>&gt; Thanks for any advice you might have,
<br>&gt;<br>&gt; -ben<br>&gt;<br>&gt;<br>&gt; --<br>&gt; Ben Hartshorne<br>&gt; email: <a href="mailto:ben@hartshorne.net">ben@hartshorne.net</a><br>&gt; <a href="http://ben.hartshorne.net">http://ben.hartshorne.net</a><br>
<br><br><br>--<br>Ben Hartshorne<br>email: <a href="mailto:ben@hartshorne.net">ben@hartshorne.net</a><br><a href="http://ben.hartshorne.net">http://ben.hartshorne.net</a><br><br>-----BEGIN PGP SIGNATURE-----<br>Version: GnuPG 
v1.4.1 (GNU/Linux)<br><br>iD8DBQFGVySPKeT3tvTdv64RAt3iAKCioA54txWxS7HjNJeBvzEd50yzqwCcCFSl<br>7F6qx4H64dJkWQAzu9ptDlQ=<br>=pAVS<br>-----END PGP SIGNATURE-----<br><br></blockquote></div><br>