Question

Slow loading website sometimes

Posted October 30, 2015 7k views
PHPServer OptimizationDigitalOceanScalingConfiguration ManagementLoad BalancingHigh Availability

Hello everyone,

I’m having issues with my website loading slow at times. I’ve set up my droplet using Vesta (Ubuntu 14) and the script I’m running uses absolutely no MySQL connections. I’ve setup Monit which notifies me anytime my website load goes over the threshold and seems to work just fine most times, but I’ve done random checks and found a simple PHP page (the only external connection is google adsense) can take a few seconds to load at times.

Looking at the graphs in my control panel I see nothing out of the ordinary besides a few random disk and bandwidth spikes that do not correlate well with when I actually have this issue. Over the past 7 days the largest CPU spike I’ve had was 40%. I’m on the $10 droplet (1 GB ram etc).

Simply rebooting the server from the command line seems to fix the problem. Can anyone help me diagnose whats going on and how I can prevent this from happening?

2 comments
  • A common issue with apache is it’s keep-alive settings. If the keep-alive timeout is too high then anytime all the available connections are used they may stay open until the timeout waiting for new requests. When this happens a new connection may have to wait for one of the listeners to time out from it’s last connection before it will respond. Normally I would be able to assist you with modifying your apache configuration for this but as your configuration is managed by Vesta I would recommend reaching out to that project’s community to see what the best practice for making this type of change is. Many control panels install their own versions of the software they use rather than the distribution’s version and some will also overwrite configuration files from their own settings so changes may not be kept.

    Another thing that will reduce your load if this is the only site you are running would be to shut down the unused MySQL service. Even without any connections, MySQL will reserve a good deal of RAM for itself.

  • Hello,

    Thank you, I’ll post on the vesta’s forum! I do want to ask though if you can give me a guide on how to disable the MySQL service.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

This question was answered by @ryanpq:

A common issue with apache is it’s keep-alive settings. If the keep-alive timeout is too high then anytime all the available connections are used they may stay open until the timeout waiting for new requests. When this happens a new connection may have to wait for one of the listeners to time out from it’s last connection before it will respond. Normally I would be able to assist you with modifying your apache configuration for this but as your configuration is managed by Vesta I would recommend reaching out to that project’s community to see what the best practice for making this type of change is. Many control panels install their own versions of the software they use rather than the distribution’s version and some will also overwrite configuration files from their own settings so changes may not be kept.

Another thing that will reduce your load if this is the only site you are running would be to shut down the unused MySQL service. Even without any connections, MySQL will reserve a good deal of RAM for itself.

View the original comment

Hello,

I’m just posting the typical issues/resolutions to such cases. They are almost every time connected with two things - Website Optimization and Server/Droplet Optimization.

Let’s start with Server Optimization.

When looking at Server/Droplet Optimization, there are a few necessary services/packages that are universal.

  • The first one would be Server-side caching. Server cache is an umbrella term covering a number of different types of caching. This includes Content Delivery Network (CDN) caching, object caching, and opcode caching. Depending on what you want to achieve you might need one or the other. Usually, though, you can have all 3 types of caching as it shouldn’t interfere with your Website/App. I won’t go into more details about what each caching does as this post will become 3 pages long. There are multiple documents providing services/packages for each of the server-type caching.

  • Next would be using PHP-FPM (if your Website is using PHP of course). PHP-FPM is an efficient method on how to minimize the memory consumption and rise the performance for the Websites with heavy traffic. It is significantly faster than traditional CGI-based methods in multi-user PHP environments.

  • Another solution would be Database Caching. A database cache supplements your primary database by removing unnecessary pressure on it, typically in the form of frequently accessed read data. The cache itself can live in a number of areas including your database, application or as a standalone layer. Usually, for this kind of caching is being used Redis.

  • Apache NPM modules. If you are using Apache, you are using one of three NPM modules. Most certainly if you haven’t configured anything on it and have used the default configuration, you are using NPMPrefrok which is the most outdated one and thus the slower. I’ll recommend using one of the other two - NPMWorker and NPM_Event depending on your situation. Again, I would urge you to read more about these 3 and what is applied in which case.

Those were the basic optimizations on a server level, let’s start with your Website/App

If you are using a CMS like WordPress, Magento, Joomla, Opencart or anything of the same matter, there will be plugins/addons. These addons can be very powerful if used correctly. The most helpful plugins are:

  • Caching Plugins
  • Image Optimization Plugins
  • Plugins that reduce redirections/requests
  • Plugins that reduce the size of JS and CSS files.

If you are not using a CMS, you’ll need to try and do what these plugins are doing manually.

Usually, Websites/Apps are slow because of a couple of reasons which range from too many requests or big images to a bunch of unnecessarily big JS or CSS files. Optimizing these whether you are using a Plugin or doing it manually is enough.

I hope this was helpful.

Regards,
KFSys