Skip to content

Commit 28db115

Browse files
aledbfroboquat
authored andcommitted
Revert "[ws-daemon] Fix CPU limit annotation"
This reverts commit 3819d92.
1 parent 35e7460 commit 28db115

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

components/ws-daemon/pkg/cpulimit/cpulimit.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ type Workspace struct {
1818
NrThrottled uint64
1919
Usage CPUTime
2020
QoS int
21-
22-
BaseLimit Bandwidth
23-
BurstLimit Bandwidth
2421
}
2522

2623
type WorkspaceHistory struct {
@@ -116,7 +113,7 @@ func (d *Distributor) Tick(dt time.Duration) (DistributorDebug, error) {
116113
return DistributorDebug{}, err
117114
}
118115

119-
wsidx := make(map[string]Workspace, len(ws))
116+
f := make(map[string]struct{}, len(ws))
120117
for _, w := range ws {
121118
h, ok := d.History[w.ID]
122119
if !ok {
@@ -126,10 +123,10 @@ func (d *Distributor) Tick(dt time.Duration) (DistributorDebug, error) {
126123
d.History[w.ID] = h
127124
}
128125
h.Update(w)
129-
wsidx[w.ID] = w
126+
f[w.ID] = struct{}{}
130127
}
131128
for oldWS := range d.History {
132-
if _, found := wsidx[oldWS]; !found {
129+
if _, found := f[oldWS]; !found {
133130
delete(d.History, oldWS)
134131
}
135132
}
@@ -175,23 +172,15 @@ func (d *Distributor) Tick(dt time.Duration) (DistributorDebug, error) {
175172
var burstBandwidth Bandwidth
176173
for _, id := range wsOrder {
177174
ws := d.History[id]
178-
limiter := d.Limiter
179-
if w := wsidx[id]; w.BaseLimit > 0 {
180-
limiter = FixedLimiter(w.BaseLimit)
181-
}
182-
limit := limiter.Limit(ws.Usage())
175+
limit := d.Limiter.Limit(ws.Usage())
183176

184177
// if we didn't get the max bandwidth, but were throttled last time
185178
// and there's still some bandwidth left to give, let's act as if had
186179
// never spent any CPU time and assume the workspace will spend their
187180
// entire bandwidth at once.
188181
var burst bool
189182
if totalBandwidth < d.TotalBandwidth && ws.Throttled() {
190-
limiter := d.BurstLimiter
191-
if w := wsidx[id]; w.BaseLimit > 0 {
192-
limiter = FixedLimiter(w.BurstLimit)
193-
}
194-
limit = limiter.Limit(ws.Usage())
183+
limit = d.BurstLimiter.Limit(ws.Usage())
195184

196185
// We assume the workspace is going to use as much as their limit allows.
197186
// This might not be true, because their process which consumed so much CPU

components/ws-daemon/pkg/cpulimit/dispatch.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,9 @@ type DispatchListener struct {
9898
}
9999

100100
type workspace struct {
101-
CFS CgroupCFSController
102-
OWI logrus.Fields
103-
BaseLimit Bandwidth
104-
BurstLimit Bandwidth
105-
HardLimit ResourceLimiter
101+
CFS CFSController
102+
OWI logrus.Fields
103+
HardLimit ResourceLimiter
106104

107105
lastThrottled uint64
108106
}
@@ -137,8 +135,6 @@ func (d *DispatchListener) source(context.Context) ([]Workspace, error) {
137135
ID: id,
138136
NrThrottled: throttled,
139137
Usage: usage,
140-
BaseLimit: w.BaseLimit,
141-
BurstLimit: w.BurstLimit,
142138
})
143139
}
144140
return res, nil
@@ -219,8 +215,7 @@ func (d *DispatchListener) WorkspaceUpdated(ctx context.Context, ws *dispatch.Wo
219215
if err != nil {
220216
return xerrors.Errorf("cannot enforce fixed CPU limit: %w", err)
221217
}
222-
wsinfo.BaseLimit = BandwidthFromQuantity(limit)
223-
wsinfo.BurstLimit = BandwidthFromQuantity(limit)
218+
wsinfo.HardLimit = FixedLimiter(BandwidthFromQuantity(limit))
224219
}
225220

226221
return nil

0 commit comments

Comments
 (0)