Reducing PieFed storage usage

Some PieFed instances will have been running for a couple of years now, and content will have been piling up quite a bit. Here are some tips that can significantly change the picture.

Don’t make copies of remote media

PieFed keeps copies of post images, author avatars, community icons locally, separate from the origin server they came from. This is good for privacy because then viewers of the posts won’t make requests to the origin servers but it does mean a lot of ‘wasted’ storage. You can turn it off at /admin/misc:

Don’t keep posts forever

Many communities have content that almost no one will look at once it is old so there is no need to keep the posts within forever. To find good candidates for trimming, go to /admin/communities?sort_by=post_count+DESC and edit each one to set it’s “Retain content” value to something other than ‘Forever’. Post trimming happens during the daily cron job that does tidy-ups in the background so make sure you have this working. There will be a warning at the top of /admin/home if not.

Trash low-quality posts

Many posts are created automatically by bots – these tend to have low engagement. To automatically delete bot posts with no replies, set the BOT_CONTENT_RETENTION environment variable to a number and after that many months the post will be deleted. MICROBLOG_CONTENT_RETENTION does the same thing for posts from Mastodon which also tend to be voluminous and without replies.

Fend off scrapers

This isn’t really a storage issue but small VPSs with small storage will often have few CPU cores so you need to keep CPU load down. Ensure the environment variable ANOOBIS is set to 1.

Set up S3

Storing media in S3 is often cheaper than storage on the VPS. It doesn’t solve database bloat the way earlier suggestions do, though.

Follow the instructions at https://codeberg.org/rimu/pyfedi/src/branch/main/INSTALL.md#s3-object-storage to get it working then set the FLASK_DEBUG environment variable to 1 and go to /test_s3 to make sure it’s working.

Don’t forget to remove FLASK_DEBUG afterwards, it ruins performance and background processing.

That will make all future posts use S3 but leave the old post images in your VPS storage. If you want to move the old images to S3, follow this process:

From the terminal, open a shell inside your docker container:

docker exec -it piefed_app1 bash

export FLASK_APP=pyfedi.py

flask move-files-to-s3

flask move-post-images-to-s3

flask move-more-post-images-to-s3

Leave a Reply

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