• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #272

21 Jun 2024 08:17PM UTC coverage: 77.548% (+0.04%) from 77.506%
#272

push

github

web-flow
Resource based tuner (#2110)

275 of 338 new or added lines in 11 files covered. (81.36%)

12 existing lines in 5 files now uncovered.

19522 of 25174 relevant lines covered (77.55%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.93
/temporal-sdk/src/main/java/io/temporal/worker/tuning/ResourceBasedControllerOptions.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.worker.tuning;
22

23
import com.google.common.base.Preconditions;
24
import io.temporal.common.Experimental;
25

26
/** Options for a {@link ResourceBasedController} */
27
@Experimental
28
public class ResourceBasedControllerOptions {
29

30
  public static ResourceBasedControllerOptions.Builder newBuilder(
31
      double targetMemoryUsage, double targetCPUUsage) {
32
    return new ResourceBasedControllerOptions.Builder()
1✔
33
        .setTargetMemoryUsage(targetMemoryUsage)
1✔
34
        .setTargetCPUUsage(targetCPUUsage);
1✔
35
  }
36

37
  public static final class Builder {
1✔
38
    private double targetMemoryUsage;
39
    private double targetCPUUsage;
40
    private double memoryPGain = 5;
1✔
41
    private double memoryIGain = 0;
1✔
42
    private double memoryDGain = 1;
1✔
43
    private double memoryOutputThreshold = 0.25;
1✔
44
    private double cpuPGain = 5;
1✔
45
    private double cpuIGain = 0;
1✔
46
    private double cpuDGain = 1;
1✔
47
    private double cpuOutputThreshold = 0.05;
1✔
48

49
    public Builder setTargetMemoryUsage(double targetMemoryUsage) {
50
      this.targetMemoryUsage = targetMemoryUsage;
1✔
51
      return this;
1✔
52
    }
53

54
    public Builder setTargetCPUUsage(double targetCPUUsage) {
55
      this.targetCPUUsage = targetCPUUsage;
1✔
56
      return this;
1✔
57
    }
58

59
    public Builder setMemoryPGain(double memoryPGain) {
NEW
60
      this.memoryPGain = memoryPGain;
×
NEW
61
      return this;
×
62
    }
63

64
    public Builder setMemoryIGain(double memoryIGain) {
NEW
65
      this.memoryIGain = memoryIGain;
×
NEW
66
      return this;
×
67
    }
68

69
    public Builder setMemoryDGain(double memoryDGain) {
NEW
70
      this.memoryDGain = memoryDGain;
×
NEW
71
      return this;
×
72
    }
73

74
    public Builder setMemoryOutputThreshold(double memoryOutputThreshold) {
NEW
75
      this.memoryOutputThreshold = memoryOutputThreshold;
×
NEW
76
      return this;
×
77
    }
78

79
    public Builder setCpuPGain(double cpuPGain) {
NEW
80
      this.cpuPGain = cpuPGain;
×
NEW
81
      return this;
×
82
    }
83

84
    public Builder setCpuIGain(double cpuIGain) {
NEW
85
      this.cpuIGain = cpuIGain;
×
NEW
86
      return this;
×
87
    }
88

89
    public Builder setCpuDGain(double cpuDGain) {
NEW
90
      this.cpuDGain = cpuDGain;
×
NEW
91
      return this;
×
92
    }
93

94
    public Builder setCpuOutputThreshold(double cpuOutputThreshold) {
NEW
95
      this.cpuOutputThreshold = cpuOutputThreshold;
×
NEW
96
      return this;
×
97
    }
98

99
    public ResourceBasedControllerOptions build() {
100
      Preconditions.checkState(
1✔
101
          targetMemoryUsage > 0, "targetMemoryUsage must be set and greater than 0");
102
      Preconditions.checkState(targetCPUUsage > 0, "targetCPUUsage must be set and greater than 0");
1✔
103
      return new ResourceBasedControllerOptions(this);
1✔
104
    }
105
  }
106

107
  private final double targetMemoryUsage;
108
  private final double targetCPUUsage;
109

110
  private final double memoryPGain;
111
  private final double memoryIGain;
112
  private final double memoryDGain;
113
  private final double memoryOutputThreshold;
114

115
  private final double cpuPGain;
116
  private final double cpuIGain;
117
  private final double cpuDGain;
118
  private final double cpuOutputThreshold;
119

120
  private ResourceBasedControllerOptions(Builder builder) {
1✔
121
    this.targetMemoryUsage = builder.targetMemoryUsage;
1✔
122
    this.targetCPUUsage = builder.targetCPUUsage;
1✔
123
    this.memoryPGain = builder.memoryPGain;
1✔
124
    this.memoryIGain = builder.memoryIGain;
1✔
125
    this.memoryDGain = builder.memoryDGain;
1✔
126
    this.memoryOutputThreshold = builder.memoryOutputThreshold;
1✔
127
    this.cpuPGain = builder.cpuPGain;
1✔
128
    this.cpuIGain = builder.cpuIGain;
1✔
129
    this.cpuDGain = builder.cpuDGain;
1✔
130
    this.cpuOutputThreshold = builder.cpuOutputThreshold;
1✔
131
  }
1✔
132

133
  public double getTargetMemoryUsage() {
134
    return targetMemoryUsage;
1✔
135
  }
136

137
  public double getTargetCPUUsage() {
138
    return targetCPUUsage;
1✔
139
  }
140

141
  public double getMemoryPGain() {
142
    return memoryPGain;
1✔
143
  }
144

145
  public double getMemoryIGain() {
146
    return memoryIGain;
1✔
147
  }
148

149
  public double getMemoryDGain() {
150
    return memoryDGain;
1✔
151
  }
152

153
  public double getMemoryOutputThreshold() {
154
    return memoryOutputThreshold;
1✔
155
  }
156

157
  public double getCpuPGain() {
158
    return cpuPGain;
1✔
159
  }
160

161
  public double getCpuIGain() {
162
    return cpuIGain;
1✔
163
  }
164

165
  public double getCpuDGain() {
166
    return cpuDGain;
1✔
167
  }
168

169
  public double getCpuOutputThreshold() {
170
    return cpuOutputThreshold;
1✔
171
  }
172
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc