How to find Optimal Opcache Memory Size?

48 views Asked by At

I have been experimenting with Opcache optimal memory size and would like some tips/help in setting up optimal memory size.

I have tried 3 scenarios:

1) 2Gb Memory, 128 MB interned strings, 3000 Files

Settings

opcache.memory_consumption=2048
opcache.interned_strings_buffer=128
opcache.max_accelerated_files=3000

Opcache results

total memory: 2.00GB
used memory: 303.15MB
free memory: 1.70GB
number of cached files: 1,087
interned strings usage
buffer size: 128.00MB
used memory: 3.44MB
free memory: 124.70MB
number of strings: 65,542
Hit rate: 100%

2) 2Gb Memory, 512 MB interned strings, 3000 Files

Settings

opcache.memory_consumption=2048
opcache.interned_strings_buffer=512
opcache.max_accelerated_files=3000

Opcache results

total memory: 2.00GB
used memory: 1.09GB
free memory: 930.03MB
number of cached files: 1,087
interned strings usage
buffer size: 128.00MB
used memory: 3.44MB
free memory: 508.56MB
number of strings: 65,542
Hit rate: 100%

3) 2Gb Memory, 128 MB interned strings, 30,000 Files

Settings

opcache.memory_consumption=2048
opcache.interned_strings_buffer=128
opcache.max_accelerated_files=30000

Opcache results

total memory: 2.00GB
used memory: 97.08MB
free memory: 1.9GB
number of cached files: 1,087
interned strings usage
buffer size: 128.00MB
used memory: 3.44MB
free memory: 124.70MB
number of strings: 65,542
Hit rate: 100%

Other Settings:

opcache.enable=1
opcache.validate_timestamps=0
opcache.max_file_size=10M
opcache.enable_cli=1

Total files in the application 2800, size on disk 90MB. PHP 7.2 FPM with Nginx.

I have following questions:

  1. Optimal Total Cache Size - There is 100% hit rate in all 3 scenarios. If RAM is not an issue, what's the optimal Opcache size in this scenario? It appears Opcache takes up more memory when allocated more. In scenario 3, while Opcache seems to have 100% hit rate, it slows down gradually until PHP is restarted. No slow down issue with other 2 scenarios.

  2. Optimal Interned Strings Size - While they only take up 3-4 MB, increasing their size massively increase total Opcache footprint. Why is that?

  3. Total Files - Increasing total files has a massive impact on memory used. It appears Opcache allocates memory for files it expects to have. No brainer here - it was a configuration mistake which somehow seems to have a lot more impact in PHP 7 vs PHP 5.

Appreciate any community advice please!

0

There are 0 answers