I wanted to share the method I use to find bits of code which slow WPBay down, which was really useful on the long term, I start to see page load speed increased and things moving faster.
So, what helped the most was enabling the PHP-FPM slow log. I set request_slowlog_timeout and enabled slowlog, then restarted PHP-FPM. Every time a request took longer than the configured threshold (15 seconds for example, but you can also lower this if needed), PHP dumps a stack trace showing exactly in what file and which function it is spending time.
To set it up, find your PHP-FPM pool configuration file (usually in your PHP-FPM config directory) and add:
request_slowlog_timeout = 5s
slowlog = /var/log/php-fpm-slow.log
Restart PHP-FPM after making the change.
Then open another terminal and watch the log:
tail -f /var/log/php-fpm-slow.log
That was way more useful than staring at code all day. I also checked the PHP-FPM logs and noticed messages about workers being busy and hitting pm.max_children.
Iām still using this method, checking logs daily. Now I started seeing regular code appearing, in cases when the site is hammered by scanner bots, trying to hack or scan it for vulnerabilities. Next step probably is banning access of these bots in some way, but getting here is already nice, as code should be mostly ok by now.
I hope this will help somebody.