コード例 #1
0
ファイル: SegmentCommand.php プロジェクト: splitio/php-client
 public function execute()
 {
     $registeredSegments = $this->cache()->getItemsOnList(SegmentCache::getCacheKeyForRegisterSegments());
     $log = $this->logger();
     if (is_array($registeredSegments) && !empty($registeredSegments)) {
         foreach ($registeredSegments as $segmentName) {
             $log->info(">>> Fetching data from segment: {$segmentName}");
             $timeStart = Latency::startMeasuringLatency();
             while (true) {
                 $timeStartPart = Latency::startMeasuringLatency();
                 if (!$this->getSplitClient()->updateSegmentChanges($segmentName)) {
                     $timeItTook = Latency::calculateLatency($timeStartPart);
                     $log->debug("Fetching segment last part ({$segmentName}) took {$timeItTook} microseconds");
                     $greedyTime = Latency::calculateLatency($timeStart);
                     $log->info("Finished fetching whole segment {$segmentName}, took {$greedyTime} microseconds");
                     break;
                 }
                 $timeItTook = Latency::calculateLatency($timeStartPart);
                 $log->debug("Fetching segment part ({$segmentName}) took {$timeItTook} microseconds");
                 //Sleep 1/2 second
                 usleep(500000);
             }
         }
         // Setting Segments ready mark
         $dateTimeUTC = new \DateTime("now", new \DateTimeZone("UTC"));
         $bur = new BlockUntilReadyCache();
         $bur->setReadySegments($dateTimeUTC->getTimestamp());
     }
 }
コード例 #2
0
 public function sendMetrics()
 {
     $metricsKeys = Di::getCache()->getKeys(MetricsCache::getCacheKeySearchLatencyPattern());
     $metricsCache = new MetricsCache();
     $cachedMetrics = array();
     foreach ($metricsKeys as $key) {
         $metricName = MetricsCache::getMetricNameFromKey($key);
         $metricBucket = MetricsCache::getBucketFromKey($key);
         if (!isset($cachedMetrics[$metricName]) || !is_array($cachedMetrics[$metricName])) {
             //initialization latency butckets
             $maxBucket = Latency::getBucketForLatencyMicros(Latency::MAX_LATENCY);
             $cachedMetrics[$metricName] = array_fill(0, $maxBucket + 1, 0);
         }
         $cachedMetrics[$metricName][$metricBucket] = $metricsCache->getLatencyAndReset($key);
     }
     $dataset = array();
     foreach ($cachedMetrics as $name => $latencies) {
         $dataset[] = array('name' => $name, 'latencies' => $latencies);
     }
     //Sending Metrics dataset.
     $response = $this->post($this->servicePath, $dataset);
     if ($response->isSuccessful()) {
         Di::getLogger()->info(count($dataset) . " Metrics sent successfuly");
     } else {
         Di::getLogger()->error("Metrics have not been sent successfully");
         Di::getLogger()->error("HTTP Code: " . $response->getStatusCode());
         Di::getLogger()->error("HTTP Body: " . $response->getBody());
     }
 }
コード例 #3
0
ファイル: SplitFactory.php プロジェクト: splitio/php-client
 /**
  * @param $timeout
  * @return bool
  */
 private function blockUntilReady($timeout)
 {
     $bur = new BlockUntilReadyCache();
     $startTime = Latency::startMeasuringLatency();
     do {
         $lastreadyCheckpoint = $bur->getReadyCheckpoint();
         if ($lastreadyCheckpoint > 0) {
             return true;
         }
         // Checkpoint in milliseconds
         $checkPoint = Latency::calculateLatency($startTime) / 1000;
         // waiting 10 milliseconds
         usleep(10000);
     } while ($checkPoint < $timeout);
     return false;
 }
コード例 #4
0
ファイル: Metrics.php プロジェクト: splitio/php-client
 /**
  * Returns the bucket that this latency falls into.
  * The latencies will not be updated.
  * @param latency
  * @return int the bucket content for the latency.
  */
 public static function getBucketForLatencyMicros($latency)
 {
     return Latency::getBucketForLatencyMicros($latency);
 }