Skip to content
Fragmented Development

Fixing performance issues in GNUsocial

GNUsocial is the most demanding services I run, by far. The strain on the database from all of the different GNUsocial, Friendica, etc. instances retrieving their subscribed users' feeds is more than I anticipated. Luckily, this story has a happy ending!

TL;DR: Install php5-memcached and memcached, enjoy fame and fortune.

For months, resource usage on my VPS has been creeping up. This month it finally broke 100%, or one whole CPU busy on average, which was a little scary. There are people (including myself) who depend on my VPS for their business, and that meant something needed to be done.

I scheduled an upgrade of GNUsocial, and started looking into possible solutions. Since the load was mostly DB-related, I started cleaning out old subscriptions (more on that later), and looked into caching. A cached query is one less query, right?

I'd heard about memcache, but never used it. A quick install later, and it was running (woo Debian). I learned that there are two PHP libraries for memcache; the "php5-memcache" library and "php5-memcached", which uses an external library and is generally preferred on unix-y systems.

I enabled the memcached plugin, installed php5-memcached, restarted php-fpm, and found that things were running much faster! Overjoyed, I posted a notice that maintenance was complete, and refreshed my timeline... which did not refresh. It seems like the memcached froze my timeline, which was not ideal.

I enabled the memcache plugin, and it caused an infinite loop of redirects. Also not the greatest.

I disabled them all in my GNUsocial config, but left the memcache server and PHP extensions installed. I remembered seeing a merge request in MMN's blog that gave me hope:

38ac5a7 Automatic memcache support enabler for config

After a check this morning, my CPU usage is hovering around 30%. Apparently, if you have a memcache server running, GNUsocial just uses it! Fantastic!

I'll be monitoring it closely for the next few days, but I think that has solved my performance issues. Thanks, GNUsocial!

Tags: server gnusocial

Add Your Comment