Skip to content

Commit 547e2a8

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

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 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,15 @@ func (s *WorkspaceService) uploadWorkspaceContent(ctx context.Context, sess *ses
407410
span.SetTag("pvc", sess.PersistentVolumeClaim)
408411
defer tracing.FinishSpan(span, &err)
409412

413+
// TODO: remove once we migrate to PVCs
414+
// Avoid too many simultaneous backups in order to avoid excessive memory utilization.
415+
waitStart := time.Now()
416+
backupWorkspaceLimiter <- true
417+
log.WithField("workspace", sess.WorkspaceID).Infof("waiting time for concurrent backups to finish was %v", time.Since(waitStart).String())
418+
defer func() {
419+
<-backupWorkspaceLimiter
420+
}()
421+
410422
var (
411423
loc = sess.Location
412424
opts []storage.UploadOption

0 commit comments

Comments
 (0)