Parallelize initial page cache population#134
Conversation
Previously, all routes were set one-by-one. Instead, up to `availableParallelism` pages are now concurrently read from the filesystem and populated into the cache handler.
…ential parallel work Added `#configureTask` alongside the existing merged handler state and wired a new `#ensureConfigured()` helper that guards the original configuration routine. The `get`, `set`, and `revalidateTag` entry points now await `#ensureConfigured()`, so they can be executed in parallel after the one-time initialization completes without racing the user-provided `onCreation` hook
|
Additional remarks: Maybe it makes sense to add a min parallelism of say 4 or 8 instead of fully relying on |
|
Hey @AyronK, any updates? :) (+ opinion on minimum parallelism count) |
|
@FabianKoder cool idea, I will test it today and get back to you. |
I think it's a solid idea @FabianKoder, I would go with 4 as default but you could introduce a parameter in instrumentation config ( |
AyronK
left a comment
There was a problem hiding this comment.
Very good addition, please consider adding a config for minimum parallelism and a default value (4 for example). Tested and works fine 👌🏻
|
I added a respective config option :) |
Introduction
We currently have thousands of statically built pages that need to be populated into the cache handler on startup. This takes about 30-40 seconds in our production instance. This change tries to reduce the time spent registering the initial cache by parallelizing the route population.
Summary
Populate page-cache in parallel instead of sequentially.
Old behavior
Previously, all routes were set one-by-one.
New behavior
Up to
os.availableParallelism()pages are now concurrently read from the filesystem and populated into the cache handler.Changes
os.availableParallelism()and awaitingPromise.all, so initial routes/pages are processed concurrently.CacheHandlerthat guaranteesonCreationruns exactly once;#ensureConfigured()now serializes calls while still letting the mainset/get/revalidateTaglogic run in parallel.OSS @durchblicker