Bottlenecks of a Web ServerDaniel FiottBlockedUnblockFollowFollowingJan 29If you have issues with server response time (SRT), which is the time it takes for the browser to receive the response, here are some tips that can be used to optimize your web application.
First of all we need to make sure that we fully understand how a web application stack works.
There are multiple web applications that can be described and in this case I will demonstrate how a PHP based application stack works.
Here’s an image of how a simple PHP web application architecture would operate.
To understand exactly what’s making your server app slow, you can use tools that are integrated in your browser.
Each browser has it’s own tools to monitor http request and response times.
In chrome you would use CRTL+SHIFT+I to inspect the page choosing the network tab.
Bottlenecks Frequently encounteredProcessing timeFirst of all check that the server has enough processing power meaning CPU and memory.
If it’s good from a server perspective check whether the service (in this case it’s PHP) is able to create a fork of the process (another instance of the process) and the amount of forks it is able to create.
The link below will help you to identify issues the child processes created by the fork.
be/en/support/faq/determining-the-correct-number-of-child-processes-for-php-fpm-on-nginxDatabase query timeWhen it comes to big databases or non optimized databases the query response might have a longer response time which will make the whole request much slower.
There are multiple solutions that can make query response faster.
In this example I am using MySQL.
– Increasing innodb size.
(memory allocated to the database)- Creating index for large tables.
Network response timeThe only configuration that can be done to a server would be to change the “keep alive connection” which is a parameter that can be set to keep connections alive for a certain amount of time.
This kind of setting might resolve in an error, so always test the configuration before and after the deployment.
Having this setting should also help with DDOS.
But for low traffic servers this should not be an issue as a normal server should be able to handle a quite substantial amount of requests.
Other solutions to speed up HTTP response timeServer CacheA more popular solution of serving HTTP requests is to apply cache which gives a rendered(static) version of the application.
In my opinion this should not be the first approach to solve application response time, because a cache needs to be cleared every time changes are implemented.
There are a few solutions when you apply a cache on an existing server:If you are using a well known CMS there are quite a few plugins that can be used for caching.
If you want to apply a cache from the server side, you can use a couple of services that offer service such caching like memcache, varnish and also fastcgi cache.
Database Query CacheIf you are using MySQL there’s a feature that can be enabled to allow query caching.
Query cache settings would need to be adjusted to the amount of queries and the queries response size.
A good reason why Database query cache should be applied before server caching is due to the process of how the query caching works.
MySQL query caching acts like a buffer, which stores the most frequent and non modified responses so you can still have content updates and changes without any effect.
Here is a good document that I recommend for you to check out.
Optimize MySQL query_cache_sizeThe MySQL query_cache_size is an in memory caches that stores the complete result sets of frequent SELECT queries…techinfobest.