Skip to content

Commit

Permalink
Use Timer instead of Hisgram on some metrics (#1242)
Browse files Browse the repository at this point in the history
For metrics below, we want to know both latency histogram and rate.
Timer, as a combination of Histogram and Meter, is the best choice.

networkClientSendAndPollTime
networkClientRequestQueueTime
networkClientRoundTripTime
networkClientTotalTime
putChunkOperationLatencyMs
  • Loading branch information
zzmao authored and jsjtzyy committed Aug 19, 2019
1 parent bbaf997 commit dd5edba
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -114,7 +115,7 @@ public List<ResponseInfo> sendAndPoll(List<RequestInfo> requestInfos, int pollTi
networkMetrics.networkClientException.inc();
} finally {
numPendingRequests.set(pendingRequests.size());
networkMetrics.networkClientSendAndPollTime.update(time.milliseconds() - startTime);
networkMetrics.networkClientSendAndPollTime.update(time.milliseconds() - startTime, TimeUnit.MILLISECONDS);
}
return responseInfoList;
}
Expand Down Expand Up @@ -363,15 +364,17 @@ private class RequestMetadata {
*/
void onRequestDequeue() {
requestDequeuedAtMs = time.milliseconds();
networkMetrics.networkClientRequestQueueTime.update(requestDequeuedAtMs - requestQueuedAtMs);
networkMetrics.networkClientRequestQueueTime.update(requestDequeuedAtMs - requestQueuedAtMs,
TimeUnit.MILLISECONDS);
}

/**
* Actions to be done on receiving response for the request sent
*/
void onResponseReceive() {
networkMetrics.networkClientRoundTripTime.update(time.milliseconds() - requestDequeuedAtMs);
networkMetrics.networkClientTotalTime.update(time.milliseconds() - requestQueuedAtMs);
networkMetrics.networkClientRoundTripTime.update(time.milliseconds() - requestDequeuedAtMs,
TimeUnit.MILLISECONDS);
networkMetrics.networkClientTotalTime.update(time.milliseconds() - requestQueuedAtMs, TimeUnit.MILLISECONDS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -86,11 +87,11 @@ public class NetworkMetrics {
public final Meter sslDecryptionTimeInUsPerKB;

// NetworkClient metrics
public final Histogram networkClientSendAndPollTime;
public final Histogram networkClientRequestQueueTime;
public final Histogram networkClientRoundTripTime;
public final Timer networkClientSendAndPollTime;
public final Timer networkClientRequestQueueTime;
public final Timer networkClientRoundTripTime;
// NetworkClient request queuing time plus round trip time.
public final Histogram networkClientTotalTime;
public final Timer networkClientTotalTime;

public final Counter connectionCheckoutTimeoutError;
public final Counter connectionNotAvailable;
Expand Down Expand Up @@ -125,10 +126,8 @@ public NetworkMetrics(MetricRegistry registry) {
transmissionSendPendingTime =
registry.histogram(MetricRegistry.name(Selector.class, "TransmissionSendPendingTime"));
transmissionSendAllTime = registry.histogram(MetricRegistry.name(Selector.class, "TransmissionSendTime"));
transmissionRoundTripTime =
registry.histogram(MetricRegistry.name(Selector.class, "TransmissionRoundTripTime"));
transmissionReceiveAllTime =
registry.histogram(MetricRegistry.name(Selector.class, "TransmissionReceiveTime"));
transmissionRoundTripTime = registry.histogram(MetricRegistry.name(Selector.class, "TransmissionRoundTripTime"));
transmissionReceiveAllTime = registry.histogram(MetricRegistry.name(Selector.class, "TransmissionReceiveTime"));
transmissionSendBytesRate = registry.meter(MetricRegistry.name(Selector.class, "TransmissionSendBytesRate"));
transmissionReceiveBytesRate = registry.meter(MetricRegistry.name(Selector.class, "TransmissionReceiveBytesRate"));
transmissionSendTime = registry.histogram(MetricRegistry.name(Selector.class, "TransmissionSendTime"));
Expand All @@ -152,12 +151,11 @@ public NetworkMetrics(MetricRegistry registry) {
sslDecryptionTimeInUsPerKB = registry.meter(MetricRegistry.name(Selector.class, "SslDecryptionTimeInUsPerKB"));

networkClientSendAndPollTime =
registry.histogram(MetricRegistry.name(NetworkClient.class, "NetworkClientSendAndPollTime"));
registry.timer(MetricRegistry.name(NetworkClient.class, "NetworkClientSendAndPollTime"));
networkClientRequestQueueTime =
registry.histogram(MetricRegistry.name(NetworkClient.class, "NetworkClientRequestQueueTime"));
networkClientRoundTripTime =
registry.histogram(MetricRegistry.name(NetworkClient.class, "NetworkClientRoundTripTime"));
networkClientTotalTime = registry.histogram(MetricRegistry.name(NetworkClient.class, "NetworkClientTotalTime"));
registry.timer(MetricRegistry.name(NetworkClient.class, "NetworkClientRequestQueueTime"));
networkClientRoundTripTime = registry.timer(MetricRegistry.name(NetworkClient.class, "NetworkClientRoundTripTime"));
networkClientTotalTime = registry.timer(MetricRegistry.name(NetworkClient.class, "NetworkClientTotalTime"));
connectionCheckoutTimeoutError =
registry.counter(MetricRegistry.name(NetworkClient.class, "ConnectionCheckoutTimeoutError"));
connectionNotAvailable = registry.counter(MetricRegistry.name(NetworkClient.class, "ConnectionNotAvailable"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.github.ambry.clustermap.ClusterMap;
import com.github.ambry.clustermap.DataNodeId;
import com.github.ambry.clustermap.DiskId;
Expand Down Expand Up @@ -73,7 +74,7 @@ public class NonBlockingRouterMetrics {
// Latency.
public final Histogram putBlobOperationLatencyMs;
public final Histogram stitchBlobOperationLatencyMs;
public final Histogram putChunkOperationLatencyMs;
public final Timer putChunkOperationLatencyMs;
public final Histogram getBlobInfoOperationLatencyMs;
public final Histogram getBlobOperationLatencyMs;
public final Histogram getBlobOperationTotalTimeMs;
Expand Down Expand Up @@ -257,7 +258,7 @@ public NonBlockingRouterMetrics(ClusterMap clusterMap, RouterConfig routerConfig
stitchBlobOperationLatencyMs =
metricRegistry.histogram(MetricRegistry.name(PutOperation.class, "StitchBlobOperationLatencyMs"));
putChunkOperationLatencyMs =
metricRegistry.histogram(MetricRegistry.name(PutOperation.class, "PutChunkOperationLatencyMs"));
metricRegistry.timer(MetricRegistry.name(PutOperation.class, "PutChunkOperationLatencyMs"));
getBlobInfoOperationLatencyMs =
metricRegistry.histogram(MetricRegistry.name(GetBlobInfoOperation.class, "GetBlobInfoOperationLatencyMs"));
getBlobOperationLatencyMs =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import org.slf4j.Logger;
Expand Down Expand Up @@ -503,7 +503,7 @@ private void onChunkOperationComplete(PutChunk chunk) {
if (chunk.chunkBlobProperties.isEncrypted()) {
routerMetrics.putEncryptedChunkOperationLatencyMs.update(operationLatencyMs);
} else {
routerMetrics.putChunkOperationLatencyMs.update(operationLatencyMs);
routerMetrics.putChunkOperationLatencyMs.update(operationLatencyMs, TimeUnit.MILLISECONDS);
}
chunk.clear();
}
Expand Down

0 comments on commit dd5edba

Please sign in to comment.