General question you should ask to yourself
- What is your context ?
- What exactly slow down your request ? is it all ? is it only specific request ?
- 5000 Users is per seconds, minutes, day ? Do you have any pick of traffic ?
- Do you run latest version of Apache/Nginx PHP7+ and MySQL ?
- Do you use Commit flush rollback pattern with your PHP code for pushing query to MySQL ?
enable option like on PHP-fpm will help to identify
request_slowlog_timeout = 6s
slowlog = /var/log/php-fpm/slowlog-site.log
even MySQL and Nginx can keep track of slow Query. (see source for more detail)
For Apache
I recommend you to switch to nginx
, it have master / slave sub process to multithread your request.
http {
worker_processes auto; // will let Nginx manage by itself how many sub process can be spawn. more core you have more request you can take at once processor tick
}
also you should probably disable access_log
as much as you can (example for static file, it will reduce writing operation on disk).
Nginx
will act as proxy with PHP-FPM
. You should go to the Unix socket options for that.
PHP-FPM
Log: Same here, try to condensate at once your log writing operation during your request flow.
Sub process: Play with Process Manager configuration inside your php-fpm www.conf
. you should find section like
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 5
pm.max_requests = 150
which is basically, how many child PHP process can be run at the same time, how much should be always be running in idle etc. (see source for more detail)
OpCache: Be sure OpCache
is enable and configure for a long term caching.
Xdebug: On production you should disable it to reduce resource footprints.
MySQL
As said on introduction, is important to reduce number of socket traffic between PHP and MySQL, use PDO
commit / execution is a good way to reduce your internal traffic.
Use innodb
engine for your database and play around innodb
configuration to encrease available cache memory, ram.
Hope this will help to try by your hand to find the perfect configuration for your config and your context.
Source