Skip to content

Keep the lobsters and shipit caches in memory - #564

Merged
k0kubun merged 1 commit into
ruby:mainfrom
thomasklemm:thomasklemm/memory-cache-store
Nov 5, 2026
Merged

k0kubun merged 1 commit into
ruby:mainfrom
thomasklemm:thomasklemm/memory-cache-store

Conversation

@thomasklemm

Copy link
Copy Markdown
Contributor

This changes the cache store of lobsters and shipit from a file store in tmp/cache to :memory_store, so each benchmark process starts with an empty cache of its own.

The shared file store causes two problems. When several lobsters processes run from one checkout, some requests fail with a 500: with three processes started together, two stopped at /replies/unread with Errno::ENOENT from File.rename, because one process deleted a cache entry and removed its empty directory while another was renaming a new entry into it. And a process starts with whatever an earlier run left in tmp/cache, so its first iteration does different work depending on that. shipit uses the Rails default file store in tmp/cache for its view fragments, so it has the second problem too.

With :memory_store, the same three concurrent lobsters runs all succeed. In the iterations after warmup, both stores record 118 cache reads, 18 writes and 8 deletes per lobsters iteration, and 249 reads per shipit iteration. All 114 lobsters responses have the same byte length and story count as with the file store.

Lobsters also gets faster. After warmup, the time spent in cache reads, writes and deletes, summed from Active Support's cache notifications, falls from 21.7 to 1.7 ms per iteration with ZJIT on Ruby a8b095a07e, and from 24.7 to 2.5 ms with the interpreter. That is about 2% of a lobsters iteration (2.3% with ZJIT, 1.8% with the interpreter), so lobsters results from before and after this change are not directly comparable.

Both apps cached through a file store in tmp/cache, so processes running
from one checkout shared it, and concurrent lobsters runs could fail with a
500 when one process removed a cache directory another was renaming into.
A memory store keeps the same cache reads, writes and deletes per iteration
without touching the disk.
@thomasklemm
thomasklemm force-pushed the thomasklemm/memory-cache-store branch from c4d362b to a920bf4 Compare November 4, 2026 08:28

@k0kubun k0kubun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, thanks!

@k0kubun
k0kubun merged commit 00f0f8b into ruby:main Nov 5, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants