Skip to content

Commit

Permalink
fix(api): stop ticker + time.sleep to reduce cpu load (#5304)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Jul 7, 2020
1 parent dae0ac7 commit b64bba5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions engine/api/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,11 @@ func (s *RedisStore) DequeueWithContext(c context.Context, queueName string, wai
}

var elem string
ticker := time.NewTicker(waitDuration).C
ticker := time.NewTicker(waitDuration)
defer ticker.Stop()
for elem == "" {
select {
case <-ticker:
case <-ticker.C:
if c.Err() != nil {
return c.Err()
}
Expand Down
6 changes: 3 additions & 3 deletions engine/cdn/cdn_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,11 @@ func (s *Service) getHatchery(ctx context.Context, hatcheryID int64, hatcheryNam
}

func (s *Service) waitingJobs(ctx context.Context) {
tick := time.NewTicker(250 * time.Millisecond)
defer tick.Stop()
for {
select {
case <-ctx.Done():
return
case _ = <-tick.C:
default:
// List all queues
keyListQueue := cache.Key(keyJobLogQueue, "*")
listKeys, err := s.Cache.Keys(keyListQueue)
Expand Down Expand Up @@ -312,6 +310,7 @@ func (s *Service) waitingJobs(ctx context.Context) {
}
})
}
time.Sleep(250 * time.Millisecond)
}
}
}
Expand All @@ -332,6 +331,7 @@ func (s *Service) dequeueJobMessages(ctx context.Context, jobLogsQueueKey string
}()

tick := time.NewTicker(5 * time.Second)
defer tick.Stop()
for {
select {
case <-ctx.Done():
Expand Down

0 comments on commit b64bba5

Please sign in to comment.