lvfangmin commented on a change in pull request #850: ZOOKEEPER-3309: Add sync 
processor metrics
URL: https://github.com/apache/zookeeper/pull/850#discussion_r265851070
 
 

 ##########
 File path: 
zookeeper-server/src/main/java/org/apache/zookeeper/server/SyncRequestProcessor.java
 ##########
 @@ -117,49 +119,41 @@ public void run() {
                 if (si == requestOfDeath) {
                     break;
                 }
-                if (si != null) {
-                    // track the number of records written to the log
-                    if (zks.getZKDatabase().append(si)) {
-                        logCount++;
-                        if (logCount > (snapCount / 2 + randRoll)) {
-                            randRoll = r.nextInt(snapCount/2);
-                            // roll the log
-                            zks.getZKDatabase().rollLog();
-                            // take a snapshot
-                            if (snapInProcess != null && 
snapInProcess.isAlive()) {
-                                LOG.warn("Too busy to snap, skipping");
-                            } else {
-                                snapInProcess = new ZooKeeperThread("Snapshot 
Thread") {
-                                        public void run() {
-                                            try {
-                                                zks.takeSnapshot();
-                                            } catch(Exception e) {
-                                                LOG.warn("Unexpected 
exception", e);
-                                            }
+                long startProcessTime = Time.currentElapsedTime();
+                ServerMetrics.SYNC_PROCESSOR_REAL_QUEUE_TIME.add(
+                        startProcessTime - si.syncQueueStartTime);
+                // track the number of records written to the log
+                if (zks.getZKDatabase().append(si)) {
+                    logCount++;
+                    if (logCount > (snapCount / 2 + randRoll)) {
+                        randRoll = r.nextInt(snapCount/2);
+                        // roll the log
+                        zks.getZKDatabase().rollLog();
+                        // take a snapshot
+                        if (snapInProcess != null && snapInProcess.isAlive()) {
+                            LOG.warn("Too busy to snap, skipping");
+                        } else {
+                            snapInProcess = new ZooKeeperThread("Snapshot 
Thread") {
+                                    public void run() {
+                                        try {
+                                            zks.takeSnapshot();
+                                        } catch(Exception e) {
+                                            LOG.warn("Unexpected exception", 
e);
                                         }
-                                    };
-                                snapInProcess.start();
-                            }
-                            logCount = 0;
+                                    }
+                                };
+                            snapInProcess.start();
                         }
-                    } else if (toFlush.isEmpty()) {
 
 Review comment:
   This is the legacy code which won't be used now, we can get rid of it, but 
it's better to keep each PR simple with a single purpose, which will make the 
code review and the future reference easier.
   
   If spotbugs complains things which not caused by the change here, we should 
leave it as is, and fix it in another PR.

----------------------------------------------------------------
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

Reply via email to