dosubot[bot] commented on issue #2627:
URL: 
https://github.com/apache/incubator-hugegraph/issues/2627#issuecomment-2274816214

   <!-- Answer -->
   To resolve the issue of histogram metrics values for JRaft returning NaN in 
the HStore backend of the Master (Apache Release Version) of your server, you 
should ensure that the `HistogramWrapper` class is correctly updating its 
snapshot. The current implementation updates the snapshot every 30 seconds, 
which might be causing the NaN values if the histogram is not being updated 
frequently enough.
   
   Here is the relevant code snippet that shows how the `HistogramWrapper` 
class is implemented:
   
   ```java
   private static class HistogramWrapper {
   
       private final com.codahale.metrics.Histogram histogram;
       private Snapshot snapshot;
       private long ts = System.currentTimeMillis();
   
       HistogramWrapper(com.codahale.metrics.Histogram histogram) {
           this.histogram = histogram;
           this.snapshot = this.histogram.getSnapshot();
       }
   
       Snapshot getSnapshot() {
           if (System.currentTimeMillis() - this.ts > 30_000) {
               this.snapshot = this.histogram.getSnapshot();
               this.ts = System.currentTimeMillis();
           }
           return this.snapshot;
       }
   }
   ```
   
   To ensure that the histogram metrics are updated correctly, you might want 
to reduce the interval for updating the snapshot or ensure that the histogram 
is being updated frequently enough. You can adjust the interval by modifying 
the condition in the `getSnapshot` method:
   
   ```java
   Snapshot getSnapshot() {
       if (System.currentTimeMillis() - this.ts > 10_000) { // Update every 10 
seconds
           this.snapshot = this.histogram.getSnapshot();
           this.ts = System.currentTimeMillis();
       }
       return this.snapshot;
   }
   ```
   
   Additionally, ensure that the histogram is being updated with new data 
points frequently enough to avoid NaN values. If the histogram is not receiving 
new data points, it might result in NaN values when the snapshot is taken 
<sup>[[1]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java)</sup>.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to