Opcache makes no difference at all

Ubuntu 20.04
Virtualmin version 6.16

I made some tests to compare the execution time of php scripts with and without opcache. I ran a php script that calculates the the prime numbers 1-500,000. In both cases regardless opcache was enabled or not, the execution time ranged 0.9-1.05 seconds.

I monitored the status of opcache with this script:
GitHub - amnuts/opcache-gui: A clean, effective and responsive interface for Zend OPcache - version 3.2.1

When opcache was enabled the status clealy showed as ‘cached’:
/home/xxx/public_html/prime2.php hits: 4, memory: 2.92KB, last used: Tue Jun 15 17:32:08 2021

When opcache was disabled,l added to the blacklist
and showed up in the ‘ignored file locations’:

Every time when enabled / disabled opcache, made a system reboot as well.
So it apparaently makes no difference if opcash is on or off…

Did anybody experience the same?

I think I would be more surprised if there was a difference. A tiny app running under php-fpm or mod_fcgi is unlikely to benefit notably from the opcache.

Yes that point makes sense. A single instance of one script makes no difference.
I installed ApacheJmeter. I was running 300 threads at once.
The result was even more surprising:
With opcache the average execution time was found to be 18.3 sec
Without opcache the average execution time was only 17.6 sec.

Is there any logical explanation for this?

It’s the same explanation I already gave. You didn’t change the thing that I mentioned would make a difference (tiny app). But, I think you’re expecting a much bigger difference than you’ll actually see, even in the ideal circumstance for using opcache. Everything is already cached at several points in the system. FPM or fcgid are already going to run very fast, relatively speaking. PHP 7 also dramatically improved performance in the general case, including parsing and compiling (making the improvement from op caching less pronounced).

1 Like

You mean even if a file is on Opcache ‘blacklist’ , it can still be cashed somewhere else in the OS?

It’s caches all the way down, friend.

I see.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.