Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ws-daemon] Fix CPU limit annotation #9479

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions components/ws-daemon/pkg/cpulimit/cpulimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type Workspace struct {
NrThrottled uint64
Usage CPUTime
QoS int

BaseLimit Bandwidth
BurstLimit Bandwidth
}

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be w.BurstLimiter > 0?

limiter = FixedLimiter(w.BurstLimit)
}
limit = limiter.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
16 changes: 12 additions & 4 deletions components/ws-daemon/pkg/cpulimit/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ type DispatchListener struct {
}

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

lastThrottled uint64
}
Expand Down Expand Up @@ -135,6 +137,8 @@ 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 @@ -215,7 +219,11 @@ func (d *DispatchListener) WorkspaceUpdated(ctx context.Context, ws *dispatch.Wo
if err != nil {
return xerrors.Errorf("cannot enforce fixed CPU limit: %w", err)
}
wsinfo.HardLimit = FixedLimiter(BandwidthFromQuantity(limit))
wsinfo.BaseLimit = BandwidthFromQuantity(limit)
wsinfo.BurstLimit = BandwidthFromQuantity(limit)
} else {
wsinfo.BaseLimit = Bandwidth(0)
wsinfo.BurstLimit = Bandwidth(0)
}

return nil
Expand Down