Home
Download
Document
Q&A
Video
Donate
Source Code
Code-Galaxy
Business
Swoole Tracker
Swoole Compiler
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上升的问题
发布于1年前 · 30 次浏览 · 来自
提问
哪
哪吒
### 问题描述 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
评论
还没有评论!
微信公众号
热门内容
- 重启worker时希望读取到其它文件的配置变更
- Think-Swoole: 全面协程化你的 ThinkPHP 应用
- 协程Co::set设置hook_flage失效
- fatal error: 'pcre2.h' file not found
- 环境有http2,调用就报错
- 最新版的协程 Redis 客户端 已不建议使用,那Redis服务端以后还会存在吗?
- framework 404
- Swoole-Cli v5.0.2 增加 opcache/readline 扩展,强化 Cli-Server
- 用curl后,php代码处理的很快,但是返回的给前端的时间慢,有人知道原因吗
- Swoole-cli 5.0 Window10运行Hyperf命令行报错
作者其它话题
- 再一个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]
- 请问那个一键协程化的代码是放外面还是set里面
- 多个模型如何进行事务异常回退?
- websocket开启wss报错