Skip to content

Commit

Permalink
Revert "[ws-daemon] Fix CPU limit annotation"
Browse files Browse the repository at this point in the history
This reverts commit 3819d92.
  • Loading branch information
aledbf authored and roboquat committed Apr 18, 2022
1 parent 35e7460 commit 28db115
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
21 changes: 5 additions & 16 deletions components/ws-daemon/pkg/cpulimit/cpulimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ type Workspace struct {
NrThrottled uint64
Usage CPUTime
QoS int

BaseLimit Bandwidth
BurstLimit Bandwidth
}

type WorkspaceHistory struct {
Expand Down Expand Up @@ -116,7 +113,7 @@ func (d *Distributor) Tick(dt time.Duration) (DistributorDebug, error) {
return DistributorDebug{}, err
}

wsidx := make(map[string]Workspace, len(ws))
f := make(map[string]struct{}, len(ws))
for _, w := range ws {
h, ok := d.History[w.ID]
if !ok {
Expand All @@ -126,10 +123,10 @@ func (d *Distributor) Tick(dt time.Duration) (DistributorDebug, error) {
d.History[w.ID] = h
}
h.Update(w)
wsidx[w.ID] = w
f[w.ID] = struct{}{}
}
for oldWS := range d.History {
if _, found := wsidx[oldWS]; !found {
if _, found := f[oldWS]; !found {
delete(d.History, oldWS)
}
}
Expand Down Expand Up @@ -175,23 +172,15 @@ func (d *Distributor) Tick(dt time.Duration) (DistributorDebug, error) {
var burstBandwidth Bandwidth
for _, id := range wsOrder {
ws := d.History[id]
limiter := d.Limiter
if w := wsidx[id]; w.BaseLimit > 0 {
limiter = FixedLimiter(w.BaseLimit)
}
limit := limiter.Limit(ws.Usage())
limit := d.Limiter.Limit(ws.Usage())

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

// We assume the workspace is going to use as much as their limit allows.
// This might not be true, because their process which consumed so much CPU
Expand Down
13 changes: 4 additions & 9 deletions components/ws-daemon/pkg/cpulimit/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ type DispatchListener struct {
}

type workspace struct {
CFS CgroupCFSController
OWI logrus.Fields
BaseLimit Bandwidth
BurstLimit Bandwidth
HardLimit ResourceLimiter
CFS CFSController
OWI logrus.Fields
HardLimit ResourceLimiter

lastThrottled uint64
}
Expand Down Expand Up @@ -137,8 +135,6 @@ func (d *DispatchListener) source(context.Context) ([]Workspace, error) {
ID: id,
NrThrottled: throttled,
Usage: usage,
BaseLimit: w.BaseLimit,
BurstLimit: w.BurstLimit,
})
}
return res, nil
Expand Down Expand Up @@ -219,8 +215,7 @@ func (d *DispatchListener) WorkspaceUpdated(ctx context.Context, ws *dispatch.Wo
if err != nil {
return xerrors.Errorf("cannot enforce fixed CPU limit: %w", err)
}
wsinfo.BaseLimit = BandwidthFromQuantity(limit)
wsinfo.BurstLimit = BandwidthFromQuantity(limit)
wsinfo.HardLimit = FixedLimiter(BandwidthFromQuantity(limit))
}

return nil
Expand Down

0 comments on commit 28db115

Please sign in to comment.