What is “Sidekiq” and why is it important?
About the queues.
How to configure multiple Sidekiq services.
- Navigate to /etc/systemd/system/ on your server.
cd /etc/systemd/system/
- Create a new file called mastodon-sidekiq-default.service
vi mastodon-sidekiq-default.service
- Copy and paste the code from this GitHub gist: mastodon-sidekiq-default.service (github.com)
- Reload the systemd daemon.
systemctl daemon-reload
- Enable and start the service.
systemctl enable mastodon-sidekiq-default.service –now
And that’s all there is to it to add another service for your Sidekiq queues! You can keep adding services depending on your server’s resources. The rule of thumb is 1 service per CPU core, but I tend to leave at least 1 CPU core available for handling media encoding (ffmpeg/convert processes).
From this image you can see I have multiple services on 2 different servers, I have 4 services on one server (sidekiq00) and 3 services on the other (sidekiq01). I keep my scheduler queue on a single service and, because I had issues with e-mails previously, I keep my mailer queues limited to 2 services on the same server.
Running Sidekiq services on remote servers
- Sidekiq queues need access to the PostgreSQL and Redis databases so this only works if you have your database servers configured for remote connections.
- Sidekiq queues need access to your media storage, you will need to have network storage configured (NFS will not work due to latency, go with an S3 compatible object storage platform).
- You will need to basically have Mastodon installed on each Sidekiq server, follow the install guide but do not configure PostgreSQL, Redis, Nodejs, Puma, or nginx. The only steps you need to follow are the Prerequisites (skipping the nginx, PostgreSQL, and Redis parts) and the Setting up Mastodon steps.
- Copy over your .env.production file from your main server.
- Once you have Mastodon installed on the new server, follow the steps above to configure the Sidekiq services, do this last since it will need the .env.production file.