dro44817 2018-11-29 03:34
浏览 114

PHP:使用带内存的Pthread池的问题

I have big Problem my server's 16Gb RAM

$scan_pol = new \Pool(2000);
$range = ip_range($start_range, $last_range);
foreach ($range as $ip_num => $ip_value) {
    $scan_pol->submit(new scan($ip_value));
}

I submit in $scan_pol 16581375 Task

unset($range);
while ($scan_pol->collect()); // here i want to edit
$scan_pol->shutdown();

and while I see the Performance in Task Manager the memory usage Excessively increasing to full and popup this error snapshot

then stop CLI
I want while collect Tasks delete task from memory to balance memory usage

NOTE: I changed Pool Threads 2000 to 1000
and tried to Reduce $range Array To reduce the pressure on the RAM but same problem

because collect after Terminated Task don't unset it from memory

Any help please

Thank You

  • 写回答

1条回答 默认 最新

  • doujuxin7392 2018-11-29 04:07
    关注

    You can implement your ip_range function as a generator instead of an iterator, which will save you a lot of memory overhead. look here:http://php.net/manual/en/language.generators.overview.php

    It can be used directly in a foreach loop without assigning a value to a variable.

    Then, please set the size of your pool according to your memory size.

    I hope this will help you.

    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败