← logbuild #24 passed2a2ecc6
Fix a Slow Self-Hosted GitLab: The RAM Trap During Pipelines
Self-hosted GitLab becomes very slow during CI pipelines? Find the RAM limit with five commands, reduce Puma/Sidekiq/Prometheus in gitlab.rb, and cut build time in half.
· 15 min read
The web UI freezes. git push hangs. A build that used to take 1:40 now takes 3:30. The runner VM looks idle in htop. The network is fine. It only happens while a pipeline is running.
The cause isn’t your network or your runner. The GitLab server reaches its RAM limit and starts to swap. Swap means Linux moves memory to the disk, and the disk is much slower than RAM. A few default services use more memory than most homelab machines can give. One Node-based pipeline is then enough to push the whole server into swap.
This post is the plan I used to find and fix that problem. Five commands to diagnose, three changes to gitlab.rb, and the build time is back to 1:40.
Environment:
| Component | Value |
|---|---|
| GitLab | GitLab EE 18.9.1 (Omnibus, Debian) |
| Host | Debian 13 VM on Proxmox |
| VM Specs | 8 vCPU, 10 GB RAM, 60 GB SSD |
| Runner | Separate VM (Docker executor) |
| Workload | Astro static site → Cloudflare Pages |
In Simple Words#
- The problem
- While a pipeline runs, the GitLab web UI freezes and
git pushhangs. A build that took 1:40 now takes 3:30. - The root cause
- The GitLab server has no free RAM. Its default services fill almost all of the 10 GB. Pipeline work then pushes the server into swap, and swap uses the slow disk.
- The solution
- Check memory with five commands. Then run fewer Puma workers, lower the Sidekiq concurrency, and turn off services you do not use, like Prometheus. Add more swap for safety.
- Think of it like this
- Your small desk is covered with open books. To open one more book, you must first carry a book to a shelf in another room. You spend your time walking, not reading. Remove the books you never read, and you have room to work.
The Workflow That Lands on the Server#
Every time the problem appears, a single commit takes this path from your editor to a built artifact (the files that the build produces):
- On your laptop you create a branch (
git checkout -b feat/x), edit code and rungit commit. - You run
git push. Workhorse receives it. Workhorse is the first service on the GitLab server that sees each request. - Puma and Sidekiq create a pipeline. They store it in Postgres and Redis.
- The runner VM asks the server for work (
/api/v4/jobs/request). The server hands out the job, and the runner starts a job container withdocker run. - While the job runs, the job container sends its logs back to the server.
- At the end, the job container sends the artifact to the server. The server took part in every step.
The heavy work happens on the runner VM, in a Docker container. But the server takes part in every step. It receives the push, creates the pipeline, gives jobs to the runner, receives the logs, and stores the artifact. So a server with no free memory becomes very slow during pipelines, even when the runner is idle.
What We’ll Cover#
- Rule out the false leads — TLS, DNS, the runner competing with the server
- Understand what GitLab really does during a pipeline — Puma, Sidekiq, Workhorse, Postgres
- Diagnose in five commands — RAM, swap, load, OOM (out of memory) kills, disk
- Read real numbers from a swapping server — what the symptoms look like
- Trim
gitlab.rb— Puma workers, Sidekiq concurrency, turn off Prometheus/KAS - Grow swap for safety
- Verify the fix — what
free -handvmstatshould look like under load
What It’s Not#
Before you tune anything, rule out three things that are not the problem:
| Suspect | Verdict | Why |
|---|---|---|
| TLS / HTTPS | Not the cause | TLS overhead is ~1–3% CPU. You’d see the CPU at 100%, not RAM used up. |
| Pi-hole / DNS routing | Not the cause | Slow DNS would slow everything, not only pipelines. Test with dig. |
| Runner / server contention | Not the cause | The runner already runs on a separate VM. If the runner VM is idle, the server is the problem. |
If htop on the runner is idle and the GitLab VM is the slow one, this post is for you.
What Actually Happens on the Server During a Pipeline#
The runner has its own VM, but the GitLab server still has work to do every time a job runs:
- Runner API polling. The runner calls
/api/v4/jobs/requestevery 3 seconds by default to ask for new jobs. Every call goes through Puma, the GitLab web server. - Trace log streaming. While the job runs, the runner sends log output back all the time: Workhorse → Redis (
ci_build_trace_chunks) → Postgres. A build that prints a lot (npm install prints a lot) means many writes. - Sidekiq state machine. Sidekiq runs GitLab’s background jobs. Every status change starts workers:
BuildTraceChunkFlushWorker,BuildFinishedWorker,PipelineUpdateWorker, and others. - Artifact upload. At the end of the job, the runner sends artifacts back through Workhorse.
A 10 GB server runs Puma + Sidekiq + Postgres + Redis + Gitaly + Workhorse + nginx + Prometheus + Registry + KAS + Pages. That system is already at its memory limit, and all of this work comes on top. RAM is full → swap → everything waits.
Diagnose First#
Run this block on the GitLab VM while a pipeline is running. Five commands and one minute give you the full picture.
free -h && echo "---" && vmstat 2 5
sudo gitlab-ctl status
top -b -n 1 -o %MEM | head -25
sudo dmesg -T | grep -iE 'oom|killed process' | tail -20
df -h && sudo du -sh /var/opt/gitlab/* | sort -hHow to read each:
| Command | Watch for | Verdict |
|---|---|---|
free -h |
available close to zero, swap used |
RAM limit reached |
vmstat 2 5 |
si / so columns non-zero |
The server is swapping right now |
gitlab-ctl status |
Long list of services | Find anything you don’t use (kas, registry, pages, prometheus) |
top -o %MEM |
Biggest memory users | Tells you which setting to change |
dmesg |
Out of memory: Killed process … |
The kernel killed a GitLab process. This explains hangs. |
df -h + du |
/var/opt/gitlab/prometheus very large |
Disk wasted on a service you may not need |
Also make the symptom clear before you change anything. Is it a slow web UI, a slow git push / git clone, or a slow pipeline runtime? Each points to a different bottleneck: Puma for the UI, Gitaly for git, the whole stack for pipelines.
Where the Pressure Goes#
- The server has 10 GB of RAM. With the default settings, the GitLab services use about 9.9 GB. The 4 Puma workers alone use 4.8 GB.
- A pipeline starts and the server needs more memory. No RAM is free, so Linux moves memory to swap on the disk. The disk is slow, so everything waits.
- Fix, part 1:
puma['worker_processes'] = 2. Two Puma workers stop. This frees about 2.4 GB. - Fix, part 2:
prometheus_monitoring['enable'] = false. This frees about 600 MB more. - Now the pipeline work fits in RAM. Swap is almost empty, and the build takes 1:40 again.
Every service on the server holds memory. Add them up with the defaults of Omnibus, the all-in-one GitLab package. Puma alone is 4×1.2 GB. You are at the limit before the pipeline even starts.
Real Numbers From a Thrashing Box#
Thrashing means the server spends most of its time moving memory to and from swap. Here is what the diagnostic block showed on my server during a slow pipeline:
Headline signals#
| Signal | Value | Verdict |
|---|---|---|
| Free RAM | 207 MB / 10 GB | Very low |
| Swap used | 1.0 GB / 1.0 GB (100%) | Completely full |
| Load avg (1/5/15) | 0.17 / 19.70 / 23.71 | System was overloaded minutes ago |
| OOM kills | none | Swap took the load, and that is why it feels slow |
| Disk usage | 28 / 59 GB (50%) | Fine |
/var/opt/gitlab/prometheus |
13 GB | A waste for a one-person instance |
vmstat was quiet at the moment I ran it. But the 5- and 15-minute load averages of 19 and 23 prove the server was overloaded just before. When swap is full, every new memory request has to wait. That is the slowness you feel.
RAM breakdown from top#
4 × Puma workers @ ~1.2 GB = 4.8 GB ← biggest consumer
1 × Sidekiq = 1.8 GB
1 × Puma master = 0.7 GB
PostgreSQL (sum) ~ 1.5 GB
Prometheus = 0.6 GB (+13 GB disk)
Gitaly = 0.2 GB
Redis, nginx, exporters ~ 0.3 GB
─────────
~ 9.9 GB right at the 10 GB ceilingA 1–2 GB npm install during a CI job pushes the whole server into swap. That’s the root cause.
The full pre-fix snapshot#
total used free shared buff/cache available
Mem: 9Gi 9.4Gi 419Mi 2.2Gi 2.6Gi 539Mi
Swap: 1.0Gi 1.0Gi 412Ki
---
procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
r b swpd free buff cache si so bi bo in cs us sy id wa st gu
0 0 1048160 429860 33120 2712088 6 4 7253 272 1307 2 1 1 97 1 0 0Swap is fully used (1048160 KB), and available RAM is at 539 MB. Anything new must first push other memory pages out to disk.
And here is the full service list. I never use many of these:
run: alertmanager: …
run: gitaly: …
run: gitlab-exporter: …
run: gitlab-kas: …
run: gitlab-workhorse: …
run: logrotate: …
run: nginx: …
run: node-exporter: …
run: postgres-exporter: …
run: postgresql: …
run: prometheus: …
run: puma: …
run: redis: …
run: redis-exporter: …
run: sidekiq: …Alertmanager, node-exporter, postgres-exporter, redis-exporter, prometheus, gitlab-kas. These are six processes I haven’t used in months, and all of them hold memory.
The Fix#
Apply in order. Step 1 alone is usually enough.
Step 1 — Trim gitlab.rb#
Edit /etc/gitlab/gitlab.rb:
# Cut Puma from 4 workers to 2. Frees ~2.4 GB.
puma['worker_processes'] = 2
# Sidekiq default is 20; 10 is plenty for a solo instance.
sidekiq['max_concurrency'] = 10
# Frees ~600 MB RAM + lets you reclaim 13 GB of disk afterwards.
prometheus_monitoring['enable'] = false
# Disable only if you're not using the Kubernetes Agent.
gitlab_kas['enable'] = false
# Disable only if you're not using these.
registry['enable'] = false
gitlab_pages['enable'] = falseApply and restart:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restartOnly after Prometheus has really stopped (check with gitlab-ctl status), free its disk space:
sudo rm -rf /var/opt/gitlab/prometheus/dataStep 2 — Grow swap to 4 GB (safety net, not a cure)#
More swap doesn’t make a swapping server fast. It does prevent OOM kills. An OOM kill is when the kernel stops a process because memory ran out. That turns a slow server into a broken one.
sudo swapoff -a
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabStep 3 — Grow the VM (when convenient)#
If you can raise RAM from 10 to 16 GB in Proxmox, do it. That alone removes the limit. You can then turn Prometheus or KAS on again without counting memory.
| Resource | Current | Recommended |
|---|---|---|
| RAM | 10 GB | 16 GB |
| Swap | 1 GB | 4 GB |
| Disk | 60 GB | 60 GB (fine after Prometheus cleanup) |
Verify the Fix#
Restart, then run the diagnostic block again. This is the state you want:
si/soinvmstatstay at 0 under pipeline loadavailableRAM stays above 1–2 GB- Load average stays well below CPU count (8)
Here is the result on my server, with no pipeline running:
total used free shared buff/cache available
Mem: 9Gi 5.0Gi 4.0Gi 208Mi 1.4Gi 4.9Gi
Swap: 1.0Gi 25Mi 998MiRAM use dropped from 9.4 GB to 5.0 GB. Swap dropped from 100% used to ~2%. A pipeline now has 4 GB of free RAM to use, and it does not need the disk.
Under pipeline load:
procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
r b swpd free buff cache si so bi bo in cs us sy id wa st gu
1 0 25692 3456384 86496 1725492 6 4 7795 271 1320 2 1 1 97 1 0 0
0 0 25692 3443544 86500 1725492 0 0 0 40 1143 1123 2 0 97 0 0 0
0 0 25692 3442508 86500 1725492 0 0 0 0 1086 1165 2 0 98 0 0 0si and so stay at 0 in every 2-second sample. No swap I/O. This is what “not thrashing” looks like.
Build and deploy time for the staging/production pipeline:
| Phase | Before | After |
|---|---|---|
| Build + deploy | 03:30 | 01:40 |
Almost 2× faster, with one config file edit and no hardware change.
The pipeline history shows the difference clearly. Before the fix, pipeline durations changed a lot from run to run. Some runs took 3, 4, even 9 minutes:

After the fix, every recent pipeline takes about 1:30–1:40. The times are predictable, with no very slow runs:

Decision Tree — When to Apply What#
Not every slow GitLab has the same cause. Match the symptom to the fix:
| Symptom in diagnostic block | Likely cause | Apply |
|---|---|---|
si / so non-zero in vmstat |
RAM used up → swap | Step 1 (trim gitlab.rb) or grow RAM to 16 GB |
Puma processes use the most memory in top |
Too many Puma workers for the server | puma['worker_processes'] = 2 |
Sidekiq + Postgres use the most memory in top |
Many trace log writes + many state changes | Step 1 + quieter CI logs (set NPM_CONFIG_LOGLEVEL=error) |
| Gitaly uses the most memory | Big repo or slow disk | Check repo size, check Proxmox storage I/O |
Disk near full, /var/opt/gitlab very large |
Old artifacts, traces, registry | Clean old job traces, expire artifacts, prune the registry |
| No RAM/CPU stress, only a slow web UI | Wrong number of Puma workers | puma['worker_processes'] = 2 |
| Cloudflare-routed traffic, runner idle, server healthy | Network detour | See GitLab Runner Performance Optimization |
What You Have Now#
| Layer | Outcome |
|---|---|
| Server | RAM use down from 9.4 GB to 5.0 GB. 4 GB of free RAM for pipelines. |
| Services | Prometheus, KAS, Registry, Pages turned off (turn them on again when you really need them) |
| Disk | 13 GB freed from /var/opt/gitlab/prometheus |
| Pipeline | 03:30 → 01:40 with no hardware change |
| Safety | 4 GB swap, so a job that uses too much memory slows the server down and does not OOM-kill Puma |
Next Steps#
- GitLab Runner Performance Optimization — the same topic on the runner side. Direct internal connections, Docker executor tuning, caching,
needsfor parallel jobs. - Self-Host Harbor Image Registry on Debian — stop pulling from Docker Hub on every CI job. Smaller base-image pulls = less Workhorse traffic = less server load.
- Monitoring Proxmox with Grafana — the diagnostic block in this post only helps after the problem starts. A Grafana dashboard that watches RAM and swap on the GitLab VM shows this trend a week earlier, before “the pipeline is broken.”
- Linux Server Security Baseline — when the GitLab server is fast again, secure it.