Skip to content

Improve performance of snowflake ids in cron jobs - #64944

Merged
CarlSchwan merged 3 commits into
masterfrom
worktree-snowflake-file-sequence
Oct 12, 2026
Merged

CarlSchwan merged 3 commits into
masterfrom
worktree-snowflake-file-sequence

Conversation

@CarlSchwan

Copy link
Copy Markdown
Member

Summary

Improve greatly speed of preview migration job as this is generating a lot of snowflake ids

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

ISequence::nextId() takes the server id, the seconds and the
milliseconds, but the generator passed the seconds, the milliseconds and
the server id, so the sequences were keyed on the wrong values.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Store one slot per second of the TTL window and per millisecond in each
lock file, so generating an id only reads and writes 8 bytes instead of
decoding, filtering and rewriting a JSON map of the last 30 seconds.

The fsync is not needed as the files only coordinate processes running
at the same time.

Generating an id went from 660µs to 22µs with the temporary directory on
disk, and from 24µs to 11µs on tmpfs.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
@CarlSchwan CarlSchwan added this to the Nextcloud 36 milestone Sep 30, 2026
@CarlSchwan CarlSchwan self-assigned this Sep 30, 2026
@CarlSchwan
CarlSchwan requested a review from a team as a code owner September 30, 2026 15:39
@CarlSchwan
CarlSchwan requested review from Altahrim, come-nc, icewind1991 and leftybournes and removed request for a team September 30, 2026 15:39
@CarlSchwan

Copy link
Copy Markdown
Member Author

/backport to stable35

@CarlSchwan

Copy link
Copy Markdown
Member Author

/backport to stable34

@CarlSchwan

Copy link
Copy Markdown
Member Author

/backport to stable33

@icewind1991

Copy link
Copy Markdown
Member

A description of the algorithm would be nice

@Altahrim Altahrim left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice!

Comment thread lib/private/Snowflake/FileSequence.php Outdated
This allow to simplify a bit the code, also add a small description of
the algorithm.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
@CarlSchwan
CarlSchwan force-pushed the worktree-snowflake-file-sequence branch from 7b9de62 to e69b8ed Compare October 1, 2026 08:18
@CarlSchwan

Copy link
Copy Markdown
Member Author

Ci failure is unrelated and will be fixed with #64975

@CarlSchwan
CarlSchwan merged commit cd002bd into master Oct 12, 2026
155 of 156 checks passed
@CarlSchwan
CarlSchwan deleted the worktree-snowflake-file-sequence branch October 12, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants