jiajunwang commented on a change in pull request #636: Simply and enhance the
RebalanceLatencyGauge so it can be used in multi-threads.
URL: https://github.com/apache/helix/pull/636#discussion_r352815776
##########
File path:
helix-core/src/main/java/org/apache/helix/monitoring/metrics/implementation/RebalanceLatencyGauge.java
##########
@@ -50,24 +53,24 @@ public RebalanceLatencyGauge(String metricName, long
slidingTimeWindow) {
@Override
public void startMeasuringLatency() {
reset();
- _startTime = System.currentTimeMillis();
+ _startTime.set(System.currentTimeMillis());
}
/**
* WARNING: this method is not thread-safe.
*/
@Override
public void endMeasuringLatency() {
- if (_startTime == VALUE_NOT_SET || _endTime != VALUE_NOT_SET) {
+ if (_startTime.get() == VALUE_NOT_SET) {
LOG.error(
"Needs to call startMeasuringLatency first! Ignoring and resetting
the metric. Metric name: {}",
_metricName);
- reset();
return;
}
- _endTime = System.currentTimeMillis();
- _lastEmittedMetricValue = _endTime - _startTime;
- updateValue(_lastEmittedMetricValue);
+ synchronized (this) {
Review comment:
No, the caller is usually reading the data from a different thread. If you
make this output value thread local, you will always get the init value (-1).
So it has to be a normal value.
The same to the metric object too.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]