Skip to content

Commit

Permalink
feat: Add 'ScheduledTaskQueueSize' options
Browse files Browse the repository at this point in the history
  • Loading branch information
rainzm committed Jun 9, 2020
1 parent 8a69558 commit 3ea4bee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/compute/models/scheduled_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"yunion.io/x/onecloud/pkg/apis"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
cop "yunion.io/x/onecloud/pkg/compute/options"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/auth"
Expand Down Expand Up @@ -549,7 +550,12 @@ func (stm *SScheduledTaskManager) timeScope(median time.Time, interval time.Dura
}
}

var timerQueue = make(chan struct{}, cop.Options.ScheduledTaskQueueSize)

func (stm *SScheduledTaskManager) Timer(ctx context.Context, userCred mcclient.TokenCredential, isStart bool) {
if len(timerQueue) == 0 {
timerQueue = make(chan struct{}, cop.Options.ScheduledTaskQueueSize)
}
// 60 is for fault tolerance
interval := 60 + 30
timeScope := stm.timeScope(time.Now(), time.Duration(interval)*time.Second)
Expand All @@ -560,7 +566,6 @@ func (stm *SScheduledTaskManager) Timer(ctx context.Context, userCred mcclient.T
log.Errorf("db.FetchModelObjects error: %s", err.Error())
return
}
timerQueue := make(chan struct{}, 20)
log.Debugf("timeScope: start: %s, end: %s", timeScope.Start, timeScope.End)
for i := range sts {
st := sts[i]
Expand Down Expand Up @@ -592,6 +597,7 @@ func (stm *SScheduledTaskManager) Timer(ctx context.Context, userCred mcclient.T
}
}(ctx)
}
// wait all finish
}

func init() {
Expand Down
2 changes: 2 additions & 0 deletions pkg/compute/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ type ComputeOptions struct {

GuestTemplateCheckInterval int `help:"interval between two consecutive inspections of Guest Template in hour unit" default:"12"`

ScheduledTaskQueueSize int `help:"the maximum number of scheduled tasks that are being executed simultaneously" default:"100"`

SCapabilityOptions
SASControllerOptions
common_options.CommonOptions
Expand Down

0 comments on commit 3ea4bee

Please sign in to comment.