Skip to content

Commit 3d5eaf3

Browse files
Add ThrottlingSignaler class to the Java SDK (#36119)
* Add ThrottlingSignaler class to the Java SDK * Update sdks/java/io/components/src/main/java/org/apache/beam/sdk/io/components/throttling/ThrottlingSignaler.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * set default namespace --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 6fe2c28 commit 3d5eaf3

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.beam.sdk.io.components.throttling;
19+
20+
import org.apache.beam.sdk.metrics.Counter;
21+
import org.apache.beam.sdk.metrics.Metrics;
22+
/**
23+
* The ThrottlingSignaler is a utility class for IOs to signal to the runner
24+
* that a process is being throttled, preventing autoscaling. This is primarily
25+
* used when making calls to a remote service where quotas and rate limiting
26+
* are reasonable considerations.
27+
*/
28+
public class ThrottlingSignaler {
29+
private final Counter throttleCounter;
30+
31+
public ThrottlingSignaler(String namespace) {
32+
this.throttleCounter = Metrics.counter(namespace, Metrics.THROTTLE_TIME_COUNTER_NAME);
33+
}
34+
35+
public ThrottlingSignaler() {
36+
this(Metrics.THROTTLE_TIME_NAMESPACE);
37+
}
38+
39+
/**
40+
* Signal that a transform has been throttled for an amount of time
41+
* represented in milliseconds.
42+
*/
43+
public void signalThrottling(long milliseconds) {
44+
throttleCounter.inc(milliseconds);
45+
}
46+
}

0 commit comments

Comments
 (0)