调整性能nginx php-fpm mysql

我正在虚拟服务器上运行一个nginx + php-fpm + mysql,这个服务器有8个内核和16G RAM。我的应用程序是一个简单的API提供程序服务器,它根据请求返回从mysql数据库生成的JSON。 数据集很简单,只有几千字节大。 但是,每秒1000k用户的高负载。 简单的请求需要10 sekonds !!! ..这是很长的。 我认为它的MYSQL,导致缓慢的反应。 因为我有一个testing数据库 – 对testing数据库的相同请求需要1sek。 可能是我需要调整我的MySQLconfiguration,使请求更快? 我正在使用mysqli和绑定技术来产生与PHP输出,

这里是我的configuration:

/etc/nginx/nginx.conf # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes 8; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /var/run/nginx.pid; events { worker_connections 15000; 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 0; keepalive_timeout 100; #gzip on; # Load config files from the /etc/nginx/conf.d directory # The default server is in conf.d/default.conf include /etc/nginx/conf.d/*.conf; } 

/etc/my.cnf中

 [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used (fedora >= 15). # If you need to run mysqld under a different user or group, # customize your systemd unit file for mysqld according to the # instructions in http://fedoraproject.org/wiki/Systemd user=mysql # Semisynchronous Replication # http://dev.mysql.com/doc/refman/5.5/en/replication-semisync.html # uncomment next line on MASTER ;plugin-load=rpl_semi_sync_master=semisync_master.so # uncomment next line on SLAVE ;plugin-load=rpl_semi_sync_slave=semisync_slave.so # Others options for Semisynchronous Replication ;rpl_semi_sync_master_enabled=1 ;rpl_semi_sync_master_timeout=10 ;rpl_semi_sync_slave_enabled=1 # http://dev.mysql.com/doc/refman/5.5/en/performance-schema.html ;performance_schema [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid 

最有可能的罪魁祸首是您的数据库查询和索引使用不足。

你应该用MySQL EXPLAIN特性检查你的SQL查询,这样你就可以看到结果是如何产生的。

如果数据库索引没有任何改进,那么您需要考虑使用PHP或Memcache来实现现成数据集的caching。

我认为这是一个I / O问题。我解决了这个问题,在不同的目录中创build了许多相同的get.php文件,并随机地将请求redirect到他们,就像循环一样。 它改善了这种情况。

问候