hhxsv5 / laravel-s

LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.
MIT License
3.82k stars 470 forks source link

处理请求会有内存溢出问题 :Allowed memory size of 134217728 bytes exhausted (tried to allocate 40960 bytes) #473

Closed FlyToper closed 3 months ago

FlyToper commented 4 months ago
  1. Your software version (Screenshot of your startup)

    Software Version
    PHP 7.3.29
    Swoole 4.8
    Laravel-s 3.7
    Laravel/Lumen 6.2
  2. Detail description about this issue(error/log)

Allowed memory size of 134217728 bytes exhausted (tried to allocate 40960 bytes)

  1. Some reproducible code blocks and steps

    //伪代码:主要是静态变量查询缓存、Redis,然后就写入log日志,逻辑很简单
    GameService::getInstance()->get($arr['game_id'])
    
    Log::channel($table)->info(json_encode($arr, JSON_UNESCAPED_UNICODE));
    1. 调试代码

      worker_num = 1

      
      //在一个laravel controller 下只有如下代码

public function test(Request $request) { global $previous; $current = memory_get_usage(); $stats = [ 'prev_mem' => $previous, 'curr_mem' => $current, 'diff_mem' => $current - $previous, ]; $previous = $current; dump($stats);

return 0; }

ab 测试
>  ab -n 200 -c 1 http://127.0.0.1:5200/test

结果如下(curr_mem 一直在增长,每次 +3624):

array:3 [ "prev_mem" => 25381224 "curr_mem" => 25384848 "diff_mem" => 3624 ]

FlyToper commented 3 months ago

Laravel LogRecorder组件有问题

hhxsv5 commented 3 months ago

嗯,一般这种情况是中间件不支持常驻内存的运行模式。