A picture is worth a 1000 memories

I recently had a bug that made me pretty angry. Load, CPU & Memory would randomly go nuts. The logs told me something about a memory issue in various places around the (WordPress) application. Nothing specific to nail it down precisely. So I went for it: Optimize the server until this thing vanishes.

My first steps were to replace Apache with NGINX, then standard PHP5 with PHP5-FPM, introduced a more eloquent caching method. But still it happened throughout the week. As said: Randomly.

After those improvements I had to accept that something within the application is causing those issues. I switched off suspicious plugins, read a ton of stuff about all kind of plugins, issues, … Still: Randomly the server went nuts.

One late night I tried some sort of image comparison, kind of finding duplicates of images. Therefore I resized the images to thumbnails to display them. As most of the images are pretty big (3000 x 3000 pixels, 4MB) it took a while to resize them. That’s the moment when it struck me! A function called aq_resize is used to resize images on the fly and it’s used in one of the most global area of the application: the footer. As it turned out aq_resize always had to resize the full image, not some sort of already resized image (defined by add_image_size). The spikes in the server performance were related to the cache, which is purged everytime a new entry is published or updated.

So by simply replacing the full image with the already downsized image I solved this issue quite easily.

Something good came out of this: The server is running smoothly and now I know at least how to install NGINX, FPM, MySQL and a lot of other components which are really useful.

This is a reminder to myself to never ever make this mistake again!

Leave a Reply

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