Repository navigation
Conversation
vndmtrx
added a commit
to helios-ptbr/helios-server
that referenced
this pull request
Nov 19, 2026
Contributor
|
We made this fix on our version of the system here at Unicamp. On a large election - 100 candidates ballot, 7.5k voters - getting all the ballots at once meant +4GB of memory. It was exhausting the VM resources, entering into swap regime, slowing tally time considerably. We used |
Owner
|
thank you for this! |
Owner
|
I'm going to replace this with #573 which has your commit + an |
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.
Election.compute_tallyiteratesself.voter_set.exclude(vote=None). Django loads the whole queryset (every voter and its encrypted ballot) before the loop starts, so memory grows linearly with the number of voters. This adds.iterator(chunk_size=500). The tally is identical.Growth rate
Peak RSS of the process running the tally loop (3 questions, 5 options each, min 0, max 1):
Comparison
Time differs by -3% to +4%, within run-to-run noise. The tally is identical in all 48 scenarios (10 to 50,000 voters, 1 to 5 questions, min 0 or 1, max 1 or all, fixed or random order, 1 to 10 trustees, 1 to 10 admins).
How to reproduce
voter.vote). Ballots may repeat, since the cost depends on ballot size and count, not on being distinct.manage.py shell), run the loop ofcompute_tallywith and without.iterator(chunk_size=500), without saving.resource.getrusage(resource.RUSAGE_SELF).ru_maxrss(KiB on Linux) and compare a hash of the resulting tally.Setup used: Docker, PostgreSQL 16, one
webprocess, 20 CPUs, 31 GiB RAM, nothing else running.Tests
ComputeTallyTestsinhelios/tests.py:test_compute_tally_matches_loading_all_voters: the tally fromcompute_tallyequals the tally built by loading all voters first (samenum_tallied, same ciphertexts).test_compute_tally_streams_voters: voters are read withiterator(chunk_size=...). It fails without the change.Full suite: 339 tests OK.