When your GitLab instance becomes sluggish with only 4 projects, the top
output reveals the real culprit:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8760 git 20 0 648908 412768 14700 S 0.7 20.2 0:30.58 bundle
8799 git 20 0 513748 302632 14300 S 0.0 14.8 0:20.02 bundle
Multiple Ruby bundle
processes are consuming over 60% of your 2GB memory. The process tree confirms these are GitLab components:
systemd─┬─agetty
├─bundle─┬─3*[bundle───{ruby-timer-thr}]
│ └─{ruby-timer-thr}
Before diving deeper, run these to gather more evidence:
# Check GitLab service status
sudo gitlab-ctl status
# View memory usage breakdown
sudo gitlab-psql -c "SELECT pg_stat_activity.pid, pg_stat_activity.query_start,
pg_stat_activity.state, pg_stat_activity.query FROM pg_stat_activity;"
# Check Unicorn workers
sudo grep worker_processes /var/opt/gitlab/gitlab-rails/etc/unicorn.rb
For small servers (2-4GB RAM), try these configuration tweaks in /etc/gitlab/gitlab.rb
:
# Reduce Unicorn workers
unicorn['worker_processes'] = 2
# Limit Sidekiq concurrency
sidekiq['concurrency'] = 5
# Adjust PostgreSQL settings
postgresql['shared_buffers'] = "256MB"
postgresql['work_mem'] = "4MB"
# Enable swap as emergency measure (if not already present)
swap_file '/var/opt/gitlab/swap' do
size 1024
end
Apply changes with:
sudo gitlab-ctl reconfigure
If problems persist after configuration changes, consider these advanced troubleshooting steps:
# Install memory_profiler gem
sudo /opt/gitlab/embedded/bin/gem install memory_profiler
# Create diagnostic script at /tmp/memcheck.rb
require 'memory_profiler'
report = Memory_profiler.report do
# Load problematic GitLab components
require_relative '/opt/gitlab/embedded/service/gitlab-rails/config/environment'
end
report.pretty_print
For Ubuntu 16.04 systems, consider these upgrade options:
# Option 1: Upgrade OS first
sudo do-release-upgrade
# Option 2: Migrate to Omnibus package
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo apt-get install gitlab-ce
Remember to backup first:
sudo gitlab-rake gitlab:backup:create
When running Gitlab CE on a Ubuntu 16.04 server with limited resources (2GB RAM in this case), we observed severe performance degradation during operations like git pushes and web interface access. The top
output revealed multiple bundle
processes consuming over 60% of total memory collectively:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 8760 git 20 0 648908 412768 14700 S 0.7 20.2 0:30.58 bundle 8799 git 20 0 513748 302632 14300 S 0.0 14.8 0:20.02 bundle
These processes are part of Gitlab's Ruby on Rails architecture. The pstree
output shows they're worker processes for handling requests:
bundle─┬─3*[bundle───{ruby-timer-thr}] └─{ruby-timer-thr}
First, let's verify and adjust the Unicorn worker configuration (Gitlab's application server):
# Edit the Gitlab configuration sudo nano /etc/gitlab/gitlab.rb # Recommended settings for 2GB server unicorn['worker_processes'] = 2 unicorn['worker_memory_limit_min'] = "250MB" unicorn['worker_memory_limit_max'] = "300MB" # Apply changes sudo gitlab-ctl reconfigure
For systems with memory constraints, consider these additional optimizations:
# Reduce Sidekiq concurrency (background jobs) sidekiq['concurrency'] = 5 # Adjust PostgreSQL shared buffers postgresql['shared_buffers'] = "256MB" # Enable memory killer unicorn['oom_score'] = -900 # Apply changes sudo gitlab-ctl reconfigure sudo systemctl restart gitlab-runsvdir
Install these utilities for deeper memory analysis:
sudo apt-get install -y ruby-dev ruby-bundler sudo gem install derailed_benchmarks # Run memory profiler bundle exec derailed bundle:mem
For consistently overloaded systems:
- Upgrade to at least 4GB RAM (Gitlab's minimum recommended)
- Consider switching to Puma instead of Unicorn (Gitlab 13.0+)
- Implement swap space as temporary relief (not ideal for production)
Regularly monitor memory usage with this cron job:
# Add to /etc/crontab 0 * * * * root /usr/bin/curl -s http://localhost/-/metrics | grep ruby_process_resident_memory_bytes