Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomly offset retention and expiration time. #270

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 11.6.1
Garbett1 marked this conversation as resolved.
Show resolved Hide resolved
--------------
* Randomly offset retentionTime and expiryTime for each job so the
goroutines don't all wake up at the same time. This is a bit of a hack,
a proper fix will be raised soon.

Version 11.6.0
--------------
* Add rate-limiter to Redis client so we don't fail slowly
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11.6.0
11.6.1
7 changes: 4 additions & 3 deletions mettle/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package api
import (
"context"
"fmt"
"math/rand"
"net"
"strings"
"sync"
Expand Down Expand Up @@ -560,7 +561,7 @@ func (s *server) process(msg *pubsub.Message) {

// deleteJob waits for a period then removes the given job from memory.
func (s *server) deleteJob(hash string, j *job) {
time.Sleep(retentionTime)
time.Sleep(retentionTime + time.Duration(rand.Int63n(int64(retentionTime))))
s.mutex.Lock()
defer s.mutex.Unlock()
// Check the action hasn't been replaced since deleteJob was called
Expand All @@ -573,11 +574,11 @@ func (s *server) deleteJob(hash string, j *job) {

// expireJob expires an action that hasn't progressed.
func (s *server) expireJob(hash string) {
time.Sleep(expiryTime)
time.Sleep(expiryTime + time.Duration(rand.Int63n(int64(expiryTime))))
if s.maybeExpireJob(hash, false) {
return
}
time.Sleep(expiryTime)
time.Sleep(expiryTime + time.Duration(rand.Int63n(int64(expiryTime))))
s.maybeExpireJob(hash, true)
}

Expand Down
Loading