How to Improve VPS Performance?
Start by finding what is holding the server back, whether that is high CPU usage, limited RAM, heavy disk activity, or an overloaded database. From there, simple changes such as enabling caching, cleaning up unnecessary processes, tuning PHP-FPM, optimizing database queries, and serving static files through a CDN can often make a noticeable difference.
Introduction
Slowness with a VPS usually happens gradually. You may have a VPS where the site loads quickly, but as time passes, the site database grows, logs and other files accumulate, and the site uses more memory. Additionally, other sites on the same server may use more memory and processing time. While a larger VPS may resolve the issue, oftentimes there are things that can be adjusted to free up memory and processing time on the VPS. f your current VPS consistently reaches its resource limits, upgrading to a suitable VPS Hosting plan can provide more CPU and memory for demanding workloads.
Before adding more memory to a VPS, it is usually a good idea to check to see how the memory is being used. There are several ways to free up memory and processing time. Background tasks can be limited. Settings in PHP and the database can be changed to minimize processing time. Disks can be cached to minimize the number of times the hard disk is read. There are other ways to minimize processing time and memory use.
8 Practical Ways to Improve VPS Performance
VPS cannot become fast just because you change some settings; first, you have to find out the issues that are making it slow. If the application is using high resources, then there are some things to check
1. Monitor CPU, RAM & Disk Usage
Before changing VPS settings, find out which resource is heavily used. Linux tools such as top and htop show active processes and CPU or memory usage. free checks RAM and swap, while df shows available disk space. iostat and vmstat show more detail about storage, CPU, and memory activity.
A short spike in usage is not always a concern. What matters more is a resource that stays heavily used over time. That pattern can point to the part of the server slowing down. Without this information, changing settings can easily fix the wrong problem.
2. Remove Unnecessary Services & Processes
Software installed on a VPS can be packed away or uninstalled, leaving behind processes and programs that are no longer needed. These include daemon processes, monitoring agents, and cron jobs. It is not uncommon to find processes that are scheduled to run excessively.
Prior to disabling a program or service, determine what its function is. Some program and service dependencies may not be obvious. Blindly removing programs and services may break other programs and services or make the server unstable.
There are necessary system processes and services. If system process resources are dominated by unnecessary processes, the system will benefit from removing them. Check system resources before and after to determine if processes or services have been removed and Domain Name System (DNS) requests have improved.
3. Enable Page, Object & PHP Caching
Caching reduces repeated work on the VPS. Page caching saves the generated output of a page, so the application does not have to build the same page again for every request. This can be especially useful for data-heavy websites and WordPress.
Object caching works at another level. Redis and Memcached keep frequently used data in memory, reducing repeated trips to the database.
PHP applications can also use OPcache to keep compiled PHP bytecode in memory. Outside the VPS, browsers and CDNs can cache static resources such as images, CSS and JavaScript.
Using the right caching layers can reduce application, database and file-serving work, leaving more resources available for requests that need to be processed.
4. Optimize PHP-FPM Worker Settings
PHP-FPM manages the worker processes that handle PHP requests. Settings such as pm.max_children, pm.start_servers, pm.min_spare_servers, and pm.max_spare_servers control how these workers are started and maintained.
The optimal number of PHP workers depends on the memory of the server, the volume of traffic, and how much RAM each PHP worker uses.
There’s no single configuration that works best for all VPS servers. There are good reasons for not copying settings for configurations from other servers. These reasons include the fact that a server may have a different workload than another. You should adjust settings based on the workload of the server you are configuring.
5. Optimize MySQL or MariaDB Queries
A site can be slow despite apparently normal CPU usage due to high database load. High database load typically manifests as slow query times. Identify your slow and/or high-volume queries with an EXPLAIN or similar command.
MySQL and MariaDB both support indexes. Like with query optimization, indexing can help find rows without scanning the entire table. Just as with query optimization, make sure indexes are removed when no longer needed.
Over time, data can become less relevant due to changes in the application or business. This can cause once-valid data to increase the cost of common operations. Determine which tables contain the most data and/or are the largest tables, and remove old and unneeded data.
6. Optimize the Web Server & Static Files
Web servers are often configured to forward common requests to application servers, which is inefficient. Common requests should be processed by web servers. For the Nginx or Apache web servers you are using, configure worker processes to handle requests using keep-alive connections, compression, and server static content. A reverse proxy can be used to handle static content.
Media files (images, CSS, JS) are requested frequently and therefore are good candidates for offloading to a CDN to reduce the load on your VPS.
Frequent, simple requests can increase the load on a VPS. Simple requests, like the thousands of requests for media files needed to render a long page, can cause the VPS to be unavailable to process requests for more complicated pages.
7. Schedule Backups & Heavy Tasks During Low Traffic
Backups and scheduled tasks are normally run separately. However, there are impacts to performance. Batch jobs can tie up resources, especially if they are processing large datasets. Large, I/O intensive jobs can impact performance.
It is normally good practice to evaluate when backups occur and compare it to when the site experiences the most load. Ideally, scheduled backups would occur during a low-load time on the site. Backup scheduling is normally prioritized, and adjusting the queue that schedules the backups may improve performance.
Evaluating the scheduled processes, or cron jobs, is a good practice. Multiple processes may be scheduled to achieve the same, or a similar, result. A good practice is to determine how long a piece of data can be considered up to date and schedule the job to process that data to ensure it is always up to date.
For a broader approach to backup scheduling, retention, and recovery, see our guide to VPS backup best practices.
8. Upgrade or Load Balance When the VPS Reaches Its Limit
Optimization has its limits. With unlimited processes and high CPU usage, this means the VPS is handling a heavy workload. In this situation, it’s recommended that you increase resources.
When a single VPS is not enough, traffic can be distributed across multiple VPS instances using load balancing. For workloads that need more flexible resource allocation as demand changes, Cloud VPS Hosting can provide a scalable environment with dedicated resources. For a web application, this will enable horizontal scaling. For the application to scale horizontally, the application and infrastructure need to be designed to distribute the workload. Horizontal scaling will not speed up an overwhelmed and overloaded database.
VPS Performance Optimization Checklist
Consider the following before increasing resources on a VPS:
- Which resource is causing the bottleneck? This can be determined by monitoring all resources. Sometimes there are processes, tasks, or services that are no longer needed. These can also be removed.
- Some applications can benefit from object caching and/or page caching. Also, there are benefits to turning on PHP OpCache.
- Indexes should be added only if it is determined through analysis that a query could benefit from it. PHP-FPM limits should be adjusted if the application demands it.
- Oversized and/or unnecessary log files should be removed, as should temporary files.
- If there are high I/O requests on the VPS and it is serving a relatively static site, that site’s assets should be loaded via a CDN.
- Resource-intensive processes should be scheduled during off-peak hours.
- If a resource constraint cannot be eliminated or accounted for, more resources can be added.
- Implement load balancing only if the application can logically be run across multiple servers.
Conclusion
Improving performance on a VPS requires deliberate changes based on the findings of an investigation. Simply changing settings will probably not result in any significant performance increases. During an investigation of resource constraints, modifications may be made to configurations of caches and/or persistent connections. Sometimes, resource constraints are completely saturated, and further modifications will not alleviate the constraint. At this point, the only option is to find a more powerful VPS. Cantech VPS Hosting offers a range of powerful VPS options to support the needs of customers’ web applications.
FAQs
How can I improve VPS performance?
Check CPU and RAM usage, and check swap and disk I/O. You may be able to cache some things, adjust PHP-FPM or database configuration, remove unnecessary processes, or add CPU and RAM when needed.
Why is my VPS running slowly?
There can be many causes behind your slow VPS. Sometimes it could be due to continuous usage of the CPU, not having enough RAM, or a lot of disk activity. It could also be bad database queries or having too many background processes.
Does caching improve VPS performance?
Yes. Features like page and object caching and PHP OPcache reduce the number of times an application and database have to be processed. Also, a CDN can be used to offload static content from the VPS.
How much RAM does a VPS need?
The amount of RAM needed depends on the OS, services, apps, and DBs. A small site probably doesn’t need a lot of RAM, but if there are a lot of users, a busy app and DB may need a lot of RAM.
Does load balancing improve VPS speed?
Load balancing allows your application to route requests to a subset of your available servers. Load balancing does not solve slow application queries. It does not remove other application-level bottlenecks.
When should I upgrade my VPS?
Apply for an upgrade when your server resources (CPUs or memory) remain constrained after you have implemented application optimizations. Other indicators may be high application server CPU or disk I/O.