Esempio n. 1
0
 /**
  * @param $sample_rate
  * @return BernoulliTrial
  */
 private function getProfileSampler($sample_rate)
 {
     if (!isset($this->sampler) || $this->sampler->getProbability() != $sample_rate) {
         $this->sampler = new BernoulliTrial($sample_rate);
     }
     return $this->sampler;
 }
Esempio n. 2
0
 /**
  * @param float $probability
  * @param float $tolerance
  * @param float $trials
  * @dataProvider sampleProvider
  */
 function testShouldSample($probability, $tolerance, $trials)
 {
     $total = 0.0;
     $trials = (double) $trials;
     $tolerance = (double) $tolerance;
     $sampler = new BernoulliTrial($probability);
     for ($i = 0; $i < $trials; $i++) {
         if ($sampler->shouldSample()) {
             $total++;
         }
     }
     $actual = $total / $trials;
     $this->assertTrue(abs($actual - $probability) < $tolerance, sprintf("percent is %f %d %d", $actual, $total, $trials));
 }
Esempio n. 3
0
 /**
  * Bind to the last stage of MW response generation and send stats to the storage
  *
  * @return bool true - it's a hook
  */
 public static function onRestInPeace()
 {
     // obey the sampling
     global $wgMemcacheStatsSampling;
     $trial = new BernoulliTrial($wgMemcacheStatsSampling / 100);
     // normalize percents to 0-1 range
     if (!$trial->shouldSample()) {
         return true;
     }
     $stats = self::getStats();
     // send generic stats
     foreach ($stats['counts'] as $name => $value) {
         \Transaction::addEvent(\Transaction::EVENT_MEMCACHE_STATS_COUNTERS, ['name' => $name, 'value' => $value]);
     }
     // send top keys for misses and hits
     foreach ($stats['keys'] as $bucket => $keys) {
         foreach ($keys as $key => $count) {
             \Transaction::addRawEvent(\Transaction::EVENT_MEMCACHE_STATS_KEYS, ['bucket' => $bucket, 'key' => $key, 'count' => $count]);
         }
     }
     return true;
 }