codefloe/forgejo-codefloe
Watch
4
12
Fork
You've already forked forgejo-codefloe
0

fix: run mirror sync git operations at lowest CPU and I/O priority #22

Merged
pat-s merged 7 commits from fix/mirror-sync-low-priority into v14.0/forgejo-codefloe 2026-02-17 23:17:18 +00:00
Owner

Summary

Large mirror repos like AUR (71M objects, 147k refs) were consuming ~86% CPU and ~28% RAM during fetch, starving the web server and causing context canceled errors, connection resets, and 3s+ PR merge times. The root cause was twofold:

  1. No resource limiting: Mirror git processes ran at normal priority, competing with web traffic
  2. Infinite restart loop: The update_mirrors cron runs every 10 minutes, but next_update_unix was only updated on successful sync. Failed or timed-out syncs left next_update_unix in the past, causing the mirror to be re-queued every 10 minutes. Even during a long-running sync (~25 min for AUR), the cron would re-queue the mirror since it had already been popped from the unique queue.

Changes

  • Low priority for mirror processes: Add LowPriority option to git.RunOpts that sets nice 19 (lowest CPU priority) and idle-class I/O scheduling on child git processes. Applied to all mirror pull sync operations (fetch, retry, wiki sync, wiki retry, prune). Linux-only via syscall.Setpriority and SYS_IOPRIO_SET; no-op on other platforms.

  • Fix mirror re-queuing during sync: Move ScheduleNextUpdate() to before runSync() so the mirror's next_update_unix is pushed forward immediately. This prevents the 10-minute cron from re-queuing a mirror that's still running or that just failed. On success, next_update_unix is rescheduled again from completion time.

  • Suppress forced-update noise: Add --no-show-forced-updates to mirror fetch commands.

Requirements

Requires CAP_SYS_NICE capability and setpriority/ioprio_set syscalls to be allowed in the systemd unit (deployed via systemd drop-in).

