Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is each php-fpm pool having their own memory pool?

Tags:

php

opcache

Let say I am using the PHP 5.5 opcode cache, and set

opcache.memory_consumption=128

, if I have 4 pools in php-fpm, will each of the 4 pool share 128MB of cache, or will they own 128M opcache for each pool?

like image 852
Ryan Avatar asked Dec 13 '13 15:12

Ryan


2 Answers

If you have any doubts about how cache memory used between pools make a simple test.

Technique is quite simple. Create 2 fpm-pools on different www-dir listening for example 8081 and 8082 ports and 2 files index.php and check.php with identical content:

<?php
echo "<pre>\n";
var_dump(opcache_get_status());

Firstly restart your php-fpm service, then run first pool localhost:8081/index.php, then localhost:8082/check.php. After this check ["scripts"] section in output. I've got next results:

localhost:8081/index.php

["scripts"]=>
  array(1) {
    ["/usr/share/nginx/html/index.php"]=>
    array(6) {
      ["full_path"]=>
      string(31) "/usr/share/nginx/html/index.php"
      ["hits"]=>
      int(0)
      ["memory_consumption"]=>
      int(1032)
      ["last_used"]=>
      string(24) "Mon Dec 23 23:38:35 2013"
      ["last_used_timestamp"]=>
      int(1387827515)
      ["timestamp"]=>
      int(1387825100)
    }
  }

localhost:8082/check.php

["scripts"]=>
  array(2) {
    ["/usr/share/nginx/html1/check.php"]=>
    array(6) {
      ["full_path"]=>
      string(32) "/usr/share/nginx/html1/check.php"
      ["hits"]=>
      int(0)
      ["memory_consumption"]=>
      int(1056)
      ["last_used"]=>
      string(24) "Mon Dec 23 23:38:47 2013"
      ["last_used_timestamp"]=>
      int(1387827527)
      ["timestamp"]=>
      int(1387825174)
    }
    ["/usr/share/nginx/html/index.php"]=>
    array(6) {
      ["full_path"]=>
      string(31) "/usr/share/nginx/html/index.php"
      ["hits"]=>
      int(0)
      ["memory_consumption"]=>
      int(1032)
      ["last_used"]=>
      string(24) "Mon Dec 23 23:38:35 2013"
      ["last_used_timestamp"]=>
      int(1387827515)
      ["timestamp"]=>
      int(1387825100)
    }
  }

As you see second pool already has index.php in cache, so answer is all 4 pools will share 128MB of cache.

like image 186
Alexander Yancharuk Avatar answered Nov 06 '22 12:11

Alexander Yancharuk


As mentioned by raina77ow through link that 128 MB will be shared betweeen 4 Pools

Adding to that, as mentioned in official documentation

; Sets how much memory to use
opcache.memory_consumption=128

opcache.memory_consumption sets the memory limit that will be used no matter how many pools you use, it will get shared accordingly.

like image 20
Abhishek Goel Avatar answered Nov 06 '22 13:11

Abhishek Goel