0

I have a active site built in Codeigniter on ngnix server with medium traffic. Occasionally the server cpu usage becomes very high and site crashes. After running top it looks like mysql is causing large cpu usage. Queries lacks slight optimizations but can that cause this problem of high cpu usage? Or is it due to other configuration problems?

server details

MemTotal: 263861736 kB

6 core cpu

nginx version 1.10.3

nginx conf

    user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
    multi_accept        on;
    use                 epoll;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;

    gzip  on;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";

        gzip_min_length 1000;
        gzip_buffers 4 32k;
        gzip_proxied any;
        gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;

    open_file_cache          max=5000  inactive=20s;
    open_file_cache_valid    30s;
    open_file_cache_min_uses 5;
    open_file_cache_errors   on;

    include /etc/nginx/conf.d/*.conf;
server_tokens off;
}

php fpm conf

[www]

user = nginx
group = nginx

pm = ondemand
pm.max_children = 100
pm.start_servers = 35
pm.min_spare_servers = 25
pm.max_spare_servers = 50
pm.process_idle_timeout = 10s;

php-fpm error log

[25-Jun-2019 20:16:02] NOTICE: fpm is running, pid 1869
[25-Jun-2019 20:16:02] NOTICE: ready to handle connections
[25-Jun-2019 20:16:02] NOTICE: systemd monitor interval set to 10000ms
[25-Jun-2019 20:16:21] WARNING: [pool www] server reached max_children setting (100), 

consider raising it
[25-Jun-2019 20:17:19] NOTICE: Terminating ...
[25-Jun-2019 20:17:19] NOTICE: exiting, bye-bye!
[25-Jun-2019 20:19:46] WARNING: [pool www] ACL set, listen.owner = 'nginx' is ignored
[25-Jun-2019 20:19:46] WARNING: [pool www] ACL set, listen.group = 'nginx' is ignored

top screenshot top scrrenshot

  • FPM reaches the limit of children, did you "consider rising it"? Why don't you add some fresh repo from nginx.org and install a newer one? Before optimizing queries did you optimize mysql configuration? Does your tables have indexes? You didn't provide enough details in order to get better help, and this question will hardly be useful for anyone else. Voting to close as too broad. – Marco Jun 25 at 19:50
  • High CPU in MySQL almost always indicates a missing INDEX (especially a composite index) or a poorly formulated query. Did you happen to grab SHOW FULL PROCESSLIST at the time of the problem? – Rick James Jun 25 at 23:10
  • @Marco will try to install a newer nginx. How to optimize mysql configuration? All the table have indexes. @RickJames never thought about SHOW FULL PROCESSLIST. I will try that. – user7408587 Jun 26 at 3:54
  • And you have 298 Sleeping processes for WHAT reason? – Wilson Hauck Jul 5 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.