diff --git a/components/ws-daemon/pkg/cpulimit/cpulimit.go b/components/ws-daemon/pkg/cpulimit/cpulimit.go index 23b67d505b7284..8a39d73f675e78 100644 --- a/components/ws-daemon/pkg/cpulimit/cpulimit.go +++ b/components/ws-daemon/pkg/cpulimit/cpulimit.go @@ -18,9 +18,6 @@ type Workspace struct { NrThrottled uint64 Usage CPUTime QoS int - - BaseLimit Bandwidth - BurstLimit Bandwidth } type WorkspaceHistory struct { @@ -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 { @@ -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) } } @@ -175,11 +172,7 @@ 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 @@ -187,11 +180,7 @@ func (d *Distributor) Tick(dt time.Duration) (DistributorDebug, error) { // 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 diff --git a/components/ws-daemon/pkg/cpulimit/dispatch.go b/components/ws-daemon/pkg/cpulimit/dispatch.go index 200b9648bde8b2..7cbf51ec869af8 100644 --- a/components/ws-daemon/pkg/cpulimit/dispatch.go +++ b/components/ws-daemon/pkg/cpulimit/dispatch.go @@ -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 } @@ -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 @@ -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