Skip to content

Commit d2bc5ca

Browse files
authored
performance: remove significant overhead of decaymap (#1420)
I have ~5% base CPU load on an idle server due to mutex 100x per second. Signed-off-by: Matthias Dötsch <matze@mdoetsch.de>
1 parent 23ec1b8 commit d2bc5ca

3 files changed

Lines changed: 3 additions & 2 deletions

File tree

decaymap/decaymap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (m *Impl[K, V]) Close() {
146146
func (m *Impl[K, V]) cleanupWorker() {
147147
defer m.wg.Done()
148148
batch := make([]deleteReq[K], 0, 64)
149-
ticker := time.NewTicker(10 * time.Millisecond)
149+
ticker := time.NewTicker(500 * time.Millisecond)
150150
defer ticker.Stop()
151151

152152
flush := func() {

decaymap/decaymap_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestImpl(t *testing.T) {
3232

3333
// Deletion of expired entries after Get is deferred to a background worker.
3434
// Assert it eventually disappears from the map.
35-
deadline := time.Now().Add(200 * time.Millisecond)
35+
deadline := time.Now().Add(700 * time.Millisecond)
3636
for time.Now().Before(deadline) {
3737
if dm.Len() == 0 {
3838
break

docs/docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Add iplist2rule tool that lets admins turn an IP address blocklist into an Anubis ruleset.
1515
- Add Polish locale ([#1292](https://github.com/TecharoHQ/anubis/pull/1309))
1616
- Fix honeypot and imprint links missing `BASE_PREFIX` when deployed behind a path prefix ([#1402](https://github.com/TecharoHQ/anubis/issues/1402))
17+
- Improve idle performance in memory storage
1718

1819
<!-- This changes the project to: -->
1920

0 commit comments

Comments
 (0)