@@ -135,41 +135,44 @@ class SchedulingDecisionMaker(
135
135
staleActivationNum,
136
136
0.0 ,
137
137
Running )
138
-
139
- case (Running , Some (duration)) if staleActivationNum > 0 =>
140
- // we can safely get the value as we already checked the existence
141
- val containerThroughput = staleThreshold / duration
142
- val num = ceiling(availableMsg.toDouble / containerThroughput)
143
- // if it tries to create more containers than existing messages, we just create shortage
144
- val actualNum = (if (num > availableMsg) availableMsg else num) - inProgress
145
- addServersIfPossible(
146
- existing,
147
- inProgress,
148
- containerThroughput,
149
- availableMsg,
150
- capacity,
151
- actualNum,
152
- staleActivationNum,
153
- duration,
154
- Running )
155
-
156
138
// need more containers and a message is already processed
157
139
case (Running , Some (duration)) =>
158
140
// we can safely get the value as we already checked the existence
159
141
val containerThroughput = staleThreshold / duration
160
142
val expectedTps = containerThroughput * (existing + inProgress)
143
+ val availableNonStaleActivations = availableMsg - staleActivationNum
144
+
145
+ var staleContainerProvision = 0
146
+ if (staleActivationNum > 0 ) {
147
+ val num = ceiling(staleActivationNum.toDouble / containerThroughput)
148
+ // if it tries to create more containers than existing messages, we just create shortage
149
+ staleContainerProvision = (if (num > staleActivationNum) staleActivationNum else num) - inProgress
150
+ }
161
151
162
- if (availableMsg >= expectedTps && existing + inProgress < availableMsg ) {
163
- val num = ceiling((availableMsg / containerThroughput) - existing - inProgress)
152
+ if (availableNonStaleActivations >= expectedTps && existing + inProgress < availableNonStaleActivations ) {
153
+ val num = ceiling((availableNonStaleActivations / containerThroughput) - existing - inProgress)
164
154
// if it tries to create more containers than existing messages, we just create shortage
165
- val actualNum = if (num + totalContainers > availableMsg) availableMsg - totalContainers else num
155
+ val actualNum =
156
+ if (num + totalContainers > availableNonStaleActivations) availableNonStaleActivations - totalContainers
157
+ else num
158
+ addServersIfPossible(
159
+ existing,
160
+ inProgress,
161
+ containerThroughput,
162
+ availableMsg,
163
+ capacity,
164
+ actualNum + staleContainerProvision,
165
+ staleActivationNum,
166
+ duration,
167
+ Running )
168
+ } else if (staleContainerProvision > 0 ) {
166
169
addServersIfPossible(
167
170
existing,
168
171
inProgress,
169
172
containerThroughput,
170
173
availableMsg,
171
174
capacity,
172
- actualNum ,
175
+ staleContainerProvision ,
173
176
staleActivationNum,
174
177
duration,
175
178
Running )
@@ -184,9 +187,9 @@ class SchedulingDecisionMaker(
184
187
case (Removing , Some (duration)) if staleActivationNum > 0 =>
185
188
// we can safely get the value as we already checked the existence
186
189
val containerThroughput = staleThreshold / duration
187
- val num = ceiling(availableMsg .toDouble / containerThroughput)
190
+ val num = ceiling(staleActivationNum .toDouble / containerThroughput)
188
191
// if it tries to create more containers than existing messages, we just create shortage
189
- val actualNum = (if (num > availableMsg) availableMsg else num) - inProgress
192
+ val actualNum = (if (num > staleActivationNum) staleActivationNum else num) - inProgress
190
193
addServersIfPossible(
191
194
existing,
192
195
inProgress,
0 commit comments