[ 
https://issues.apache.org/jira/browse/SCB-370?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16388831#comment-16388831
 ] 

ASF GitHub Bot commented on SCB-370:
------------------------------------

wujimin commented on a change in pull request #572: [SCB-370] Improve latency 
and max precision
URL: 
https://github.com/apache/incubator-servicecomb-java-chassis/pull/572#discussion_r172712666
 
 

 ##########
 File path: 
metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/HighPrecisionBasicTimer.java
 ##########
 @@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.metrics.core;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.servicecomb.foundation.metrics.MetricsConst;
+
+import com.netflix.servo.monitor.BasicTimer;
+import com.netflix.servo.monitor.Monitor;
+import com.netflix.servo.monitor.MonitorConfig;
+import com.netflix.servo.tag.Tags;
+
+//latency and max should return by default millisecond unit value for easy use
+//because Timer is extends NumericMonitor<Long> so only can return Long result 
value and lost precision (value after the decimal point will be remove)
+//warp BasicTimer, return custom Monitor<Double> for calculate double 
millisecond value
+public class HighPrecisionBasicTimer extends BasicTimer {
+  private final MonitorForTimerValue timerValueMonitor;
+
+  private final MonitorForTimerMax timerMaxMonitor;
+
+  public MonitorForTimerValue getTimerValueMonitor() {
+    return timerValueMonitor;
+  }
+
+  public MonitorForTimerMax getTimerMaxMonitor() {
+    return timerMaxMonitor;
+  }
+
+  public HighPrecisionBasicTimer(MonitorConfig config) {
+    super(config, TimeUnit.NANOSECONDS);
+    this.timerValueMonitor = new MonitorForTimerValue(this);
+    this.timerMaxMonitor = new MonitorForTimerMax(this);
+  }
+
+  class MonitorForTimerValue implements Monitor<Double> {
+
+    private final BasicTimer timer;
+
+    public MonitorForTimerValue(BasicTimer timer) {
+      this.timer = timer;
+    }
+
+    @Override
+    public Double getValue() {
+      return this.getValue(0);
+    }
+
+    @Override
+    public Double getValue(int pollerIndex) {
+      //we need direct div for keep value after the decimal point
+      long nanoValue = timer.getValue();
+      return (double) nanoValue / (double) 1000000;
 
 Review comment:
   it seems that you confused input unit and output unit

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Metrics timer (like latency) output precision must to nano level not milli 
> level
> --------------------------------------------------------------------------------
>
>                 Key: SCB-370
>                 URL: https://issues.apache.org/jira/browse/SCB-370
>             Project: Apache ServiceComb
>          Issue Type: Sub-task
>          Components: Java-Chassis
>    Affects Versions: java-chassis-1.0.0-m1
>            Reporter: yangyongzheng
>            Assignee: yangyongzheng
>            Priority: Major
>             Fix For: java-chassis-1.0.0-m1
>
>
> current metrics latency default unit is MILLISECONDS and low than 1 
> milliseconds like 0.5 will return 0,we need support higher accuracy and keep 
> value after the decimal point



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to