php-pm / php-pm-httpkernel

HttpKernel adapter for use of Symfony and Laravel frameworks with PHP-PM
MIT License
246 stars 72 forks source link

Memory Leaking #106

Closed aftabnaveed closed 6 years ago

aftabnaveed commented 6 years ago

I have setup new Laravel application without any additional packages or service providers it seems like to be leaking memory on each request. I tried to collect some info using meminfo but that too is not able to provide relevant info:

Memory Leaks:

                                                                                                                      │ime (ms)
--- Worker 5501 stderr ---                                                                                             │  50%     24
11546560                                                                                                               │  66%     34
[24/May/2018:16:38:45 +0000] 172.19.0.9 - - "GET /catalog/product/view/id/34072 HTTP/1.0" 200 347109 "-"               │  75%     50
13175728                                                                                                               │  80%   1380
[24/May/2018:16:39:17 +0000] 172.19.0.9 - - "GET /catalog/product/view/id/34072 HTTP/1.0" 200 346935 "-"               │  90%   2856
14878304                                                                                                               │  95%  11978
[24/May/2018:16:42:07 +0000] 172.19.0.9 - - "GET /catalog/product/view/id/34072 HTTP/1.0" 200 346911 "-"               │  98%  17847
16796656                                                                                                               │  99%  22491
[24/May/2018:16:42:37 +0000] 172.19.0.9 - - "GET /catalog/product/view/id/34072 HTTP/1.0" 200 346889 "-"               │ 100%  30584 (longest request)

With each request it is adding around 2MB of memory and not releasing it. I generated the meminfo and it is reporting all well, here is the summary:

+---------+-----------------+-----------------------------+
| Type    | Instances Count | Cumulated Self Size (bytes) |
+---------+-----------------+-----------------------------+
| string  | 160             | 5788                        |
| boolean | 44              | 704                         |
| array   | 9               | 648                         |
| integer | 1               | 16                          |
| float   | 1               | 16                          |
+---------+-----------------+-----------------------------+

