Batch download counts - #1518
Open
LaurentRDC wants to merge 2 commits into
Open
Conversation
LaurentRDC
force-pushed
the
optimize-download-counts
branch
from
August 24, 2026 20:59
5ce96f4 to
2321247
Compare
This patch batches download counts, rather than incurring an acid-state transaction for every download. This reduces the number of events related to download counts, while creating the potential for some downloads being dropped due to the in-memory cache being flushed only periodically. Benchmarks included in this patch show much better replay times, and a smaller acid-state event log, proportional to the batching factor. The cost is slightly higher memory usage due to the in-memory download counts cache. In order to properly shutdown the download counts feature, a "pre-shutdown" step has been added to features, such that download counts can be flushed to disk on graceful shutdown. This batching does not require anything special when it comes to deployment, as the previous download counts can be modeled as batches of 1. This patch therefore doesn't require a migration. Partially fixes haskell#1342
LaurentRDC
force-pushed
the
optimize-download-counts
branch
from
August 24, 2026 21:01
2321247 to
d7ab719
Compare
LaurentRDC
commented
Aug 24, 2026
LaurentRDC
marked this pull request as ready for review
August 24, 2026 23:06
|
Tick the box to add this pull request to the merge queue (same as
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch batches download counts, rather than incurring an acid-state transaction for every download.
This reduces the number of events related to download counts, while creating the potential for some downloads being dropped due to the in-memory cache being flushed only periodically.
Benchmarks included in this patch show much better replay times, and a smaller acid-state event log, proportional to the batching factor. The cost is slightly higher memory usage due to the in-memory download counts cache.
In order to properly shutdown the download counts feature, a "pre-shutdown" step has been added to features, such that download counts can be flushed to disk on graceful shutdown.
This batching does not require anything special when it comes to deployment, as the previous download counts can be modeled as batches of 1. This patch therefore doesn't require a migration.
Partially fixes #1342. The way downloads are stored in per package-day counts forever could also be optimized, but this will require a change in the event log representation.
Benchmarks
The
DownloadCountBenchbenchmarks below distributed 20k downloads over 300 packages. In thebatchedmode, downloads are batched in batches of 3000. Usingindividualmode uses the legacy patch of incrementing the on-disk download count by 1.Legacy behavior
New behavior, where batches of 3000 download counts are flushed at once
This is an extreme example, but it still shows major performance improvements, roughly proportional to batching.