Understanding Your Configuration

Photo credit: Unsplash: forrestcavale

I believe that it is best to understand the configuration and behavior of the tools I use. I don’t appreciate a ‘black box’ approach to technology. I’ve always wanted to understand how and why things work the way they do.

Throughout my website tech series, I tried to explain the details of my approach and why the work the way they do.

I made a mistake.

Recently, I discovered I was really constrained for RAM on my web server, and was having some issues keeping all the processes running. After some investigation, I discovered the problem. I copied some nginx example configuration from the internet, and didn’t really understand what those values meant.

Here is the new diff from my nginx.conf file:

-  proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=GHOST:100m inactive=24h max_size=2g;
+  proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=GHOST:1m inactive=24h max_size=50m;

-  ssl_session_cache shared:SSL:20m;
+  ssl_session_cache shared:SSL:1m;

You can see I dropped the size of a few things. Let’s start with proxy_cache_path

From the nginx docs:

all active keys and information about data are stored in a shared memory zone, whose name and size are configured by the keys_zone parameter. One megabyte zone can store about 8 thousand keys.

Remember, we are talking about the cache that nginx maintains to hold copies of my Ghost blog pages. There are no where near 8,000 keys that I will be storing the in cache. That shared memory zone was allocated for nginx, no matter how much data I was putting in it. Instantly, 99 MB back in RAM.

I also adjusted the max_size parameter, but that is just for the disk space used before old objects are evicted from my cache. For the HTML being sent by Ghost, 2 GB was excessive, so I dropped it down to 50 MB.

Now, looking at ssl_session_cache, from the docs:

The cache size is specified in bytes; one megabyte can store about 4000 sessions.

Now, I hope to see my readership grow, but an SSL session cache that can hold 4,000 session should be plenty, so another 19 MB in RAM saved.

The lesson here is simple, there are lot of great examples of server configuration items on the internet. It is important to consider the server you are deploying. If, as in my case, it is just a tiny DigitalOcean server, you might need to adjust some things. You will need to consider the RAM, CPU, Storage, and software of your server, as well as the traffic you expect.

Most of all, make sure you understand what the directives your configuration uses are actually doing, and what each parameter means for the performance and stability of your setup.