mirror of https://github.com/grpc/grpc-java.git
services: allow cpu utilization greater than 1 (#10107)
This commit is contained in:
parent
fe53346697
commit
b249a5340e
|
|
@ -135,7 +135,7 @@ public final class CallMetricRecorder {
|
|||
* @since 1.47.0
|
||||
*/
|
||||
public CallMetricRecorder recordCpuUtilizationMetric(double value) {
|
||||
if (disabled || !MetricRecorderHelper.isUtilizationValid(value)) {
|
||||
if (disabled || !MetricRecorderHelper.isCpuUtilizationValid(value)) {
|
||||
return this;
|
||||
}
|
||||
cpuUtilizationMetric = value;
|
||||
|
|
|
|||
|
|
@ -64,11 +64,11 @@ public final class MetricRecorder {
|
|||
}
|
||||
|
||||
/**
|
||||
* Update the CPU utilization metrics data in the range [0, 1]. Values outside the valid range are
|
||||
* ignored.
|
||||
* Update the CPU utilization metrics data in the range [0, inf). Values outside the valid range
|
||||
* are ignored.
|
||||
*/
|
||||
public void setCpuUtilizationMetric(double value) {
|
||||
if (!MetricRecorderHelper.isUtilizationValid(value)) {
|
||||
if (!MetricRecorderHelper.isCpuUtilizationValid(value)) {
|
||||
return;
|
||||
}
|
||||
cpuUtilization = value;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,15 @@ final class MetricRecorderHelper {
|
|||
return utilization >= 0.0 && utilization <= 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the cpu utilization value is in the range [0, inf) and false otherwise.
|
||||
* Occasionally users have over 100% cpu utilization and get a runaway effect where the backend
|
||||
* with highest qps gets more and more qps sent to it. So we allow cpu utilization > 1.0.
|
||||
*/
|
||||
static boolean isCpuUtilizationValid(double utilization) {
|
||||
return utilization >= 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the qps value is in the range [0, inf) and false otherwise.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class CallMetricRecorderTest {
|
|||
recorder.recordUtilizationMetric("util1", 1.001);
|
||||
|
||||
MetricReport dump = recorder.finalizeAndDump2();
|
||||
Truth.assertThat(dump.getCpuUtilization()).isEqualTo(0);
|
||||
Truth.assertThat(dump.getCpuUtilization()).isEqualTo(1.001);
|
||||
Truth.assertThat(dump.getMemoryUtilization()).isEqualTo(0);
|
||||
Truth.assertThat(dump.getQps()).isEqualTo(0);
|
||||
Truth.assertThat(dump.getUtilizationMetrics()).isEmpty();
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ public class OrcaServiceImplTest {
|
|||
public void testApis() throws Exception {
|
||||
ImmutableMap<String, Double> firstUtilization = ImmutableMap.of("util", 0.1);
|
||||
OrcaLoadReport goldenReport = OrcaLoadReport.newBuilder()
|
||||
.setCpuUtilization(random.nextDouble())
|
||||
.setCpuUtilization(random.nextDouble() * 10)
|
||||
.setMemUtilization(random.nextDouble())
|
||||
.putAllUtilization(firstUtilization)
|
||||
.putUtilization("queue", 1.0)
|
||||
|
|
@ -276,7 +276,6 @@ public class OrcaServiceImplTest {
|
|||
assertThat(reports.next()).isEqualTo(goldenReport);
|
||||
|
||||
defaultTestService.setCpuUtilizationMetric(-0.001);
|
||||
defaultTestService.setCpuUtilizationMetric(1.001);
|
||||
defaultTestService.setMemoryUtilizationMetric(-0.001);
|
||||
defaultTestService.setMemoryUtilizationMetric(1.001);
|
||||
defaultTestService.setQpsMetric(-0.001);
|
||||
|
|
|
|||
Loading…
Reference in New Issue