Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit 0287f83

Browse files
fix: scope the throttling metric to exclude element size calculation (#1835)
This should prevent off by 1 failures in unit tests on slow vms
1 parent 959bc57 commit 0287f83

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

‎gax/src/main/java/com/google/api/gax/batching/BatcherImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ public ApiFuture<ElementResultT> add(ElementT element) {
213213
// will only be done from a single calling thread.
214214
Preconditions.checkState(closeFuture == null, "Cannot add elements on a closed batcher");
215215

216+
long bytesSize = batchingDescriptor.countBytes(element);
217+
216218
// This is not the optimal way of throttling. It does not send out partial batches, which
217219
// means that the Batcher might not use up all the resources allowed by FlowController.
218220
// The more efficient implementation should look like:
@@ -230,7 +232,7 @@ public ApiFuture<ElementResultT> add(ElementT element) {
230232
// defer it till we decide on if refactoring FlowController is necessary.
231233
Stopwatch stopwatch = Stopwatch.createStarted();
232234
try {
233-
flowController.reserve(1, batchingDescriptor.countBytes(element));
235+
flowController.reserve(1, bytesSize);
234236
} catch (FlowControlException e) {
235237
// This exception will only be thrown if the FlowController is set to ThrowException behavior
236238
throw FlowControlRuntimeException.fromFlowControlException(e);

0 commit comments

Comments
 (0)