Skip to content

Commit b64bba5

Browse files
authored
fix(api): stop ticker + time.sleep to reduce cpu load (#5304)
1 parent dae0ac7 commit b64bba5

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

engine/api/cache/redis.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,11 @@ func (s *RedisStore) DequeueWithContext(c context.Context, queueName string, wai
233233
}
234234

235235
var elem string
236-
ticker := time.NewTicker(waitDuration).C
236+
ticker := time.NewTicker(waitDuration)
237+
defer ticker.Stop()
237238
for elem == "" {
238239
select {
239-
case <-ticker:
240+
case <-ticker.C:
240241
if c.Err() != nil {
241242
return c.Err()
242243
}

engine/cdn/cdn_log.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,11 @@ func (s *Service) getHatchery(ctx context.Context, hatcheryID int64, hatcheryNam
277277
}
278278

279279
func (s *Service) waitingJobs(ctx context.Context) {
280-
tick := time.NewTicker(250 * time.Millisecond)
281-
defer tick.Stop()
282280
for {
283281
select {
284282
case <-ctx.Done():
285283
return
286-
case _ = <-tick.C:
284+
default:
287285
// List all queues
288286
keyListQueue := cache.Key(keyJobLogQueue, "*")
289287
listKeys, err := s.Cache.Keys(keyListQueue)
@@ -312,6 +310,7 @@ func (s *Service) waitingJobs(ctx context.Context) {
312310
}
313311
})
314312
}
313+
time.Sleep(250 * time.Millisecond)
315314
}
316315
}
317316
}
@@ -332,6 +331,7 @@ func (s *Service) dequeueJobMessages(ctx context.Context, jobLogsQueueKey string
332331
}()
333332

334333
tick := time.NewTicker(5 * time.Second)
334+
defer tick.Stop()
335335
for {
336336
select {
337337
case <-ctx.Done():

0 commit comments

Comments
 (0)