@@ -18,6 +18,9 @@ type Workspace struct {
18
18
NrThrottled uint64
19
19
Usage CPUTime
20
20
QoS int
21
+
22
+ BaseLimit Bandwidth
23
+ BurstLimit Bandwidth
21
24
}
22
25
23
26
type WorkspaceHistory struct {
@@ -113,7 +116,7 @@ func (d *Distributor) Tick(dt time.Duration) (DistributorDebug, error) {
113
116
return DistributorDebug {}, err
114
117
}
115
118
116
- f := make (map [string ]struct {} , len (ws ))
119
+ wsidx := make (map [string ]Workspace , len (ws ))
117
120
for _ , w := range ws {
118
121
h , ok := d .History [w .ID ]
119
122
if ! ok {
@@ -123,10 +126,10 @@ func (d *Distributor) Tick(dt time.Duration) (DistributorDebug, error) {
123
126
d .History [w .ID ] = h
124
127
}
125
128
h .Update (w )
126
- f [w .ID ] = struct {}{}
129
+ wsidx [w .ID ] = w
127
130
}
128
131
for oldWS := range d .History {
129
- if _ , found := f [oldWS ]; ! found {
132
+ if _ , found := wsidx [oldWS ]; ! found {
130
133
delete (d .History , oldWS )
131
134
}
132
135
}
@@ -172,15 +175,23 @@ func (d *Distributor) Tick(dt time.Duration) (DistributorDebug, error) {
172
175
var burstBandwidth Bandwidth
173
176
for _ , id := range wsOrder {
174
177
ws := d .History [id ]
175
- limit := d .Limiter .Limit (ws .Usage ())
178
+ limiter := d .Limiter
179
+ if w := wsidx [id ]; w .BaseLimit > 0 {
180
+ limiter = FixedLimiter (w .BaseLimit )
181
+ }
182
+ limit := limiter .Limit (ws .Usage ())
176
183
177
184
// if we didn't get the max bandwidth, but were throttled last time
178
185
// and there's still some bandwidth left to give, let's act as if had
179
186
// never spent any CPU time and assume the workspace will spend their
180
187
// entire bandwidth at once.
181
188
var burst bool
182
189
if totalBandwidth < d .TotalBandwidth && ws .Throttled () {
183
- limit = d .BurstLimiter .Limit (ws .Usage ())
190
+ limiter := d .BurstLimiter
191
+ if w := wsidx [id ]; w .BaseLimit > 0 {
192
+ limiter = FixedLimiter (w .BurstLimit )
193
+ }
194
+ limit = limiter .Limit (ws .Usage ())
184
195
185
196
// We assume the workspace is going to use as much as their limit allows.
186
197
// This might not be true, because their process which consumed so much CPU
0 commit comments