You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2018/01/16 23:19:16 UTC

[geode] 01/02: GEODE-4290 add operation time statistics to the protobuf server

This is an automated email from the ASF dual-hosted git repository.

bschuchardt pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 13364a301b495d42c02a9ce5b38484a3c6f83366
Author: Bruce Schuchardt <bs...@pivotal.io>
AuthorDate: Tue Jan 16 12:42:45 2018 -0800

    GEODE-4290 add operation time statistics to the protobuf server
    
    Time spent processing operations is now captured using System.nanoTime().
---
 .../internal/protocol/statistics/NoOpStatistics.java     | 10 ++++++++++
 .../protocol/statistics/ProtocolClientStatistics.java    | 12 ++++++++++++
 .../statistics/ProtobufClientStatisticsImpl.java         | 16 +++++++++++++++-
 .../v1/operations/GetAllRequestOperationHandler.java     |  2 ++
 .../v1/operations/GetRequestOperationHandler.java        |  2 ++
 .../v1/operations/PutAllRequestOperationHandler.java     |  2 ++
 .../v1/operations/PutRequestOperationHandler.java        |  3 +++
 .../v1/operations/RemoveRequestOperationHandler.java     |  3 +++
 8 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/statistics/NoOpStatistics.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/statistics/NoOpStatistics.java
index 8bacd32..88cd89b 100644
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/statistics/NoOpStatistics.java
+++ b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/statistics/NoOpStatistics.java
@@ -44,4 +44,14 @@ public class NoOpStatistics implements ProtocolClientStatistics {
   public void incAuthenticationFailures() {
 
   }
+
+  @Override
+  public long startOperation() {
+    return 0;
+  }
+
+  @Override
+  public void endOperation(long startOperationTime) {
+
+  }
 }
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/statistics/ProtocolClientStatistics.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/statistics/ProtocolClientStatistics.java
index 9b6ca63..bf8359a 100644
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/statistics/ProtocolClientStatistics.java
+++ b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/statistics/ProtocolClientStatistics.java
@@ -30,4 +30,16 @@ public interface ProtocolClientStatistics {
   void incAuthorizationViolations();
 
   void incAuthenticationFailures();
+
+  /**
+   * Invoke this at the start of an operation and then invoke endOperation in a finally block
+   */
+  long startOperation();
+
+  /**
+   * record the end of an operation. The parameter value should be from startOperation and
+   * endOperation must be invoked in the same thread as startOperation because we're using
+   * System.nanoTime()
+   */
+  void endOperation(long startOperationTime);
 }
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/statistics/ProtobufClientStatisticsImpl.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/statistics/ProtobufClientStatisticsImpl.java
index 7b40c88..58bcccb 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/statistics/ProtobufClientStatisticsImpl.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/statistics/ProtobufClientStatisticsImpl.java
@@ -35,6 +35,7 @@ public class ProtobufClientStatisticsImpl implements ProtocolClientStatistics {
   private final int messagesSentId;
   private final int authorizationViolationsId;
   private final int authenticationFailuresId;
+  private final int operationTimeId;
 
   public ProtobufClientStatisticsImpl(StatisticsFactory statisticsFactory, String statisticsName) {
     if (statisticsFactory == null) {
@@ -58,7 +59,9 @@ public class ProtobufClientStatisticsImpl implements ProtocolClientStatistics {
         statisticsFactory.createLongCounter("messagesReceived", "Messages received from clients.",
             "messages"),
         statisticsFactory.createLongCounter("messagesSent", "Messages sent to clients.",
-            "messages")};
+            "messages"),
+        statisticsFactory.createLongCounter("operationTime", "Time spent performing operations",
+            "nanoseconds")};
     statType = statisticsFactory.createType(getStatsName(), "Protobuf client/server statistics",
         serverStatDescriptors);
     this.stats = statisticsFactory.createAtomicStatistics(statType, statisticsName);
@@ -71,6 +74,7 @@ public class ProtobufClientStatisticsImpl implements ProtocolClientStatistics {
     bytesSentId = this.stats.nameToId("bytesSent");
     messagesReceivedId = this.stats.nameToId("messagesReceived");
     messagesSentId = this.stats.nameToId("messagesSent");
+    operationTimeId = this.stats.nameToId("operationTime");
   }
 
 
@@ -112,4 +116,14 @@ public class ProtobufClientStatisticsImpl implements ProtocolClientStatistics {
   public void incAuthenticationFailures() {
     stats.incLong(authenticationFailuresId, 1);
   }
+
+  @Override
+  public long startOperation() {
+    return System.nanoTime();
+  }
+
+  @Override
+  public void endOperation(long startOperationTime) {
+    stats.incLong(operationTimeId, System.nanoTime() - startOperationTime);
+  }
 }
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java
index d000dea..e2d38bd 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java
@@ -59,6 +59,7 @@ public class GetAllRequestOperationHandler
           .of(ProtobufResponseUtilities.makeErrorResponse(SERVER_ERROR, "Region not found"));
     }
 
