1 GB VPS server Performance Tips
VPS server Performance

4 Performance tips for 1 GB VPS – run high traffic websites

The notion that the more the RAM, the better the performance is quite common in the smartphone industry. Every day we are seeing smartphones being launched with higher and higher RAMs for better performance. From a few KBs of RAM a decade ago, we are talking about 12GB RAM on a smartphone. But do we actually need that much RAM is the question? Most of our laptops are either 4 or 8GB RAM and work quite flawlessly.

Eventually, it all depends on how the software is optimized to utilize the RAM efficiently. In this post, I’ll be talking about optimizing the performance of a 1 GB VPS server for running high traffic websites and apps. You’ll be surprised that a 1 GB VPS server can run 4-5 medium traffic websites easily!

Word of caution

Before I deep dive into how to improve the performance of your 1 GB VPS server, please note that these settings may differ from one server to another. Tweaking these settings without understanding your requirements can lead to server crashes on your website or app. It totally depends on the stack you are using.

The optimization tips for 1 GB VPS given here are for Apache servers and precisely the LAMP stack (Linux, Apache, MySQL, PHP) I highly recommend taking a backup and snapshot of your VPS server before doing these changes. Further, I also suggest doing these changes on a staging server than the production server.

1GB VPS server Performance Tips
VPS server Performance

Lastly, if you are on shared hosting, this tutorial isn’t for you. As these settings require root access that is provided only with VPS hosting. If you’re confused between shared and cloud hosting, read my post on cloud hosting for bloggers to understand more.

4 Performance tips for 1 GB VPS

1. Add a Swap Space

The first and foremost thing that I’ll recommend you do after doing the basic configurations on your VPS server is to attach a swap space. This is a dedicated area on your hard disk (not RAM) that will be used as RAM by the system. To put it in a simpler form, we are in a way increasing the RAM of your VPS by providing some extra space from your hard disk. This way, the system gets access to more space than just 1 GB and hence you can see immense performance improvement post adding swap space.

Adding Swap Space. Courtesy: TecMint.com
Adding Swap Space. Courtesy: TecMint.com

Most Linux based VPS servers allow you to add a swap space. The size of which you can decide based on the storage you have and the applications you are running. A 2GB swap space is a bare minimum when you are running a LAMP stack as MySQL takes a lot of RAM. So adding a swap space will allow all your apps and services to run at their best performance. I’m linking to a post on how to add swap space on ubuntu.

2. Reduce Logging

The next step is to reduce the logging that is done. Most of the Linux-based 1 GB VPS servers have default logging settings which eventually create a lot of logs thus eating the RAM and storage at the same time. There are some logs that are essential like Apache, Mail Server, MySQL, etc. while there are other system-level logs like journal logs that can be tuned.

The first step to reducing logging on a 1 GB VPS server is to reduce the retention period for Apache logs. This can be done by configuring the log rotation settings in the Apache.conf file. This way we will instruct Apache to keep logs only for few days (say 3 days) post which the logs will be overwritten. You can create a cron job to copy the logs every 24 hours to a cloud location in case you want to access all logs. For beginners, this might not be required.

Clearing Journalctl logs. Courtesy: Dannyda.com
Clearing Journalctl logs. Courtesy: Dannyda.com

The next step is to clear the journal logs that are specific to the Linux VPS server. Journal logs are system-level logs where events from all the other components of the system are logged. We often don’t need to store all of them and hence we can clear the journal logs for a certain period to optimize the performance of the 1 GB VPS server. Here is a link to clear journal logs on the Linux 1 GB VPS server.

These were the two simplest performance tips for a 1 GB VPS server that you can do. Doing these will not do anything to your server in most cases. However, the next two performance tips for 1 GB VPS will affect the performance of your website/app and hence request you to take caution.

3. Tuning Apache Server

Apache server is one of the most widely used servers on the internet. It is versatile and can do a lot of tasks on its own. In fact, WordPress recommends an Apache server though it can run on NGINX as well. There are quite a few things we need to understand about Apache servers.

MPM Modules – Multi-Processing Modules: These are modules that extend the functionality of the Apache server. Based on different environments, a server admin may require different features that can be enabled by enabling/disabling the various MPM Modules. In simpler terms, if you are a blogger and use WordPress, think of MPM modules as plugins, but for the Apache Server. There are about 8 core MPM modules and many add-ons.

For this purpose, we will use the prefork module. The MPM Prefork module is where it implements a non-threaded web server. It runs multiple server processes that handle the incoming requests. There’s a parent process that manages the size of each server pool.

To put it in simple terms, think of the server as a bank with lots of counters. Each counter can process the request of customers in the queue. So more the number counters, the faster it can process the request, but it would also require a lot of floor space too. This is exactly what the MPM prefork module does.

