Visitar URL original
fix: fix client blocking latency · googleapis/java-bigtable@9179a0a · GitHub
Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.

Commit 9179a0a

Browse files
committed
fix: fix client blocking latency
1 parent 0330d77 commit 9179a0a

6 files changed

Lines changed: 25 additions & 14 deletions

File tree

‎google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableGrpcStreamTracer.java‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.stub.metrics;
1717

18-
import com.google.common.base.Stopwatch;
19-
import io.grpc.Attributes;
2018
import io.grpc.ClientStreamTracer;
2119
import io.grpc.Metadata;
22-
import java.util.concurrent.TimeUnit;
2320

2421
/**
2522
* Records the time a request is enqueued in a grpc channel queue. This a bridge between gRPC stream
@@ -28,21 +25,15 @@
2825
*/
2926
class BigtableGrpcStreamTracer extends ClientStreamTracer {
3027

31-
private final Stopwatch stopwatch = Stopwatch.createUnstarted();
3228
private final BigtableTracer tracer;
3329

3430
public BigtableGrpcStreamTracer(BigtableTracer tracer) {
3531
this.tracer = tracer;
3632
}
3733

38-
@Override
39-
public void streamCreated(Attributes transportAttrs, Metadata headers) {
40-
stopwatch.start();
41-
}
42-
4334
@Override
4435
public void outboundMessageSent(int seqNo, long optionalWireSize, long optionalUncompressedSize) {
45-
tracer.grpcChannelQueuedLatencies(stopwatch.elapsed(TimeUnit.NANOSECONDS));
36+
tracer.grpcMessageSent();
4637
}
4738

4839
static class Factory extends ClientStreamTracer.Factory {

‎google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableTracer.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ public void setLocations(String zone, String cluster) {
8383
// noop
8484
}
8585

86+
@Deprecated
87+
/** @deprecated {@link #grpcMessageSent()} is called instead. */
8688
public void grpcChannelQueuedLatencies(long queuedTimeMs) {
8789
// noop
8890
}
91+
92+
/** Called when the message is sent on a grpc channel. */
93+
public void grpcMessageSent() {
94+
// noop
95+
}
8996
}

‎google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ public void batchRequestThrottled(long throttledTimeNanos) {
263263
}
264264

265265
@Override
266-
public void grpcChannelQueuedLatencies(long queuedTimeNanos) {
267-
totalClientBlockingTime.addAndGet(queuedTimeNanos);
266+
public void grpcMessageSent() {
267+
totalClientBlockingTime.addAndGet(attemptTimer.elapsed(TimeUnit.NANOSECONDS));
268268
}
269269

270270
@Override

‎google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,11 @@ public void grpcChannelQueuedLatencies(long queuedTimeMs) {
225225
tracer.grpcChannelQueuedLatencies(queuedTimeMs);
226226
}
227227
}
228+
229+
@Override
230+
public void grpcMessageSent() {
231+
for (BigtableTracer tracer : bigtableTracers) {
232+
tracer.grpcMessageSent();
233+
}
234+
}
228235
}

‎google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,8 @@ public void testQueuedOnChannelUnaryLatencies() {
692692
.put(CLIENT_NAME_KEY, CLIENT_NAME)
693693
.build();
694694

695-
long expected = CHANNEL_BLOCKING_LATENCY * 2 / 3;
696695
long actual = getAggregatedValue(clientLatency, attributes);
697-
assertThat(actual).isAtLeast(expected);
696+
assertThat(actual).isAtLeast(CHANNEL_BLOCKING_LATENCY);
698697
}
699698

700699
@Test

‎google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracerTest.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,11 @@ public void testRequestBlockedOnChannel() {
258258
verify(child3, times(1)).grpcChannelQueuedLatencies(5L);
259259
verify(child4, times(1)).grpcChannelQueuedLatencies(5L);
260260
}
261+
262+
@Test
263+
public void testGrpcMessageSent() {
264+
compositeTracer.grpcMessageSent();
265+
verify(child3, times(1)).grpcMessageSent();
266+
verify(child4, times(1)).grpcMessageSent();
267+
}
261268
}

0 commit comments

Comments
 (0)