zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject [zookeeper] branch master updated: ZOOKEEPER-3383: Improve prep processor metric accuracy and de-flaky u…
Date Fri, 10 May 2019 10:22:41 GMT
This is an automated email from the ASF dual-hosted git repository.

andor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 4243b95  ZOOKEEPER-3383: Improve prep processor metric accuracy and de-flaky u…
4243b95 is described below

commit 4243b95f4c1a0c6c6e9a6d78a789fae647d43b20
Author: Jie Huang <jiehuang@fb.com>
AuthorDate: Fri May 10 12:22:34 2019 +0200

    ZOOKEEPER-3383: Improve prep processor metric accuracy and de-flaky u…
    
    …nit test
    
    Author: Jie Huang <jiehuang@fb.com>
    
    Reviewers: andor@apache.org
    
    Closes #937 from jhuan31/ZOOKEEPER-3383
---
 .../java/org/apache/zookeeper/server/PrepRequestProcessor.java     | 7 ++++---
 .../src/main/java/org/apache/zookeeper/server/Request.java         | 2 ++
 .../apache/zookeeper/server/PrepRequestProcessorMetricsTest.java   | 4 +++-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/PrepRequestProcessor.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/PrepRequestProcessor.java
index 48c3bfc..8042537 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/PrepRequestProcessor.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/PrepRequestProcessor.java
@@ -133,6 +133,7 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
             while (true) {
                 ServerMetrics.getMetrics().PREP_PROCESSOR_QUEUE_SIZE.add(submittedRequests.size());
                 Request request = submittedRequests.take();
+                ServerMetrics.getMetrics().PREP_PROCESSOR_QUEUE_TIME.add(Time.currentElapsedTime()
- request.prepQueueStartTime);
                 long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK;
                 if (request.type == OpCode.ping) {
                     traceMask = ZooTrace.CLIENT_PING_TRACE_MASK;
@@ -143,9 +144,9 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
                 if (Request.requestOfDeath == request) {
                     break;
                 }
-                long prepStartTime = Time.currentElapsedTime();
+
+                request.prepStartTime = Time.currentElapsedTime();
                 pRequest(request);
-                ServerMetrics.getMetrics().PREP_PROCESS_TIME.add(Time.currentElapsedTime()
- prepStartTime);
             }
         } catch (RequestProcessorException e) {
             if (e.getCause() instanceof XidRolloverException) {
@@ -908,7 +909,7 @@ public class PrepRequestProcessor extends ZooKeeperCriticalThread implements
             }
         }
         request.zxid = zks.getZxid();
-        ServerMetrics.getMetrics().PREP_PROCESSOR_QUEUE_TIME.add(Time.currentElapsedTime()
- request.prepQueueStartTime);
+        ServerMetrics.getMetrics().PREP_PROCESS_TIME.add(Time.currentElapsedTime() - request.prepStartTime);
         nextProcessor.processRequest(request);
     }
 
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java
index c8f7c74..83f3e0b 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java
@@ -82,6 +82,8 @@ public class Request {
 
     public long prepQueueStartTime= -1;
 
+    public long prepStartTime = -1;
+
     public long commitProcQueueStartTime = -1;
 
     public long commitRecvTime = -1;
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/PrepRequestProcessorMetricsTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/PrepRequestProcessorMetricsTest.java
index 019d0e7..90e2fe1 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/PrepRequestProcessorMetricsTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/PrepRequestProcessorMetricsTest.java
@@ -123,6 +123,8 @@ public class PrepRequestProcessorMetricsTest extends ZKTestCase {
         Map<String, Object> values = MetricsUtils.currentServerMetrics();
         Assert.assertEquals(3L, values.get("prep_processor_request_queued"));
 
+        // the sleep is just to make sure the requests will stay in the queue for some time
+        Thread.sleep(20);
         prepRequestProcessor.start();
 
         threeRequests.await(500, TimeUnit.MILLISECONDS);
@@ -130,7 +132,7 @@ public class PrepRequestProcessorMetricsTest extends ZKTestCase {
         values = MetricsUtils.currentServerMetrics();
         Assert.assertEquals(3L, values.get("max_prep_processor_queue_size"));
 
-        Assert.assertThat((long)values.get("min_prep_processor_queue_time_ms"), greaterThan(0l));
+        Assert.assertThat((long)values.get("min_prep_processor_queue_time_ms"), greaterThan(20l));
         Assert.assertEquals(3L, values.get("cnt_prep_processor_queue_time_ms"));
 
         Assert.assertEquals(3L, values.get("cnt_prep_process_time"));


Mime
View raw message