Mastodon server scaling

Comments and improvement suggestions welcomed!

My goals and interests are for configuring cloud based virtual Mastodon servers to scale from 1-500 users. This page is going to be a series of improvements one can make to scale or improve the operation of their Mastodon instance. This post presumes you already have a Mastodon instance up and running in at least a single user form, and is not an installation guide.

I am currently running a 2 server Mastodon cluster hosted on Digital Ocean. The main server is Mastodon v4.1.6 on Ubuntu 20.04 LTS, with 4 premium Intel vCPUs, 8GB RAM, and 160GB NVMe SSD. The database server is PostgreSQL on Ubuntu 22.04 LTS with 2 premium Intel vCPUs, 2GB RAM, and 90GB NVMe SSD.

Swap space

One of the first things you need to do is check if you have a swap file.

# swapon --show

If not, follow these directions to add and configure one, or configure you’re existing swap file. I suggest 4GB. Less if you have to and more won’t help you.

How To Add Swap Space on Ubuntu 20.04
How To Add Swap Space on Ubuntu 22.04

Sidekiq services scaling

Because TurtleIsland.social has 4 vCPUs, we split the default Sidekiq /etc/systemd/system/mastodon-sidekiq.service into 3 processes. When we had 2 vCPUs, we split it into the first 2 processes.

/etc/systemd/system/mastodon-sidekiq-scheduler.service which runs sidekiq -c 5 -q scheduler,1 -q mailers,1
/etc/systemd/system/mastodon-sidekiq-1.service which runs sidekiq -c 5 -q default,8 -q push,6 -q ingress,4 -q pull,1
/etc/systemd/system/mastodon-sidekiq-1.service which runs sidekiq -c 5 -q default,8 -q push,6 -q ingress,4 -q pull,1

As per these instructions:
Sidekiq Tuning Small Mastodon Servers

Ingress memory leaking

Web services scaling

Mastodon database server

See this article to build a database server
Steps to add a dedicated database server to Mastodon

Rate Limits

Edit this file:
/home/mastodon/live/config/initializers/rack_attack.rb

Change this:
throttle(‘throttle_authenticated_api’, limit: 1_500, period: 5.minutes) do |req|
req.authenticated_user_id if req.api_request?
end

To this:
throttle(‘throttle_authenticated_api’, limit: 3_000, period: 5.minutes) do |req|
req.authenticated_user_id if req.api_request?
end

Restart mastodon* services

Thanks!
-Yehuda

Updated periodically – About TurtleIsland.social
Updated periodically – Migrating to TurtleIsland.social
Updated periodically – Introduction to Settler Colonialism
Updated periodically – Decolonization is not a metaphor
Updated periodically – Mvskoke History & Resources

Follow on Mastodon – TurtleIsland.social/@Yehuda

This page is subject to content updates/additions. If you think any content should be updated or added, please leave a private comment on Mastodon – TurtleIsland.social/@Yehuda.