Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up network related metrics. #1236

Merged
merged 2 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

25 changes: 20 additions & 5 deletions ambry-api/src/main/java/com.github.ambry/network/NetworkSend.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,34 @@ public class NetworkSend {
private final String connectionId;
// The bytes to be sent over the connection
private final Send payload;
// The creation time of this send
private final long sendCreateTimeInMs;
// The start time of this send
private final long sendStartTimeInMs;
private final NetworkSendMetrics metrics;
private long sendStartTimeInMs = -1;
private final Time time;
private final ServerNetworkResponseMetrics metrics;

public NetworkSend(String connectionId, Send payload, NetworkSendMetrics metrics, Time time) {
public NetworkSend(String connectionId, Send payload, ServerNetworkResponseMetrics metrics, Time time) {
this.connectionId = connectionId;
this.payload = payload;
this.sendCreateTimeInMs = time.milliseconds();
this.time = time;
this.sendStartTimeInMs = time.milliseconds();
this.metrics = metrics;
}

public long getSendCreateTimeInMs() {
return sendCreateTimeInMs;
}

public boolean maySetSendStartTimeInMs() {
if (sendStartTimeInMs == -1) {
sendStartTimeInMs = time.milliseconds();
return true;
} else {
return false;
}
}

public long getSendStartTimeInMs() {
return sendStartTimeInMs;
}
Expand All @@ -49,7 +64,7 @@ public Send getPayload() {
return payload;
}

public void onSendComplete() {
public void updateServerResponseMetrics() {
if (metrics != null) {
metrics.updateSendTime(time.milliseconds() - sendStartTimeInMs);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
/**
* Tracks a set of metrics for a network response by a Server
*/
public class ServerNetworkResponseMetrics extends NetworkSendMetrics {
public class ServerNetworkResponseMetrics {

private final Histogram responseQueueTime;
private final Histogram responseSendTime;
private final Histogram responseTotalTime;
private final Histogram responseSendTimeBySize;
private final Histogram responseTotalTimeBySize;
Expand All @@ -30,8 +31,8 @@ public class ServerNetworkResponseMetrics extends NetworkSendMetrics {
public ServerNetworkResponseMetrics(Histogram responseQueueTime, Histogram responseSendTime,
Histogram responseTotalTime, Histogram responseSendTimeBySize, Histogram responseTotalTimeBySize,
long timeSpentTillNow) {
super(responseSendTime);
this.responseQueueTime = responseQueueTime;
this.responseSendTime = responseSendTime;
this.responseTotalTime = responseTotalTime;
this.responseSendTimeBySize = responseSendTimeBySize;
this.responseTotalTimeBySize = responseTotalTimeBySize;
Expand All @@ -51,9 +52,8 @@ public void updateQueueTime(long value) {
* Updates few metrics when send completes
* @param value the time spent by the response to be completely sent
*/
@Override
public void updateSendTime(long value) {
super.updateSendTime(value);
responseSendTime.update(value);
if (responseSendTimeBySize != null) {
responseSendTimeBySize.update(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public HelixVcrCluster(CloudConfig cloudConfig, ClusterMapConfig clusterMapConfi
}

/**
* Add {@link PartitionId} to assignedPartitionIds set, if {@parm partitionIdStr} valid.
* Add {@link PartitionId} to assignedPartitionIds set, if {@param partitionIdStr} valid.
* Used in {@link HelixVcrStateModel} if current VCR becomes leader of a partition.
* @param partitionIdStr The partitionIdStr notified by Helix.
*/
Expand All @@ -104,7 +104,7 @@ public void addPartition(String partitionIdStr) {
}

/**
* Remove {@link PartitionId} from assignedPartitionIds set, if {@parm partitionIdStr} valid.
* Remove {@link PartitionId} from assignedPartitionIds set, if {@param partitionIdStr} valid.
* Used in {@link HelixVcrStateModel} if current VCR becomes offline or standby a partition.
* @param partitionIdStr The partitionIdStr notified by Helix.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ public List<ResponseInfo> sendAndPoll(List<RequestInfo> requestInfos, int pollTi
List<ResponseInfo> responseInfoList = new ArrayList<>();
try {
for (RequestInfo requestInfo : requestInfos) {
ClientNetworkRequestMetrics clientNetworkRequestMetrics =
new ClientNetworkRequestMetrics(networkMetrics.requestQueueTime, networkMetrics.requestSendTime,
networkMetrics.requestSendTotalTime, 0);
pendingRequests.add(new RequestMetadata(time.milliseconds(), requestInfo, clientNetworkRequestMetrics));
pendingRequests.add(new RequestMetadata(requestInfo));
}
List<NetworkSend> sends = prepareSends(responseInfoList);
if (networkConfig.networkClientEnableConnectionReplenishment) {
Expand Down Expand Up @@ -185,8 +182,7 @@ private List<NetworkSend> prepareSends(List<ResponseInfo> responseInfoList) {
requestMetadata.pendingConnectionId = null;
}
logger.trace("Connection checkout succeeded for {}:{} with connectionId {} ", host, port, connId);
sends.add(new NetworkSend(connId, requestMetadata.requestInfo.getRequest(),
requestMetadata.clientNetworkRequestMetrics, time));
sends.add(new NetworkSend(connId, requestMetadata.requestInfo.getRequest(), null, time));
connectionIdToRequestInFlight.put(connId, requestMetadata);
iter.remove();
requestMetadata.onRequestDequeue();
Expand Down Expand Up @@ -340,8 +336,6 @@ public void wakeup() {
* A class that consists of a {@link RequestInfo} and some metadata related to the request
*/
private class RequestMetadata {
// to track network request related metrics
ClientNetworkRequestMetrics clientNetworkRequestMetrics;
// the RequestInfo associated with the request.
RequestInfo requestInfo;
// the time at which this request was queued.
Expand All @@ -358,28 +352,26 @@ private class RequestMetadata {
// check out this connection. This, however, does not affect correctness.
private String pendingConnectionId;

RequestMetadata(long requestQueuedAtMs, RequestInfo requestInfo,
ClientNetworkRequestMetrics clientNetworkRequestMetrics) {
RequestMetadata(RequestInfo requestInfo) {
this.requestInfo = requestInfo;
this.requestQueuedAtMs = requestQueuedAtMs;
this.clientNetworkRequestMetrics = clientNetworkRequestMetrics;
this.requestQueuedAtMs = time.milliseconds();
this.pendingConnectionId = null;
}

/**
* Actions to be done on dequeue of this request and ready to be sent
*/
void onRequestDequeue() {
requestDequeuedAtMs = System.currentTimeMillis();
clientNetworkRequestMetrics.updateQueueTime(requestDequeuedAtMs - requestQueuedAtMs);
requestDequeuedAtMs = time.milliseconds();
networkMetrics.networkClientRequestQueueTime.update(requestDequeuedAtMs - requestQueuedAtMs);
}

/**
* Actions to be done on receiving response for the request sent
*/
void onResponseReceive() {
networkMetrics.requestResponseRoundTripTime.update(System.currentTimeMillis() - requestDequeuedAtMs);
networkMetrics.requestResponseTotalTime.update(System.currentTimeMillis() - requestQueuedAtMs);
networkMetrics.networkClientRoundTripTime.update(time.milliseconds() - requestDequeuedAtMs);
networkMetrics.networkClientTotalTime.update(time.milliseconds() - requestQueuedAtMs);
}
}
}
Loading