@@ -396,6 +396,9 @@ func (s *WorkspaceService) DisposeWorkspace(ctx context.Context, req *api.Dispos
396
396
return resp , nil
397
397
}
398
398
399
+ // channel to limit the number of concurrent backups and uploads.
400
+ var backupWorkspaceLimiter = make (chan bool , 3 )
401
+
399
402
func (s * WorkspaceService ) uploadWorkspaceContent (ctx context.Context , sess * session.Workspace , backupName , mfName string ) (err error ) {
400
403
//nolint:ineffassign
401
404
span , ctx := opentracing .StartSpanFromContext (ctx , "uploadWorkspaceContent" )
@@ -407,6 +410,15 @@ func (s *WorkspaceService) uploadWorkspaceContent(ctx context.Context, sess *ses
407
410
span .SetTag ("pvc" , sess .PersistentVolumeClaim )
408
411
defer tracing .FinishSpan (span , & err )
409
412
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
+
410
422
var (
411
423
loc = sess .Location
412
424
opts []storage.UploadOption
@@ -469,6 +481,7 @@ func (s *WorkspaceService) uploadWorkspaceContent(ctx context.Context, sess *ses
469
481
)
470
482
}
471
483
484
+ <- here
472
485
err = BuildTarbal (ctx , loc , tmpf .Name (), sess .FullWorkspaceBackup , opts ... )
473
486
if err != nil {
474
487
return
0 commit comments