+    long startTime = messageExecutionContext.getStatistics().startOperation();
     Map<Boolean, List<Object>> resultsCollection;
     try {
       ((InternalCache) messageExecutionContext.getCache()).setReadSerializedForCurrentThread(true);
@@ -68,6 +69,7 @@ public class GetAllRequestOperationHandler
           .collect(Collectors.partitioningBy(x -> x instanceof BasicTypes.Entry));
     } finally {
       ((InternalCache) messageExecutionContext.getCache()).setReadSerializedForCurrentThread(false);
+      messageExecutionContext.getStatistics().endOperation(startTime);
     }
     RegionAPI.GetAllResponse.Builder responseBuilder = RegionAPI.GetAllResponse.newBuilder();
 
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandler.java
index 254148e..3016d72 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandler.java
@@ -52,6 +52,7 @@ public class GetRequestOperationHandler
       return Failure
           .of(ProtobufResponseUtilities.makeErrorResponse(SERVER_ERROR, "Region not found"));
     }
+    long startOperationTime = messageExecutionContext.getStatistics().startOperation();
 
     try {
       ((InternalCache) messageExecutionContext.getCache()).setReadSerializedForCurrentThread(true);
@@ -71,6 +72,7 @@ public class GetRequestOperationHandler
           ProtobufResponseUtilities.makeErrorResponse(INVALID_REQUEST, "Encoding not supported."));
     } finally {
       ((InternalCache) messageExecutionContext.getCache()).setReadSerializedForCurrentThread(false);
+      messageExecutionContext.getStatistics().endOperation(startOperationTime);
     }
   }
 }
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java
index b93f815..353f0e6 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java
@@ -59,10 +59,12 @@ public class PutAllRequestOperationHandler
           "Region passed does not exist: " + regionName));
     }
 
+    long startTime = messageExecutionContext.getStatistics().startOperation();
     RegionAPI.PutAllResponse.Builder builder = RegionAPI.PutAllResponse.newBuilder()
         .addAllFailedKeys(putAllRequest.getEntryList().stream()
             .map((entry) -> singlePut(serializationService, region, entry)).filter(Objects::nonNull)
             .collect(Collectors.toList()));
+    messageExecutionContext.getStatistics().endOperation(startTime);
     return Success.of(builder.build());
   }
 
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandler.java
index 60a8d7b..dd06fad 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandler.java
@@ -52,6 +52,7 @@ public class PutRequestOperationHandler
           "Region passed by client did not exist: " + regionName));
     }
 
+    long startTime = messageExecutionContext.getStatistics().startOperation();
     try {
       BasicTypes.Entry entry = request.getEntry();
 
@@ -68,6 +69,8 @@ public class PutRequestOperationHandler
       logger.error("Got error when decoding Put request: {}", ex);
       return Failure
           .of(ProtobufResponseUtilities.makeErrorResponse(INVALID_REQUEST, ex.toString()));
+    } finally {
+      messageExecutionContext.getStatistics().endOperation(startTime);
     }
   }
 }
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandler.java
index 6b345ba..d3b6e59 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandler.java
@@ -52,6 +52,7 @@ public class RemoveRequestOperationHandler
           .of(ProtobufResponseUtilities.makeErrorResponse(SERVER_ERROR, "Region not found"));
     }
 
+    long startTime = messageExecutionContext.getStatistics().startOperation();
     try {
       Object decodedKey = serializationService.decode(request.getKey());
       region.remove(decodedKey);
@@ -62,6 +63,8 @@ public class RemoveRequestOperationHandler
       logger.error("Received Remove request with unsupported encoding: {}", ex);
       return Failure.of(ProtobufResponseUtilities.makeErrorResponse(INVALID_REQUEST,
           "Encoding not supported: " + ex.getMessage()));
+    } finally {
+      messageExecutionContext.getStatistics().endOperation(startTime);
     }
   }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.