Home
Download
Document
Forum
Video
Donate
Source Code
AI 助理
Sponsors
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
Products
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
Login
Register
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
swoole使用自定义进程后 cpu占用很高
### 问题描述 swoole使用自定义进程后 cpu占用很高 Load Avg: 3.83, 3.31, 2.99 CPU usage: 13.5% user, 4.68% sys, 82.25% idle SharedLibs: 153M resident, 44M data, 29M linkedit. MemRegions: 432269 total, 7388M resident, 140M private, 1907M shared. 未使用自定义进程 Load Avg: 2.64, 3.17, 2.98 CPU usage: 4.49% user, 2.22% sys, 93.28% idle SharedLibs: 153M resident, 44M data, 29M linkedit. MemRegions: 432438 total, 7529M resident, 147M private, 1698M shared. ### Swoole版本,PHP版本,以及操作系统版本信息 PHP 7.4.2 (cli) (built: Feb 17 2020 12:56:02) ( NTS ) swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.5.2 Built => Feb 24 2021 19:21:10 coroutine => enabled debug => enabled trace_log => enabled kqueue => enabled rwlock => enabled pcre => enabled zlib => 1.2.11 brotli => E16777223/D16777223 async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => Off => Off swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 262144 => 262144 ### 未使用自定义进程相关代码 ```php <?php namespace App\Console\Commands use Illuminate\Console\Command; use Illuminate\Support\Carbon; use Swoole\Coroutine; use function Swoole\Coroutine\run; class test extends Command { protected $signature = 'test'; public function handle() { run(function () { while (true){ Coroutine::create(function() { var_dump(file_get_contents("http://www.xinhuanet.com/")); }); }); } } ``` ### 使用自定义进程相关代码 ```php <?php namespace App\Processes; use Hhxsv5\LaravelS\Swoole\Process\CustomProcessInterface; use Swoole\Http\Server; use Swoole\Process; use Swoole\Runtime; use Swoole\Coroutine; use function Swoole\Coroutine\run; class TestProcess implements CustomProcessInterface { /** * @var bool 退出标记,用于Reload更新 */ private static $quit = false; public static function callback(Server $swoole, Process $process) { Runtime::enableCoroutine(true,SWOOLE_HOOK_SLEEP); Coroutine::create(function() { while (1){ var_dump(1); } }); } // 要求:LaravelS >= v3.4.0 并且 callback() 必须是异步非阻塞程序。 public static function onReload(Server $swoole, Process $process) { self::$quit = true; } // 要求:LaravelS >= v3.7.4 并且 callback() 必须是异步非阻塞程序。 public static function onStop(Server $swoole, Process $process) { self::$quit = true; } } ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 期望 得到解决自定义进程cpu上升的问题
发布于2年前 · 33 次浏览 · 来自
提问
哪吒
### 问题描述 swoole使用自定义进程后 cpu占用很高 Load Avg: 3.83, 3.31, 2.99 CPU usage: 13.5% user, 4.68% sys, 82.25% idle SharedLibs: 153M resident, 44M data, 29M linkedit. MemRegions: 432269 total, 7388M resident, 140M private, 1907M shared. 未使用自定义进程 Load Avg: 2.64, 3.17, 2.98 CPU usage: 4.49% user, 2.22% sys, 93.28% idle SharedLibs: 153M resident, 44M data, 29M linkedit. MemRegions: 432438 total, 7529M resident, 147M private, 1698M shared. ### Swoole版本,PHP版本,以及操作系统版本信息 PHP 7.4.2 (cli) (built: Feb 17 2020 12:56:02) ( NTS ) swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.5.2 Built => Feb 24 2021 19:21:10 coroutine => enabled debug => enabled trace_log => enabled kqueue => enabled rwlock => enabled pcre => enabled zlib => 1.2.11 brotli => E16777223/D16777223 async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => Off => Off swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 262144 => 262144 ### 未使用自定义进程相关代码 ```php <?php namespace App\Console\Commands use Illuminate\Console\Command; use Illuminate\Support\Carbon; use Swoole\Coroutine; use function Swoole\Coroutine\run; class test extends Command { protected $signature = 'test'; public function handle() { run(function () { while (true){ Coroutine::create(function() { var_dump(file_get_contents("http://www.xinhuanet.com/")); }); }); } } ``` ### 使用自定义进程相关代码 ```php <?php namespace App\Processes; use Hhxsv5\LaravelS\Swoole\Process\CustomProcessInterface; use Swoole\Http\Server; use Swoole\Process; use Swoole\Runtime; use Swoole\Coroutine; use function Swoole\Coroutine\run; class TestProcess implements CustomProcessInterface { /** * @var bool 退出标记,用于Reload更新 */ private static $quit = false; public static function callback(Server $swoole, Process $process) { Runtime::enableCoroutine(true,SWOOLE_HOOK_SLEEP); Coroutine::create(function() { while (1){ var_dump(1); } }); } // 要求:LaravelS >= v3.4.0 并且 callback() 必须是异步非阻塞程序。 public static function onReload(Server $swoole, Process $process) { self::$quit = true; } // 要求:LaravelS >= v3.7.4 并且 callback() 必须是异步非阻塞程序。 public static function onStop(Server $swoole, Process $process) { self::$quit = true; } } ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 期望 得到解决自定义进程cpu上升的问题
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
还没有评论!
微信公众号
热门内容
作者其它话题
- 再一个http请求中如何 异步发送一个http请求
- 如何swoole协程并行执行
- http_request_on_header_value: invalid multipart/form-data body fd:1
- 用processes 在linux上 一直有core文件
暂无回复的问答
- CodeGalaxy K3s 轻量集群节点之间如何实现负载均衡
- 关于openssl CURL WARNING swSSL_connect: SSL_connect(fd=69) failed. Error: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small[1|394]
- 多个模型如何进行事务异常回退?
- websocket开启wss报错
- 协程tcp服务器如何使用多进程?recv()方法接收信息,打印出来的pid一直是同一个。没用使用到多进程啊。