Skip to content

Commit c775e4e

Browse files
committed
Separate inbound & outbound histograms
1 parent b527e82 commit c775e4e

File tree

4 files changed

+94
-55
lines changed

4 files changed

+94
-55
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/nodes.stats/60_transport_stats.yml

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"Transport handling time histogram":
2626
- skip:
2727
version: " - 8.0.99"
28-
reason: "handling_time_histogram was added in 8.1"
28+
reason: "handling_time_histograms were added in 8.1"
2929
features: [arbitrary_key]
3030

3131
- do:
@@ -37,16 +37,31 @@
3737
nodes.stats:
3838
metric: [ transport ]
3939

40-
- length: { nodes.$node_id.transport.handling_time_histogram: 17 }
40+
- length: { nodes.$node_id.transport.inbound_handling_time_histogram: 18 }
4141

42-
- gte: { nodes.$node_id.transport.handling_time_histogram.0.count: 0 }
43-
- is_false: nodes.$node_id.transport.handling_time_histogram.0.ge_millis
44-
- match: { nodes.$node_id.transport.handling_time_histogram.0.lt_millis: 1 }
42+
- gte: { nodes.$node_id.transport.inbound_handling_time_histogram.0.count: 0 }
43+
- is_false: nodes.$node_id.transport.inbound_handling_time_histogram.0.ge_millis
44+
- match: { nodes.$node_id.transport.inbound_handling_time_histogram.0.lt_millis: 1 }
4545

46-
- gte: { nodes.$node_id.transport.handling_time_histogram.1.count: 0 }
47-
- match: { nodes.$node_id.transport.handling_time_histogram.1.ge_millis: 1 }
48-
- match: { nodes.$node_id.transport.handling_time_histogram.1.lt_millis: 2 }
46+
- gte: { nodes.$node_id.transport.inbound_handling_time_histogram.1.count: 0 }
47+
- match: { nodes.$node_id.transport.inbound_handling_time_histogram.1.ge_millis: 1 }
48+
- match: { nodes.$node_id.transport.inbound_handling_time_histogram.1.lt_millis: 2 }
4949

50-
- gte: { nodes.$node_id.transport.handling_time_histogram.16.count: 0 }
51-
- match: { nodes.$node_id.transport.handling_time_histogram.16.ge_millis: 65536 }
52-
- is_false: nodes.$node_id.transport.handling_time_histogram.16.lt_millis
50+
- gte: { nodes.$node_id.transport.inbound_handling_time_histogram.17.count: 0 }
51+
- match: { nodes.$node_id.transport.inbound_handling_time_histogram.17.ge_millis: 65536 }
52+
- is_false: nodes.$node_id.transport.inbound_handling_time_histogram.17.lt_millis
53+
54+
55+
- length: { nodes.$node_id.transport.outbound_handling_time_histogram: 18 }
56+
57+
- gte: { nodes.$node_id.transport.outbound_handling_time_histogram.0.count: 0 }
58+
- is_false: nodes.$node_id.transport.outbound_handling_time_histogram.0.ge_millis
59+
- match: { nodes.$node_id.transport.outbound_handling_time_histogram.0.lt_millis: 1 }
60+
61+
- gte: { nodes.$node_id.transport.outbound_handling_time_histogram.1.count: 0 }
62+
- match: { nodes.$node_id.transport.outbound_handling_time_histogram.1.ge_millis: 1 }
63+
- match: { nodes.$node_id.transport.outbound_handling_time_histogram.1.lt_millis: 2 }
64+
65+
- gte: { nodes.$node_id.transport.outbound_handling_time_histogram.17.count: 0 }
66+
- match: { nodes.$node_id.transport.outbound_handling_time_histogram.17.ge_millis: 65536 }
67+
- is_false: nodes.$node_id.transport.outbound_handling_time_histogram.17.lt_millis

server/src/main/java/org/elasticsearch/transport/TcpTransport.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.common.io.stream.RecyclerBytesStreamOutput;
3030
import org.elasticsearch.common.io.stream.StreamInput;
3131
import org.elasticsearch.common.network.CloseableChannel;
32+
import org.elasticsearch.common.network.HandlingTimeTracker;
3233
import org.elasticsearch.common.network.NetworkAddress;
3334
import org.elasticsearch.common.network.NetworkService;
3435
import org.elasticsearch.common.network.NetworkUtils;
@@ -116,6 +117,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
116117

