lincolnloop / memcache-top

Automatically exported from code.google.com/p/memcache-top
BSD 3-Clause "New" or "Revised" License
5 stars 2 forks source link

Incorrect calculation of cache_hit parameter #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the memcache-top with --nolifetime option and short sleep time (say 5 
seconds)
2. Look at the evolution of the calculated cache_hit
3. Compare the observed values of the cache_hit parameter with similar values 
calculated in another way (say manually or automatically)

What is the expected output? What do you see instead?
We obtain that many cache_hit values are often zero but this do not match the 
real memcached state.

What version of the product are you using? On what operating system?
0.6 on many Linux RedHat 5.x and Mac OS X

Please provide any additional information below.
Analizing the problem I have found that the initialization value (equal to 
zero) of cache_hit variable is used also when we do not have cache misses. 
Infact, look at the following code lines (lines 292-295 of version 0.6 of the 
script):

  $outstats{cache_hit} = 0;
  if ( defined($outstats{get_misses}) && $outstats{get_misses} > 0 ) {
          $outstats{cache_hit} = ( $laststats{$instance}{get_hits} / $laststats{$instance}{cmd_get} ) * 100;
  }

In the case of nolifetime the get_misses is calculated as variation from the 
previous value. The script calculate the cache_hit only if get_misses is bigger 
than zero. I think that this is not correct, because we can have no variation 
of the get_misses value (no misses) and at the same time have a variation of 
the get_hits and cmd_get values (cache hits). I propose then the following 
modification:

  $outstats{cache_hit} = 0;
  if ( defined($outstats{get_misses}) && $outstats{get_misses} >= 0 ) {
          $outstats{cache_hit} = ( $laststats{$instance}{get_hits} / $laststats{$instance}{cmd_get} ) * 100;
  }

into which the cache_hit is calculated also when we do not have cache misses.

Attached you can find our current version of the script that has also some 
minor changes, like the possibility to log the measured data to file for 
post-process purposes and a simple command line help.

Massimiliano

Original issue reported on code.google.com by m.ottimo...@gmail.com on 30 Aug 2012 at 8:59

Attachments:

GoogleCodeExporter commented 9 years ago
Please, use the attached version of our script because the previous was wrong.

Massimiliano

Original comment by m.ottimo...@gmail.com on 30 Aug 2012 at 10:28

Attachments:

GoogleCodeExporter commented 9 years ago
I'll take a look at this shortly and see about patching it in.  Thanks for 
submitting this!

Original comment by nicholas...@gmail.com on 29 Nov 2012 at 1:16

GoogleCodeExporter commented 9 years ago
$laststats{$instance}{cmd_get} needs to be greater than 0 or else you'll get a 
nice division by zero with a freshly started memcached before any requests 
occurred.

Original comment by bj...@slagkryssaren.com on 5 Feb 2013 at 7:22