## Summary Large mirror repos like AUR (71M objects, 147k refs) were consuming ~86% CPU and ~28% RAM during fetch, starving the web server and causing context canceled errors, connection resets, and 3s+ PR merge times. The root cause was twofold: 1. **No resource limiting**: Mirror git processes ran at normal priority, competing with web traffic 2. **Infinite restart loop**: The `update_mirrors` cron runs every 10 minutes, but `next_update_unix` was only updated on successful sync. Failed or timed-out syncs left `next_update_unix` in the past, causing the mirror to be re-queued every 10 minutes. Even during a long-running sync (~25 min for AUR), the cron would re-queue the mirror since it had already been popped from the unique queue. ### Changes - **Low priority for mirror processes**: Add `LowPriority` option to `git.RunOpts` that sets nice 19 (lowest CPU priority) and idle-class I/O scheduling on child git processes. Applied to all mirror pull sync operations (fetch, retry, wiki sync, wiki retry, prune). Linux-only via `syscall.Setpriority` and `SYS_IOPRIO_SET`; no-op on other platforms. - **Fix mirror re-queuing during sync**: Move `ScheduleNextUpdate()` to before `runSync()` so the mirror's `next_update_unix` is pushed forward immediately. This prevents the 10-minute cron from re-queuing a mirror that's still running or that just failed. On success, `next_update_unix` is rescheduled again from completion time. - **Suppress forced-update noise**: Add `--no-show-forced-updates` to mirror fetch commands. ### Requirements Requires `CAP_SYS_NICE` capability and `setpriority`/`ioprio_set` syscalls to be allowed in the systemd unit (deployed via systemd drop-in).
pat-s force-pushed fix/mirror-sync-low-priority from f0e8a9c17d
Some checks failed
testing / frontend-checks (pull_request) Successful in 1m51s
testing / backend-checks (pull_request) Failing after 8m31s
testing / test-pgsql (pull_request) Has been skipped
testing / test-sqlite (pull_request) Has been skipped
testing / test-e2e (pull_request) Has been skipped
testing / test-mysql (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (redict) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / security-check (pull_request) Has been skipped
testing / test-unit (pull_request) Has been skipped
to 4e7a1330ab
All checks were successful
testing / frontend-checks (pull_request) Successful in 1m47s
testing / backend-checks (pull_request) Successful in 7m33s
testing / test-e2e (pull_request) Successful in 42m48s
testing / test-unit (pull_request) Successful in 16m27s
testing / test-remote-cacher (redis) (pull_request) Successful in 5m35s
testing / test-mysql (pull_request) Successful in 34m20s
testing / test-remote-cacher (garnet) (pull_request) Successful in 2m56s
testing / test-remote-cacher (redict) (pull_request) Successful in 2m58s
testing / test-remote-cacher (valkey) (pull_request) Successful in 5m30s
testing / test-sqlite (pull_request) Successful in 45m57s
testing / security-check (pull_request) Successful in 3m36s
testing / test-pgsql (pull_request) Successful in 48m9s
2026-02-17 12:00:47 +00:00
Compare
perf: limit mirror fetch negotiation to HEAD instead of all refs
Some checks failed
testing / frontend-checks (pull_request) Successful in 1m53s
testing / backend-checks (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
testing / test-e2e (pull_request) Has been cancelled
testing / test-unit (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
testing / security-check (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (redict) (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
f779dfb670
For mirrors with many refs (e.g. AUR with 147k+), git fetch negotiates
against every local ref, causing rev-list to walk the entire object
graph. This consumed ~65% CPU for 20+ minutes per sync.

Use --negotiation-tip=HEAD to limit negotiation to a single ref, which
is sufficient for mirrors since HEAD establishes a common ancestor.

Also add --no-show-forced-updates to skip per-ref force-update checks.
perf: use noop negotiation algorithm for mirror fetches
Some checks failed
testing / test-unit (pull_request) Has been cancelled
testing / test-e2e (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
testing / security-check (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / frontend-checks (pull_request) Successful in 1m54s
testing / backend-checks (pull_request) Has been cancelled
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / test-remote-cacher (redict) (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
1b48b1ecb6
Replace --negotiation-tip=HEAD with fetch.negotiationAlgorithm=noop.
The negotiation-tip only limits what we send to the server, but the
expensive part is the local rev-list --not --all walk which still
enumerates all refs.

With noop, git skips negotiation entirely. The server uses protocol v2
ref advertisement to determine what to send, avoiding the rev-list
walk altogether. For mirrors that sync regularly, the server sends only
the delta — a tiny or empty pack for up-to-date mirrors.
fix: pass noop negotiation via env vars instead of -c flag
Some checks failed
testing / frontend-checks (pull_request) Successful in 1m54s
testing / backend-checks (pull_request) Successful in 15m24s
testing / test-unit (pull_request) Successful in 7m24s
testing / test-remote-cacher (redict) (pull_request) Successful in 3m1s
testing / test-remote-cacher (garnet) (pull_request) Successful in 3m3s
testing / test-remote-cacher (redis) (pull_request) Successful in 5m1s
testing / test-remote-cacher (valkey) (pull_request) Successful in 5m19s
testing / test-mysql (pull_request) Successful in 35m53s
testing / test-e2e (pull_request) Successful in 37m13s
testing / test-sqlite (pull_request) Failing after 42m37s
testing / test-pgsql (pull_request) Successful in 49m20s
testing / security-check (pull_request) Has been skipped
5ad980a7b4
The -c flag was being appended after the fetch subcommand, causing
"unknown switch" errors. Use GIT_CONFIG_COUNT/KEY/VALUE environment
variables instead, which apply as git config before subcommand parsing.
revert: remove noop negotiation algorithm for mirror fetches
Some checks failed
testing / test-remote-cacher (garnet) (pull_request) Successful in 3m15s
testing / test-remote-cacher (valkey) (pull_request) Successful in 5m2s
testing / test-remote-cacher (redict) (pull_request) Successful in 4m55s
testing / frontend-checks (pull_request) Successful in 1m48s
testing / backend-checks (pull_request) Successful in 7m23s
testing / test-unit (pull_request) Successful in 8m8s
testing / test-remote-cacher (redis) (pull_request) Successful in 3m17s
testing / test-e2e (pull_request) Successful in 38m28s
testing / test-mysql (pull_request) Successful in 38m59s
testing / test-sqlite (pull_request) Failing after 44m28s
testing / test-pgsql (pull_request) Successful in 49m8s
testing / security-check (pull_request) Has been skipped
ef873b7c33
The noop algorithm skips negotiation but doesn't help with the real
bottleneck: the post-fetch connectivity check (rev-list --not --all),
which is unavoidable for repos with many refs. Meanwhile noop risks
larger downloads since the server can't optimize the pack. Keep the
global skipping algorithm instead.
fix: schedule next mirror update before sync to prevent cron re-queuing
Some checks failed
testing / frontend-checks (pull_request) Successful in 1m52s
testing / backend-checks (pull_request) Failing after 9m35s
testing / test-e2e (pull_request) Has been skipped
testing / test-mysql (pull_request) Has been skipped
testing / test-pgsql (pull_request) Has been skipped
testing / test-unit (pull_request) Has been skipped
testing / test-remote-cacher (redict) (pull_request) Has been skipped
testing / test-sqlite (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / security-check (pull_request) Has been skipped
d382bfb3d3
The update_mirrors cron runs every 10 minutes and picks up all mirrors
where next_update_unix <= now. Previously, next_update_unix was only
updated on successful sync completion. This meant that while a long-running
sync was in progress (e.g. AUR with 147k refs taking 25+ min), the cron
would re-queue the mirror every 10 minutes, and on failure it would never
be rescheduled at all — creating an infinite retry loop.

Move ScheduleNextUpdate() to before runSync() so the mirror is immediately
pushed forward by its configured interval, preventing re-queuing during
the sync. On success, it reschedules again from completion time.
chore: remove unused TouchMirror function
All checks were successful
testing / test-unit (pull_request) Successful in 8m28s
testing / frontend-checks (pull_request) Successful in 1m41s
testing / backend-checks (pull_request) Successful in 15m15s
testing / test-remote-cacher (redis) (pull_request) Successful in 5m22s
testing / test-remote-cacher (valkey) (pull_request) Successful in 5m24s
testing / test-remote-cacher (redict) (pull_request) Successful in 5m25s
testing / test-e2e (pull_request) Successful in 29m37s
testing / test-sqlite (pull_request) Successful in 42m33s
testing / test-remote-cacher (garnet) (pull_request) Successful in 5m25s
testing / test-mysql (pull_request) Successful in 29m44s
testing / test-pgsql (pull_request) Successful in 44m38s
testing / security-check (pull_request) Successful in 1m52s
issue-labels / backporting (pull_request_target) Has been skipped
milestone / set (pull_request_target) Has been skipped
6e4b15bd9d
No longer called after moving ScheduleNextUpdate() before runSync().
Fixes deadcode lint failure.
pat-s merged commit ba71cc3d4f into v14.0/forgejo-codefloe 2026-02-17 23:17:18 +00:00
pat-s deleted branch fix/mirror-sync-low-priority 2026-02-17 23:17:19 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
codefloe/forgejo-codefloe!22
No description provided.