117118
private final TransportHandshaker handshaker;
118119
private final TransportKeepAlive keepAlive;
120+
private final HandlingTimeTracker outboundHandlingTimeTracker = new HandlingTimeTracker();
119121
private final OutboundHandler outboundHandler;
120122
private final InboundHandler inboundHandler;
121123
private final ResponseHandlers responseHandlers = new ResponseHandlers();
@@ -141,14 +143,7 @@ public TcpTransport(
141143
String nodeName = Node.NODE_NAME_SETTING.get(settings);
142144

143145
this.recycler = createRecycler(settings, pageCacheRecycler);
144-
this.outboundHandler = new OutboundHandler(
145-
nodeName,
146-
version,
147-
statsTracker,
148-
threadPool,
149-
recycler,
150-
networkService.getHandlingTimeTracker()
151-
);
146+
this.outboundHandler = new OutboundHandler(nodeName, version, statsTracker, threadPool, recycler, outboundHandlingTimeTracker);
152147
this.handshaker = new TransportHandshaker(
153148
version,
154149
threadPool,
@@ -927,7 +922,8 @@ public final TransportStats getStats() {
927922
bytesRead,
928923
messagesSent,
929924
bytesWritten,
930-
networkService.getHandlingTimeTracker().getHistogram()
925+
networkService.getHandlingTimeTracker().getHistogram(),
926+
outboundHandlingTimeTracker.getHistogram()
931927
);
932928
}
933929

server/src/main/java/org/elasticsearch/transport/TransportStats.java

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class TransportStats implements Writeable, ToXContentFragment {
2828
private final long rxSize;
2929
private final long txCount;
3030
private final long txSize;
31-
private final long[] handlingTimeBucketFrequencies;
31+
private final long[] inboundHandlingTimeBucketFrequencies;
32+
private final long[] outboundHandlingTimeBucketFrequencies;
3233

3334
public TransportStats(
3435
long serverOpen,
@@ -37,16 +38,18 @@ public TransportStats(
3738
long rxSize,
3839
long txCount,
3940
long txSize,
40-
long[] handlingTimeBucketFrequencies
41+
long[] inboundHandlingTimeBucketFrequencies,
42+
long[] outboundHandlingTimeBucketFrequencies
4143
) {
4244
this.serverOpen = serverOpen;
4345
this.totalOutboundConnections = totalOutboundConnections;
4446
this.rxCount = rxCount;
4547
this.rxSize = rxSize;
4648
this.txCount = txCount;
4749
this.txSize = txSize;
48-
this.handlingTimeBucketFrequencies = handlingTimeBucketFrequencies;
49-
assert assertHistogramConsistent();
50+
this.inboundHandlingTimeBucketFrequencies = inboundHandlingTimeBucketFrequencies;
51+
this.outboundHandlingTimeBucketFrequencies = outboundHandlingTimeBucketFrequencies;
52+
assert assertHistogramsConsistent();
5053
}
5154

5255
public TransportStats(StreamInput in) throws IOException {
@@ -57,14 +60,19 @@ public TransportStats(StreamInput in) throws IOException {
5760
txCount = in.readVLong();
5861
txSize = in.readVLong();
5962
if (in.getVersion().onOrAfter(Version.V_8_1_0) && in.readBoolean()) {
60-
handlingTimeBucketFrequencies = new long[HandlingTimeTracker.BUCKET_COUNT];
61-
for (int i = 0; i < handlingTimeBucketFrequencies.length; i++) {
62-
handlingTimeBucketFrequencies[i] = in.readVLong();
63+
inboundHandlingTimeBucketFrequencies = new long[HandlingTimeTracker.BUCKET_COUNT];
64+
for (int i = 0; i < inboundHandlingTimeBucketFrequencies.length; i++) {
65+
inboundHandlingTimeBucketFrequencies[i] = in.readVLong();
66+
}
67+
outboundHandlingTimeBucketFrequencies = new long[HandlingTimeTracker.BUCKET_COUNT];
68+
for (int i = 0; i < inboundHandlingTimeBucketFrequencies.length; i++) {
69+
outboundHandlingTimeBucketFrequencies[i] = in.readVLong();
6370
}
6471
} else {
65-
handlingTimeBucketFrequencies = new long[0];
72+
inboundHandlingTimeBucketFrequencies = new long[0];
73+
outboundHandlingTimeBucketFrequencies = new long[0];
6674
}
67-
assert assertHistogramConsistent();
75+
assert assertHistogramsConsistent();
6876
}
6977

7078
@Override
@@ -76,8 +84,12 @@ public void writeTo(StreamOutput out) throws IOException {
7684
out.writeVLong(txCount);
7785
out.writeVLong(txSize);
7886
if (out.getVersion().onOrAfter(Version.V_8_1_0)) {
79-
out.writeBoolean(handlingTimeBucketFrequencies.length > 0);
80-
for (long handlingTimeBucketFrequency : handlingTimeBucketFrequencies) {
87+
assert (inboundHandlingTimeBucketFrequencies.length > 0) == (outboundHandlingTimeBucketFrequencies.length > 0);
88+
out.writeBoolean(inboundHandlingTimeBucketFrequencies.length > 0);
89+
for (long handlingTimeBucketFrequency : inboundHandlingTimeBucketFrequencies) {
90+
out.writeVLong(handlingTimeBucketFrequency);
91+
}
92+
for (long handlingTimeBucketFrequency : outboundHandlingTimeBucketFrequencies) {
8193
out.writeVLong(handlingTimeBucketFrequency);
8294
}
8395
}
@@ -123,16 +135,21 @@ public ByteSizeValue getTxSize() {
123135
return txSize();
124136
}
125137

126-
public long[] getHandlingTimeBucketFrequencies() {
127-
return Arrays.copyOf(handlingTimeBucketFrequencies, handlingTimeBucketFrequencies.length);
138+
public long[] getInboundHandlingTimeBucketFrequencies() {
139+
return Arrays.copyOf(inboundHandlingTimeBucketFrequencies, inboundHandlingTimeBucketFrequencies.length);
128140
}
129141

130-
private boolean assertHistogramConsistent() {
131-
if (handlingTimeBucketFrequencies.length == 0) {
142+
public long[] getOutboundHandlingTimeBucketFrequencies() {
143+
return Arrays.copyOf(outboundHandlingTimeBucketFrequencies, outboundHandlingTimeBucketFrequencies.length);
144+
}
145+
146+
private boolean assertHistogramsConsistent() {
147+
assert inboundHandlingTimeBucketFrequencies.length == outboundHandlingTimeBucketFrequencies.length;
148+
if (inboundHandlingTimeBucketFrequencies.length == 0) {
132149
// Stats came from before v8.1
133150
assert Version.CURRENT.major == Version.V_8_0_0.major;
134151
} else {
135-
assert handlingTimeBucketFrequencies.length == HandlingTimeTracker.BUCKET_COUNT;
152+
assert inboundHandlingTimeBucketFrequencies.length == HandlingTimeTracker.BUCKET_COUNT;
136153
}
137154
return true;
138155
}
@@ -146,22 +163,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
146163
builder.humanReadableField(Fields.RX_SIZE_IN_BYTES, Fields.RX_SIZE, new ByteSizeValue(rxSize));
147164
builder.field(Fields.TX_COUNT, txCount);
148165
builder.humanReadableField(Fields.TX_SIZE_IN_BYTES, Fields.TX_SIZE, new ByteSizeValue(txSize));
149-
if (handlingTimeBucketFrequencies.length > 0) {
150-
final int[] handlingTimeBucketBounds = HandlingTimeTracker.getBucketUpperBounds();
151-
assert handlingTimeBucketFrequencies.length == handlingTimeBucketBounds.length + 1;
152-
builder.startArray(Fields.HANDLING_TIME_HISTOGRAM);
153-
for (int i = 0; i < handlingTimeBucketFrequencies.length; i++) {
154-
builder.startObject();
155-
if (i > 0 && i <= handlingTimeBucketBounds.length) {
156-
builder.field("ge_millis", handlingTimeBucketBounds[i - 1]);
157-
}
158-
if (i < handlingTimeBucketBounds.length) {
159-
builder.field("lt_millis", handlingTimeBucketBounds[i]);
160-
}
161-
builder.field("count", handlingTimeBucketFrequencies[i]);
162-
builder.endObject();
163-
}
164-
builder.endArray();
166+
if (inboundHandlingTimeBucketFrequencies.length > 0) {
167+
histogramToXContent(builder, inboundHandlingTimeBucketFrequencies, Fields.INBOUND_HANDLING_TIME_HISTOGRAM);
168+
histogramToXContent(builder, outboundHandlingTimeBucketFrequencies, Fields.OUTBOUND_HANDLING_TIME_HISTOGRAM);
165169
} else {
166170
// Stats came from before v8.1
167171
assert Version.CURRENT.major == Version.V_8_0_0.major;
@@ -170,6 +174,24 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
170174
return builder;
171175
}
172176

177+
private void histogramToXContent(XContentBuilder builder, long[] bucketFrequencies, String fieldName) throws IOException {
178+
final int[] bucketBounds = HandlingTimeTracker.getBucketUpperBounds();
179+
assert bucketFrequencies.length == bucketBounds.length + 1;
180+
builder.startArray(fieldName);
181+
for (int i = 0; i < bucketFrequencies.length; i++) {
182+
builder.startObject();
183+
if (i > 0 && i <= bucketBounds.length) {
184+
builder.field("ge_millis", bucketBounds[i - 1]);
185+
}
186+
if (i < bucketBounds.length) {
187+
builder.field("lt_millis", bucketBounds[i]);
188+
}
189+
builder.field("count", bucketFrequencies[i]);
190+
builder.endObject();
191+
}
192+
builder.endArray();
193+
}
194+
173195
static final class Fields {
174196
static final String TRANSPORT = "transport";
175197
static final String SERVER_OPEN = "server_open";
@@ -180,6 +202,7 @@ static final class Fields {
180202
static final String TX_COUNT = "tx_count";
181203
static final String TX_SIZE = "tx_size";
182204
static final String TX_SIZE_IN_BYTES = "tx_size_in_bytes";
183-
static final String HANDLING_TIME_HISTOGRAM = "handling_time_histogram";
205+
static final String INBOUND_HANDLING_TIME_HISTOGRAM = "inbound_handling_time_histogram";
206+
static final String OUTBOUND_HANDLING_TIME_HISTOGRAM = "outbound_handling_time_histogram";
184207
}
185208
}

server/src/test/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStatsTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,12 @@ public void testSerialization() throws IOException {
241241
assertEquals(nodeStats.getTransport().getTxCount(), deserializedNodeStats.getTransport().getTxCount());
242242
assertEquals(nodeStats.getTransport().getTxSize(), deserializedNodeStats.getTransport().getTxSize());
243243
assertArrayEquals(
244-
nodeStats.getTransport().getHandlingTimeBucketFrequencies(),
245-
deserializedNodeStats.getTransport().getHandlingTimeBucketFrequencies()
244+
nodeStats.getTransport().getInboundHandlingTimeBucketFrequencies(),
245+
deserializedNodeStats.getTransport().getInboundHandlingTimeBucketFrequencies()
246+
);
247+
assertArrayEquals(
248+
nodeStats.getTransport().getOutboundHandlingTimeBucketFrequencies(),
249+
deserializedNodeStats.getTransport().getOutboundHandlingTimeBucketFrequencies()
246250
);
247251
}
248252
if (nodeStats.getHttp() == null) {
@@ -679,6 +683,7 @@ public static NodeStats createNodeStats() {
679683
randomNonNegativeLong(),
680684
randomNonNegativeLong(),
681685
randomNonNegativeLong(),
686+
IntStream.range(0, HandlingTimeTracker.BUCKET_COUNT).mapToLong(i -> randomNonNegativeLong()).toArray(),
682687
IntStream.range(0, HandlingTimeTracker.BUCKET_COUNT).mapToLong(i -> randomNonNegativeLong()).toArray()
683688
)
684689
: null;

0 commit comments

Comments
 (0)