Example of MaxRequestWorkers for MPM prefork. Courtesy: LiquidWeb.com
Example of MaxRequestWorkers for MPM prefork. Courtesy: LiquidWeb.com

There are a few directives inside the mpm_prefork.conf file which we will tweak to optimize the performance of Apache for 1 GB VPS.

  • StartServers: The number of child server processes that will be created on startup. The default is 5. No need to play with this and the default value is good enough.
  • MinSpareServers: This is the minimum number of the idle child server process that the server will run at the minimum. This number can be reduced to free up RAM. Setting this to a higher number is not good.
  • MaxSpareServers: This is the maximum number of idle child server processes that the server will run. This number has to always be greater than MinSpareServers. Setting this to a higher number is a bad idea.
  • ServerLimit: This is the upper limit on the configurable number of processes. You need to ensure that this value isn’t too high at it WILL eat a lot of RAM slowing down your system.
  • MaxClients: This setting defines how many concurrent requests can be served. Any connection request from browsers that come in after that will be queued. By default, it is 256 but some hosting companies increase it to 512 or 1024 to handle large loads. However for a 1 GB VPS server, keeping this lower helps.
  • MaxRequestsPerChild: This setting defines the limit of the number of connections that an individual child server process will handle.

Tweaking the above settings in the mpm_prefork.conf file will help you improve the performance of your website on a 1 GB VPS server. For reference, you can refer to the below values.

<IfModule mpm_prefork_module>
 StartServers        5
 MinSpareServers     2
 MaxSpareServers     10
 ServerLimit         128
 MaxClients          128
 MaxRequestsPerChild 30
</IfModule>

4. MySQL Optimization

A database is the heart of any content management system. For WordPress it is MySQL. MySQL is a memory-intensive database and running it efficiently on a 1 GB VPS server is tricky. Because both Apache and MySQL if configure incorrectly will lead to 5xx errors to the user. Though the default configurations are good for a small site, if you are handling large traffic, you need to tweak these settings to improve the performance of your website.

Configuring mysqld.conf file. Courtesy: InmotionHosting.com
Configuring mysqld.conf file. Courtesy: InmotionHosting.com

To do this you need to tweak the various settings under my.cnf file present on your server under the MySQL folder. There are a lot of buffers, threads, and connection settings that can be tweaked. Keeping these numbers too low will lead to higher processor usage while a higher number will lead to high RAM usage. Hence striking a balance is required. For this you can refer to the sample settings shared below, you would need to tweak these in mysqld.cnf file on your DigitalOcean server to get the best performance.

symbolic-links=0
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 4M
table_open_cache = 8
sort_buffer_size = 128K
read_buffer_size = 512K
read_rnd_buffer_size = 512K
net_buffer_length = 4K
thread_stack = 480K
innodb_file_per_table
max_connections=100
max_user_connections=50
wait_timeout=50
interactive_timeout=50
long_query_time=5

Power your 1 GB VPS with these optimization tips

These were the few tips I had to share on improving the performance of your 1 GB VPS server. Since I moved my blog from Siteground to DigitalOcean, there were quite a few tweaks that I had to do too. The main reason was that once I had moved, the CPU usage and RAM were always more than 80% and I couldn’t exactly figure out the reason for it. I played around with these tweaks and since then, both the CPU and RAM usage have been in the 10-20% range most of the time.

Hence, if you too are looking for some great performance enhancements from your 1 GB VPS server, follow these tips. For any queries, leave your comments below or tweet to me at @Atulmaharaj, DM me on Instagram or Get In Touch with me.

I am taking my blog to the next level with Blogchatter’s #MyFriendAlexa.

About Atulmaharaj

Maintaining the blog for the past 6 years, I'm a Foodie, Techie, Cricket Enthu, Traveler, Blogger and a Cook ! You'll find posts within a wide range of topics from food to technology. Favorite Quote: "Traveling is like reading a book, one who hasn't traveled, hasn't turned a page.

Check Also

5 Killer features of Microsoft Clarity

5 Killer features of Microsoft Clarity – a new Google Analytics competitor?

Humans have created some of the most extraordinary things in the world. From the Pyramids …

3 comments

  1. Atul ji, this seems a very highly researched data that you have put across. I am quite new to all these jargons but I am sure its very important.

Share your thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Are You Serious ?


You should not leave without signing up for our newsletter !

Get a weekly digest of all the posts from the blog delivered right to your inbox, just a click away, Sign Up Now !
PS: We hate Spam too, We promise, we'll never spam.
Name
Email address
Secure and Spam free...
%d bloggers like this: