Skip to content

Commit a05dca6

Browse files
committed
[ws-daemon] Limit the number of concurrent workspace backups
1 parent 68e77c3 commit a05dca6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

components/ws-daemon/pkg/content/service.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ func (s *WorkspaceService) DisposeWorkspace(ctx context.Context, req *api.Dispos
396396
return resp, nil
397397
}
398398

399+
// channel to limit the number of concurrent backups and uploads.
400+
var backupWorkspaceLimiter = make(chan bool, 3)
401+
399402
func (s *WorkspaceService) uploadWorkspaceContent(ctx context.Context, sess *session.Workspace, backupName, mfName string) (err error) {
400403
//nolint:ineffassign
401404
span, ctx := opentracing.StartSpanFromContext(ctx, "uploadWorkspaceContent")
@@ -407,6 +410,12 @@ func (s *WorkspaceService) uploadWorkspaceContent(ctx context.Context, sess *ses
407410
span.SetTag("pvc", sess.PersistentVolumeClaim)
408411
defer tracing.FinishSpan(span, &err)
409412

413+
// Avoid too many simultaneous backups in order to avoid excessive memory utilization.
414+
backupWorkspaceLimiter <- true
415+
defer func() {
416+
<-backupWorkspaceLimiter
417+
}()
418+
410419
var (
411420
loc = sess.Location
412421
opts []storage.UploadOption
@@ -469,6 +478,7 @@ func (s *WorkspaceService) uploadWorkspaceContent(ctx context.Context, sess *ses
469478
)
470479
}
471480

481+
<-here
472482
err = BuildTarbal(ctx, loc, tmpf.Name(), sess.FullWorkspaceBackup, opts...)
473483
if err != nil {
474484
return

0 commit comments

Comments
 (0)