I dumped the above summary inside PHPPM\Bootstrap\Laravel@postHandle method meminfo_dump(fopen('/tmp/my_dump_file.json', 'w')); I do not see any objects listed there which sounds strange to me unless I am misinterpretting it :(

aftabnaveed commented 6 years ago

Ok I am able to fix the meminfo dump for my objects and here is the result for 2 requests.

First/Initial Request:

+------------------------------------------------------------+-----------------+-----------------------------+
| Type                                                       | Instances Count | Cumulated Self Size (bytes) |
+------------------------------------------------------------+-----------------+-----------------------------+
| array                                                      | 1444            | 103968                      |
| string                                                     | 1222            | 127053                      |
| boolean                                                    | 328             | 5248                        |
| null                                                       | 160             | 2560                        |
| Closure                                                    | 118             | 8496                        |
| integer                                                    | 105             | 1680                        |
| Illuminate\Foundation\Application                          | 51              | 3672                        |
| float                                                      | 34              | 544                         |
| unknown                                                    | 31              | 496                         |
| resource                                                   | 18              | 288                         |
| React\Socket\Connection                                    | 10              | 720                         |
| React\Stream\DuplexResourceStream                          | 10              | 720                         |
| React\EventLoop\StreamSelectLoop                           | 9               | 648                         |
| Illuminate\Routing\Router                                  | 9               | 648                         |
| Illuminate\Http\Request                                    | 8               | 576                         |
| Symfony\Component\VarDumper\Dumper\CliDumper               | 8               | 576                         |
| Illuminate\Events\Dispatcher                               | 8               | 576                         |
| React\Http\Io\MiddlewareRunner                             | 7               | 504                         |
| Illuminate\Routing\Route                                   | 7               | 504                         |
| DebugBar\DataFormatter\DataFormatter                       | 6               | 432                         |
| Illuminate\Session\SessionManager                          | 6               | 432                         |
| PHPPM\ProcessSlave                                         | 6               | 432                         |
| React\Http\Io\HttpBodyStream                               | 6               | 432                         |
| React\Http\Io\ServerRequest                                | 6               | 432                         |
| Illuminate\Filesystem\Filesystem                           | 6               | 432                         |
| React\Http\Io\CloseProtectionStream                        | 5               | 360                         |
| React\Http\StreamingServer                                 | 4               | 288                         |
| Illuminate\Session\Store                                   | 4               | 288                         |
| Symfony\Component\HttpFoundation\ParameterBag              | 4               | 288                         |
| PHPPM\Bootstraps\Laravel                                   | 4               | 288                         |
| Symfony\Component\VarDumper\Cloner\VarCloner               | 4               | 288                         |
| Illuminate\Http\Response                                   | 3               | 216                         |
| RingCentral\Psr7\Uri                                       | 3               | 216                         |
| Barryvdh\Debugbar\LaravelDebugbar                          | 3               | 216                         |
| Illuminate\Hashing\HashManager                             | 3               | 216                         |
| App\Http\Kernel                                            | 3               | 216                         |
| Illuminate\Auth\AuthManager                                | 3               | 216                         |
| RingCentral\Psr7\BufferStream                              | 3               | 216                         |
| Illuminate\Auth\AuthServiceProvider                        | 3               | 216                         |
| Illuminate\Foundation\Providers\FormRequestServiceProvider | 3               | 216                         |
| Illuminate\Routing\RouteCollection                         | 3               | 216                         |
| Illuminate\Database\Connectors\ConnectionFactory           | 3               | 216                         |
| Barryvdh\Debugbar\ServiceProvider                          | 2               | 144                         |
| Illuminate\Queue\QueueManager                              | 2               | 144                         |
| Illuminate\Queue\QueueServiceProvider                      | 2               | 144                         |
| Illuminate\Cookie\CookieJar                                | 2               | 144                         |
| Illuminate\Auth\EloquentUserProvider                       | 2               | 144                         |
| Barryvdh\Debugbar\SymfonyHttpDriver                        | 2               | 144                         |
| Illuminate\Cookie\CookieServiceProvider                    | 2               | 144                         |
[0] 0:bashM 1:docker- 2:[tmux]*                                                                                      

Second Run/Request:

+------------------------------------------------------------+-----------------+-----------------------------+
| Type                                                       | Instances Count | Cumulated Self Size (bytes) |
+------------------------------------------------------------+-----------------+-----------------------------+
| array                                                      | 2131            | 153432                      |
| string                                                     | 1387            | 208403                      |
| boolean                                                    | 382             | 6112                        |
| null                                                       | 205             | 3280                        |
| integer                                                    | 149             | 2384                        |
| Closure                                                    | 137             | 9864                        |
| float                                                      | 62              | 992                         |
| Illuminate\Foundation\Application                          | 59              | 4248                        |
| unknown                                                    | 33              | 528                         |
| Illuminate\Routing\Route                                   | 32              | 2304                        |
| resource                                                   | 23              | 368                         |
| React\Http\Io\ServerRequest                                | 18              | 1296                        |
| Symfony\Component\VarDumper\Dumper\CliDumper               | 14              | 1008                        |
| Illuminate\Routing\Router                                  | 13              | 936                         |
| DebugBar\DataFormatter\DataFormatter                       | 12              | 864                         |
| React\Stream\DuplexResourceStream                          | 10              | 720                         |
| React\EventLoop\StreamSelectLoop                           | 10              | 720                         |
| Illuminate\Http\Request                                    | 9               | 648                         |
| Illuminate\Session\SessionManager                          | 9               | 648                         |
| Illuminate\Events\Dispatcher                               | 9               | 648                         |
| Illuminate\Filesystem\Filesystem                           | 9               | 648                         |
| React\Http\Io\MiddlewareRunner                             | 9               | 648                         |
| React\Socket\Connection                                    | 8               | 576                         |
| Symfony\Component\HttpFoundation\ParameterBag              | 8               | 576                         |
| Symfony\Component\VarDumper\Cloner\VarCloner               | 7               | 504                         |
| PHPPM\ProcessSlave                                         | 6               | 432                         |
| Illuminate\Session\Store                                   | 6               | 432                         |
| React\Http\Io\HttpBodyStream                               | 6               | 432                         |
| Barryvdh\Debugbar\LaravelDebugbar                          | 5               | 360                         |
| Illuminate\Http\Response                                   | 5               | 360                         |
| React\Http\Io\CloseProtectionStream                        | 5               | 360                         |
| Barryvdh\Debugbar\DataCollector\GateCollector              | 4               | 288                         |
| Barryvdh\Debugbar\DataFormatter\SimpleFormatter            | 4               | 288                         |
| RingCentral\Psr7\Uri                                       | 4               | 288                         |
| Illuminate\Auth\AuthServiceProvider                        | 4               | 288                         |
| Symfony\Component\HttpFoundation\Cookie                    | 4               | 288                         |
| RingCentral\Psr7\BufferStream                              | 4               | 288                         |
| DebugBar\DataFormatter\DebugBarVarDumper                   | 4               | 288                         |
| Swift_Plugins_MessageLogger                                | 4               | 288                         |
| React\EventLoop\Timer\Timer                                | 3               | 216                         |
| Illuminate\Auth\AuthManager                                | 3               | 216                         |
| Illuminate\Hashing\HashManager                             | 3               | 216                         |
| Barryvdh\Debugbar\SymfonyHttpDriver                        | 3               | 216                         |
| Illuminate\Cookie\CookieServiceProvider                    | 3               | 216                         |

I see the instances count for some of the objects in 2nd request has increased which means the previous objects were not cleared properly.

BTW This is the PHP extension I used to get memory info of my objects: https://github.com/mathieuk/php-meminfo/tree/bugfix/use_correct_symbol_table_php71

andig commented 6 years ago

Closing this one as duplicate.