This is an automated email from the ASF dual-hosted git repository.
szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 53d5af75a RATIS-2092. Add metrics to expose number of zero-copy
unclosed messages (#1095)
53d5af75a is described below
commit 53d5af75a2d86efed78931028a504cecd16018f5
Author: Duong Nguyen <[email protected]>
AuthorDate: Thu May 23 00:29:45 2024 -0700
RATIS-2092. Add metrics to expose number of zero-copy unclosed messages
(#1095)
---
.../main/java/org/apache/ratis/grpc/metrics/ZeroCopyMetrics.java | 6 ++++++
.../org/apache/ratis/grpc/server/GrpcClientProtocolService.java | 1 +
.../org/apache/ratis/grpc/server/GrpcServerProtocolService.java | 1 +
.../java/org/apache/ratis/grpc/util/ZeroCopyMessageMarshaller.java | 4 ++++
4 files changed, 12 insertions(+)
diff --git
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/ZeroCopyMetrics.java
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/ZeroCopyMetrics.java
index fec2135a9..1fcc317f9 100644
---
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/ZeroCopyMetrics.java
+++
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/ZeroCopyMetrics.java
@@ -24,6 +24,8 @@ import org.apache.ratis.metrics.RatisMetrics;
import
org.apache.ratis.thirdparty.com.google.common.annotations.VisibleForTesting;
import org.apache.ratis.thirdparty.com.google.protobuf.AbstractMessage;
+import java.util.function.Supplier;
+
public class ZeroCopyMetrics extends RatisMetrics {
private static final String RATIS_GRPC_METRICS_APP_NAME = "ratis_grpc";
private static final String RATIS_GRPC_METRICS_COMP_NAME = "zero_copy";
@@ -43,6 +45,10 @@ public class ZeroCopyMetrics extends RatisMetrics {
RATIS_GRPC_METRICS_COMP_NAME, RATIS_GRPC_METRICS_DESC));
}
+ public void addUnreleased(String name, Supplier<Integer> unreleased) {
+ getRegistry().gauge(name + "_num_unreleased_messages", () -> unreleased);
+ }
+
public void onZeroCopyMessage(AbstractMessage ignored) {
zeroCopyMessages.inc();
diff --git
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcClientProtocolService.java
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcClientProtocolService.java
index 97b011890..d1ef99c74 100644
---
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcClientProtocolService.java
+++
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcClientProtocolService.java
@@ -161,6 +161,7 @@ class GrpcClientProtocolService extends
RaftClientProtocolServiceImplBase {
this.executor = executor;
this.zeroCopyRequestMarshaller = new
ZeroCopyMessageMarshaller<>(RaftClientRequestProto.getDefaultInstance(),
zeroCopyMetrics::onZeroCopyMessage,
zeroCopyMetrics::onNonZeroCopyMessage, zeroCopyMetrics::onReleasedMessage);
+ zeroCopyMetrics.addUnreleased("client_protocol",
zeroCopyRequestMarshaller::getUnclosedCount);
}
RaftPeerId getId() {
diff --git
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java
index 00cb699cf..4257f0038 100644
---
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java
+++
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java
@@ -232,6 +232,7 @@ class GrpcServerProtocolService extends
RaftServerProtocolServiceImplBase {
this.server = server;
this.zeroCopyRequestMarshaller = new
ZeroCopyMessageMarshaller<>(AppendEntriesRequestProto.getDefaultInstance(),
zeroCopyMetrics::onZeroCopyMessage,
zeroCopyMetrics::onNonZeroCopyMessage, zeroCopyMetrics::onReleasedMessage);
+ zeroCopyMetrics.addUnreleased("server_protocol",
zeroCopyRequestMarshaller::getUnclosedCount);
}
RaftPeerId getId() {
diff --git
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/util/ZeroCopyMessageMarshaller.java
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/util/ZeroCopyMessageMarshaller.java
index 057550c13..3cdbc07c7 100644
---
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/util/ZeroCopyMessageMarshaller.java
+++
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/util/ZeroCopyMessageMarshaller.java
@@ -226,4 +226,8 @@ public class ZeroCopyMessageMarshaller<T extends
MessageLite> implements Prototy
public InputStream popStream(T message) {
return unclosedStreams.remove(message);
}
+
+ public int getUnclosedCount() {
+ return unclosedStreams.size();
+ }
}