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

Commit

Permalink
fix: scope the throttling metric to exclude element size calculation (#…
Browse files Browse the repository at this point in the history
…1835)

This should prevent off by 1 failures in unit tests on slow vms
  • Loading branch information
igorbernstein2 committed Oct 19, 2022
1 parent 959bc57 commit 0287f83
Showing 1 changed file with 3 additions and 1 deletion.
Expand Up @@ -213,6 +213,8 @@ public ApiFuture<ElementResultT> add(ElementT element) {
// will only be done from a single calling thread.
Preconditions.checkState(closeFuture == null, "Cannot add elements on a closed batcher");

long bytesSize = batchingDescriptor.countBytes(element);

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

0 comments on commit 0287f83

Please sign in to comment.