Search code examples
mysqllinuxapacheserverweb-performance

Linux web server configuration for AJAX web page highly consumed CPU


I have www service with chat used for many users at same time based on AJAX which consumes a lot of CPU resources and needs many database connections. I’m asking about server configuration for such scenario for Debian 9 with MariaDB and Apache and PHP 5.6 (7.x not working with my service). I increased parameter Maximum No. of Connections (max_used_connections in my.cnf) to 2000: max_connections = 2000 to avoid database error. Which also parameter should I change to increase productivity of my server and decrease chat delay?

I have made tests: simultaneously I opened 200 chat window on one browser (Chrome 76.0.3809.100) and I have see about 60 second delay (it shoud be 1 second due to php code) and I have observe that my server have only 21 web processes. How I can improve in server configuration?

Below is output for command "ps aux" from server console, which I use to see CPU usage for processes

USER    PID %CPU    %MEM    VSZ RSS TTY STAT    START   TIME    COMMAND    
postfix 21107   0   0   83704   6816    ?   S   22:12   00:00   pickup    
root    25493   0   0   0   0   ?   I   22:58   00:00   [kworker/u16:1-e]    
root    26082   0   0   0   0   ?   I   21:46   00:00   [kworker/6:0-eve]    
root    26094   0   0   0   0   ?   I   21:46   00:00   [kworker/7:2-cgr]    
root    26253   0   0   0   0   ?   I   21:47   00:00   [kworker/4:1-eve]    
root    26417   0   0   0   0   ?   I   21:47   00:00   [kworker/2:0-eve]    
www-data    26580   0   0   519484  10732   ?   S   21:48   00:00   php-fpm:    
www-data    26581   0   0   519484  10732   ?   S   21:48   00:00   php-fpm:    
root    26585   0   0   0   0   ?   I   21:48   00:00   [kworker/1:0-eve]    
root    27185   0   0   0   0   ?   I   21:51   00:00   [kworker/0:1-eve]
root    28031   0   0   0   0   ?   I   23:00   00:00   [kworker/2:2-eve]    
postfix 30240   0   0   83704   6800    ?   S   23:00   00:00   anvil    
root    1029    0,1 0   658632  18944   ?   Sl  20:32   00:09   /usr/bin/python3    
clamav  734 0,2 2,4 1008592 787196  ?   Ssl 20:32   00:25   /usr/sbin/clamd    
www-data    9793    3,8 0,3 605264  114312  ?   S   22:05   02:22   /usr/sbin/apache2    
www-data    10709   3,9 0,3 853140  120500  ?   S   22:06   02:25   /usr/sbin/apache2    
www-data    10668   4,3 0,3 597996  104668  ?   S   22:06   02:40   /usr/sbin/apache2    
www-data    9883    4,5 0,3 597060  105312  ?   S   22:05   02:47   /usr/sbin/apache2    
www-data    9791    4,6 0,3 604864  115324  ?   R   22:05   02:52   /usr/sbin/apache2    
www-data    9792    5,1 0,3 598828  108416  ?   S   22:05   03:07   /usr/sbin/apache2    
www-data    10073   5,4 0,3 599192  105860  ?   S   22:05   03:18   /usr/sbin/apache2    
www-data    10363   5,6 0,3 844492  113288  ?   S   22:06   03:25   /usr/sbin/apache    
www-data    9794    5,8 0,3 851780  120412  ?   S   22:05   03:34   /usr/sbin/apache2    
www-data    9795    6   0,3 599708  108424  ?   S   22:05   03:42   /usr/sbin/apache2    
www-data    9822    6,1 0,3 602568  109008  ?   S   22:05   03:45   /usr/sbin/apache2    
www-data    10710   6,3 0,3 598836  105540  ?   S   22:06   03:52   /usr/sbin/apache2    
www-data    27116   7,2 0,3 608036  114096  ?   S   22:44   01:37   /usr/sbin/apache2    
mysql   946 9   0,6 958820  221472  ?   Ssl 20:32   14:01   /usr/sbin/mysqld    
www-data    27013   9,5 0,3 598352  104688  ?   S   22:44   02:08   /usr/sbin/apache2    
www-data    27119   10,5    0,3 602800  110460  ?   S   22:44   02:21   /usr/sbin/apache2    
www-data    27054   10,6    0,3 596540  104216  ?   S   22:44   02:23   /usr/sbin/apache2    
www-data    27117   10,8    0,3 596612  103268  ?   S   22:44   02:25   /usr/sbin/apache2

Solution

  • Your environment can be enhanced by the following:

    • Check server's hardware and make sure about the requirements for RAM and CPU.
    • Use Mysqltuner script to tune database engine performance.
    • Check your queries and try to enhance them.
    • Install cache modules on Apache like: memcached and apcu.
    • Use PHP-FPM as it's recommended for better performance.

    And then you need to make benchmark test to check if hardware specifications and configurations is suitable for your environment or not.

    There are many tools for benchmark test like: ab - Apache HTTP benchmarking Tool, or any other online tools.