Reducing PieFed RAM usage

PieFed 1.8 introduces two new environment variables that you can set to reduce the amount of RAM PieFed uses on the server.

PieFed comes with “mid-range” default settings, suitable for an instance of up to 100 people. But the vast majority of instances are less than that and many are for a single user so in those cases the defaults are overkill by a large margin.

After changing any of these (in .env.docker or .env files) you will need to restart your containers or services.

App workers

‘gunicorn’ is the piece of software that PieFed uses to interface with the web and the number of gunicorn processes we run determines how many concurrent users an instance can have (even if you have 50 weekly active users, most likely only a couple will be using it at a time). For a low number of users you only need 1 or 2 workers.

GUNICORN_WORKERS = 2

PieFed defaults to 4 workers or the number of cores your server has divided by two, whichever is greater. So there’s an opportunity to at least halve the RAM used by gunicorn.

Stop scrapers from hammering your instance by setting ANOOBIS = 1, thus leaving more capacity for real traffic.

Background workers

‘celery’ is the piece of software that PieFed uses for background tasks including receiving and sending federation traffic. The amount of federation traffic your instance receives depends on how many communities your users have joined which might only be a couple of dozen on a single-user instance.

CELERY_CONCURRENCY = 2

PieFed defaults to 4 celery processes which is enough for handling the load from subscribing to every active community there is and thousands of Mastodon accounts. PieFed.social uses 6 processes, due to hosting quite a few local communities and lots of users which adds extra federation traffic. So 2 should be enough for most smaller instances.

Single-user instances might be able to get away with a single celery process, especially if the daily cron job is set to run at a quiet time (the cron job kicks off a celery task two which would get in the way of federation if there is only one worker). So half the usual RAM usage should be possible, maybe even 25%.

Give it a try and see what happens. If your redis container RAM usage steadily climbs up to hundreds of MB then the background queue is filling up and you need more celery workers to process it fast enough. Monitor ram usage with docker stats.

Database

Take a look in compose.yaml, near the top, for things like this:

      # Memory
      - -c
      - shared_buffers=1GB
      - -c
      - effective_cache_size=2GB
      - -c
      - work_mem=32MB

Try halving those values, see what happens. Chances are it’ll be fine.

With these tweaks, crust.piefed.social uses ~1.5 GB of RAM.

Leave a Reply

Your email address will not be published. Required fields are marked *