Skip to content

Instantly share code, notes, and snippets.

@Showfom
Created April 29, 2022 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Showfom/0f0d2cda25a8d2de36b600c53534eb00 to your computer and use it in GitHub Desktop.
Save Showfom/0f0d2cda25a8d2de36b600c53534eb00 to your computer and use it in GitHub Desktop.
Split sidekiq

A common issue for Mastodon instances is a backlogged sidekiq queue. This is easily to fix by splitting up Sidekiq service files.

The following approach assumes that your non-Docker Mastodon lives at /home/mastodon/live.

Steps

Add all files to /etc/systemd/system/.

Adjust the process nums after -c in the ExecStart= line, based on your server capacity.

Reload the deamon and enable all processes.

systemctl daemon-reload
systemctl enable --now mastodon-sidekiq-default-@1.service mastodon-sidekiq-push-@1.service mastodon-sidekiq-mailers-@1.service mastodon-sidekiq-pull-@1.service

References

@stux @bgme

[Unit]
Description=mastodon-sidekiq-default-%i
After=network.target
[Service]
Type=simple
User=mastodon
WorkingDirectory=/home/mastodon/live
Environment="RAILS_ENV=production"
Environment="DB_POOL=50"
Environment="MALLOC_ARENA_MAX=2"
ExecStart=/home/mastodon/.rbenv/shims/bundle exec sidekiq -c 50 -q default
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=mastodon-sidekiq-mailers-%i
After=network.target
[Service]
Type=simple
User=mastodon
WorkingDirectory=/home/mastodon/live
Environment="RAILS_ENV=production"
Environment="DB_POOL=25"
Environment="MALLOC_ARENA_MAX=2"
ExecStart=/home/mastodon/.rbenv/shims/bundle exec sidekiq -c 25 -q mailers
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=mastodon-sidekiq-pull-%i
After=network.target
[Service]
Type=simple
User=mastodon
WorkingDirectory=/home/mastodon/live
Environment="RAILS_ENV=production"
Environment="DB_POOL=25"
Environment="MALLOC_ARENA_MAX=2"
ExecStart=/home/mastodon/.rbenv/shims/bundle exec sidekiq -c 25 -q pull
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=mastodon-sidekiq-push-%i
After=network.target
[Service]
Type=simple
User=mastodon
WorkingDirectory=/home/mastodon/live
Environment="RAILS_ENV=production"
Environment="DB_POOL=25"
Environment="MALLOC_ARENA_MAX=2"
ExecStart=/home/mastodon/.rbenv/shims/bundle exec sidekiq -c 25 -q push
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment