Skip to content

Commit

Permalink
add concurrency control in "ControlWorkload" (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
DuodenumL authored Feb 9, 2022
1 parent 951fd88 commit 0ad2595
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions cluster/calcium/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package calcium
import (
"bytes"
"context"
"sync"

"github.com/projecteru2/core/cluster"
"github.com/projecteru2/core/log"
Expand All @@ -20,15 +19,12 @@ func (c *Calcium) ControlWorkload(ctx context.Context, ids []string, t string, f

utils.SentryGo(func() {
defer close(ch)
wg := sync.WaitGroup{}
pool := utils.NewGoroutinePool(int(c.config.MaxConcurrency))
for _, id := range ids {
wg.Add(1)
utils.SentryGo(func(id string) func() {
pool.Go(ctx, func(id string) func() {
return func() {
defer wg.Done()
var message []*bytes.Buffer
err := c.withWorkloadLocked(ctx, id, func(ctx context.Context, workload *types.Workload) error {

var err error
switch t {
case cluster.WorkloadStop:
Expand Down Expand Up @@ -61,7 +57,7 @@ func (c *Calcium) ControlWorkload(ctx context.Context, ids []string, t string, f
}
}(id))
}
wg.Wait()
pool.Wait(ctx)
})

return ch, nil
Expand Down

0 comments on commit 0ad2595

Please sign in to comment.