phpnginxpagespeed-insightsopcache

PHP-FPM slows down after a while - Opcache File Cache


My set up is a large drupal website with 50,000 requests per day. My main issue is that Php-fpm slows down after 10-15 minutes of a restart (1500+ code files). Cache is only full 40% (174mb of 512mb). Initial server response time is over 700ms but goes down to 170ms for first few minutes of a restart as per Google site speed testing.

I found this answer with similar issue and have added Opcache file cache with some improvement. https://forums.cpanel.net/threads/php-fpm-restart-necessary-for-site-speed.650549/#post-2654105

Current Opcache Settings

 [opcache]
    opcache.enable=1
    opcache.memory_consumption=512
    opcache.interned_strings_buffer=64
    opcache.max_accelerated_files=50000
    opcache.max_wasted_percentage=15
    opcache.validate_timestamps=0
    opcache.revalidate_freq=0
    opcache.mmap_base=0x20000000
    opcache.file_cache='var/www/cache'
    opcache.file_cache_fallback=1

Any other ideas on how to optimise the above to achieve consistent php-fpm performance. (Set up is Php-fpm 7.2, Nginx, Drupal, Mariadb on AWS server with 64G memory)

Tried adding File cache. It has shaved off 100ms but probably a lot more can be done.


Solution

  • After months of trial and error, I think I have found the issue and it's solved now.

    It was quite unrelated to Opcache. The real issue was that I had pm.max_requestsset to handle 5000 requests which was causing memory leaks.

    Changed it to 200 requests and increased pm.max_children other values.

    This way each child gets respawned after 200 requests and any slow processes don't linger on. I was running Cron every 15 minutes which was particularly problematic in terms of memory leak.