|
67 | 67 | $peers = (array) $rpcPeers->{'peers'}; |
68 | 68 | $data->numPeers = count($peers); |
69 | 69 |
|
| 70 | + // -- Get confirmation info from nano_node. Average time, blocks used, time span and percentiles |
| 71 | + // -- over last X min (set by CONFIRMATION_TIME_LIMIT) or max 2048 blocks which is a node limitation |
| 72 | + //$timeStampBefore = microtime(true); // measure execution time |
| 73 | + $rpcConfHistory = getConfirmationHistory($ch); |
| 74 | + $confirmations = $rpcConfHistory->{'confirmations'}; // a list of last X confirmations {hash,duration,time,tally} |
| 75 | + //$confAverage = $rpcConfHistory->{'confirmation_stats'}->{'average'}; // average time [ms] of all confirmations |
| 76 | + //$confCount = $rpcConfHistory->{'confirmation_stats'}->{'count'}; // number of confirmations retrieved from the node |
| 77 | + |
| 78 | + // remove data older than $timeLimit |
| 79 | + usort($confirmations, 'cmpByTime'); // sort array by time value [ms unix time] |
| 80 | + $confCompact = []; // new filtered array |
| 81 | + $durationTotal = 0; // for average calc |
| 82 | + $confAverage = 0; // average confirmation duration |
| 83 | + $timeSpan = 0; // full time span of the data [ms] |
| 84 | + foreach ($confirmations as $confirmation) { |
| 85 | + // only keep data which is later than X ms from latest (highest) value |
| 86 | + if ($confirmation->{'time'} >= $confirmations[0]->{'time'} - CONFIRMATION_TIME_LIMIT) { |
| 87 | + array_push($confCompact, $confirmation); // add new data |
| 88 | + $durationTotal += $confirmation->{'duration'}; |
| 89 | + } else { |
| 90 | + break; // stop iterating once we pass that limit to save time |
| 91 | + } |
| 92 | + } |
| 93 | + $confCount = count($confCompact); |
| 94 | + |
| 95 | + // calculate duration average and time span, avoid dividing by zero |
| 96 | + if ($confCount > 0) { |
| 97 | + $confAverage = round($durationTotal / $confCount); |
| 98 | + $timeSpan = $confCompact[0]->{'time'} - $confCompact[$confCount - 1]->{'time'}; // first minus last |
| 99 | + } |
| 100 | + |
| 101 | + // get percentiles directly from the filtered array |
| 102 | + usort($confCompact, 'cmpByDuration'); // sort array by duration value |
| 103 | + $percentile50 = getConfirmationsDurationPercentile(50, $confCompact); // 50 percentile also called median |
| 104 | + $percentile75 = getConfirmationsDurationPercentile(75, $confCompact); |
| 105 | + $percentile90 = getConfirmationsDurationPercentile(90, $confCompact); |
| 106 | + $percentile95 = getConfirmationsDurationPercentile(95, $confCompact); |
| 107 | + $percentile99 = getConfirmationsDurationPercentile(99, $confCompact); |
| 108 | + |
| 109 | + // combine an array with all confirmation info |
| 110 | + $confSummary = ['count' => $confCount, 'timeSpan' => $timeSpan, 'average' => $confAverage, 'percentile50' => $percentile50, |
| 111 | + 'percentile75' => $percentile75, 'percentile90' => $percentile90, 'percentile95' => $percentile95, 'percentile99' => $percentile99, ]; |
| 112 | + $data->confirmationInfo = $confSummary; |
| 113 | + //$data->apiProcTimeConf = round((microtime(true) - $timeStampBefore) * 1000); |
| 114 | + |
70 | 115 | // -- Get node account balance from nano_node |
71 | 116 | $rpcNodeAccountBalance = getAccountBalance($ch, $nanoNodeAccount); |
72 | 117 | $data->accBalanceMnano = rawToCurrency($rpcNodeAccountBalance->{'balance'}, $currency); |
|
122 | 167 | // close curl handle |
123 | 168 | curl_close($ch); |
124 | 169 |
|
| 170 | + // calculate total script execution time |
| 171 | + $data->apiProcTime = round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000); |
| 172 | + |
125 | 173 | return $data; |
126 | 174 | }); |
127 | 175 |
|
|
0 commit comments