MAC下composer安装hyperf后遇到的CPU资源占用过高的情况

上午通过hyperf的官网安装说明通过:

composer create-project hyperf/hyperf-skeleton 

命令安装了hyperf,安装过程中询问各种composer package是否安装,我都选择的y,安装记录如下:

composer create-project hyperf/hyperf-skeleton 
Creating a "hyperf/hyperf-skeleton" project at "./hyperf-skeleton"
Installing hyperf/hyperf-skeleton (v2.0.4)
  - Installing hyperf/hyperf-skeleton (v2.0.4): Downloading (100%)         
Created project in /Users/mac/www/hyperf-skeleton
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
> Installer\Script::install
Setting up optional packages
Setup data and cache dir
Removing installer development dependencies

  What time zone do you want to setup ?
  [n] Default time zone for php.ini
Make your selection or type a time zone name, like Asia/Shanghai (n):
y

  Do you want to use Database (MySQL Client) ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (yes): yes
Invalid answer

  Do you want to use Database (MySQL Client) ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (yes): y
  - Adding package hyperf/database (~2.0.0)
  - Adding package hyperf/db-connection (~2.0.0)

  Do you want to use Redis Client ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (yes): y
  - Adding package hyperf/redis (~2.0.0)
  - Copying config/autoload/redis.php

  Which RPC protocol do you want to use ?
  [1] JSON RPC with Service Governance
  [2] JSON RPC
  [3] gRPC
  [n] None of the above
  Make your selection or type a composer package name and version (n): 3
  - Adding package hyperf/grpc-client (~2.0.0)
  - Adding package hyperf/grpc-server (~2.0.0)

  Which config center do you want to use ?
  [1] Apollo
  [2] Aliyun ACM
  [3] ETCD
  [n] None of the above
  Make your selection or type a composer package name and version (n): 1
  - Adding package hyperf/config-apollo (~2.0.0)
  - Copying config/autoload/apollo.php

  Do you want to use hyperf/constants component ?
  [y] yes
  [n] None of the above
  Make your selection (n): y
  - Adding package hyperf/constants (~2.0.0)
  - Copying app/Constants/ErrorCode.php
  - Copying app/Exception/BusinessException.php

  Do you want to use hyperf/async-queue component ? (A simple redis queue component)
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (n): y
  - Adding package hyperf/async-queue (~2.0.0)
  - Copying config/autoload/async_queue.php
  - Copying app/Process/AsyncQueueConsumer.php
  - Copying app/Listener/QueueHandleListener.php
  - Copying config/autoload/redis.php

  Do you want to use hyperf/amqp component ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (n): y
  - Adding package hyperf/amqp (~2.0.0)
  - Copying config/autoload/amqp.php

  Do you want to use hyperf/model-cache component ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (n): y
  - Adding package hyperf/model-cache (~2.0.0)
  - Copying app/Model/Model.php
  - Copying config/autoload/databases.php
  - Copying config/autoload/redis.php

  Do you want to use hyperf/elasticsearch component ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (n): y
  - Adding package hyperf/elasticsearch (~2.0.0)

  Do you want to use hyperf/tracer component ? (An open tracing protocol component, adapte with Zipkin etc.)
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (n): y
  - Adding package hyperf/tracer (~2.0.0)
  - Copying config/autoload/opentracing.php
Remove installer
Removing composer.lock from .gitignore
Removing Expressive installer classes, configuration, tests and docs
Loading composer repositories with package information
Updating dependencies (including require-dev)


Package operations: 132 installs, 0 updates, 0 removals
  - Installing composer/package-versions-deprecated (1.11.99): Downloading (100%)         
  - Installing hyperf/contract (v2.0.9): Downloading (100%)         
  - Installing doctrine/inflector (2.0.3): Loading from cache
  - Installing hyperf/utils (v2.0.9): Downloading (100%)         
  - Installing psr/simple-cache (1.0.1): Loading from cache
  - Installing psr/container (1.0.0): Loading from cache
  - Installing hyperf/cache (v2.0.9): Downloading (100%)         
  - Installing symfony/finder (v5.1.5): Loading from cache
  - Installing symfony/polyfill-ctype (v1.18.1): Loading from cache
  - Installing phpoption/phpoption (1.7.5): Loading from cache
  - Installing vlucas/phpdotenv (v4.1.8): Loading from cache
  - Installing hyperf/config (v2.0.9): Downloading (100%)         
  - Installing psr/log (1.1.3): Loading from cache
  - Installing psr/event-dispatcher (1.0.0): Loading from cache
  - Installing fig/http-message-util (1.1.4): Downloading (100%)         
  - Installing psr/http-message (1.0.1): Loading from cache
  - Installing hyperf/framework (v2.0.11): Downloading (100%)         
  - Installing monolog/monolog (2.1.1): Loading from cache
  - Installing hyperf/logger (v2.0.11): Downloading (100%)         
  - Installing hyperf/memory (v2.0.3): Downloading (100%)         
  - Installing hyperf/pool (v2.0.3): Downloading (100%)         
  - Installing hyperf/redis (v2.0.3): Downloading (100%)         
  - Installing jean85/pretty-package-versions (1.5.1): Downloading (100%)         - Installing google/protobuf (v3.13.0): Downloading (100%)         
  - Installing hyperf/grpc (v2.0.11): Downloading (100%)         
  - Installing hyperf/grpc-client (v2.0.11): Downloading (100%)         
  - Installing laminas/laminas-zendframework-bridge (1.1.1): Downloading (100%)   - Installing laminas/laminas-stdlib (3.3.0): Downloading (100%)         
  - Installing laminas/laminas-mime (2.7.4): Downloading (100%)         
  - Installing hyperf/http-message (v2.0.11): Downloading (100%)         
  - Installing symfony/polyfill-php80 (v1.18.1): Loading from cache
  - Installing symfony/polyfill-mbstring (v1.18.1): Loading from cache
  - Installing symfony/polyfill-intl-normalizer (v1.18.1): Loading from cache
  - Installing symfony/polyfill-intl-grapheme (v1.18.1): Loading from cache
  - Installing symfony/string (v5.1.5): Loading from cache
  - Installing symfony/service-contracts (v2.2.0): Loading from cache
  - Installing symfony/polyfill-php73 (v1.18.1): Loading from cache
  - Installing symfony/console (v5.1.5): Loading from cache
  - Installing hyperf/server (v2.0.9): Downloading (100%)         
  - Installing psr/http-server-handler (1.0.1): Downloading (100%)         
  - Installing psr/http-server-middleware (1.0.1): Downloading (100%)         
  - Installing hyperf/dispatcher (v2.0.10): Downloading (100%)         
  - Installing hyperf/exception-handler (v2.0.10): Downloading (100%)         
  - Installing hyperf/event (v2.0.10): Downloading (100%)         
  - Installing nikic/fast-route (v1.3.0): Downloading (100%)         
  - Installing hyperf/http-server (v2.0.11): Downloading (100%)         
  - Installing nikic/php-parser (v4.9.1): Loading from cache
  - Installing phpdocumentor/reflection-common (2.2.0): Loading from cache
  - Installing webmozart/assert (1.9.1): Loading from cache
  - Installing phpdocumentor/type-resolver (1.3.0): Loading from cache
  - Installing phpdocumentor/reflection-docblock (5.2.1): Loading from cache
  - Installing roave/signature (1.0.0): Downloading (100%)         
  - Installing jetbrains/phpstorm-stubs (v2019.3): Downloading (100%)         
  - Installing roave/better-reflection (4.9.0): Downloading (100%)         
  - Installing doctrine/instantiator (1.3.1): Loading from cache
  - Installing doctrine/lexer (1.2.1): Loading from cache
  - Installing doctrine/annotations (1.10.4): Downloading (100%)         
  - Installing hyperf/di (v2.0.10): Downloading (100%)         
  - Installing hyperf/grpc-server (v2.0.11): Downloading (100%)         
  - Installing hyperf/config-apollo (v2.0.10): Downloading (100%)         
  - Installing hyperf/constants (v2.0.9): Downloading (100%)         
  - Installing hyperf/command (v2.0.10): Downloading (100%)         
  - Installing hyperf/async-queue (v2.0.11): Downloading (100%)         
  - Installing phpseclib/phpseclib (2.0.29): Downloading (100%)         
  - Installing php-amqplib/php-amqplib (v2.12.0): Downloading (100%)         
  - Installing hyperf/process (v2.0.9): Downloading (100%)         
  - Installing hyperf/amqp (v2.0.8): Downloading (100%)         
  - Installing symfony/translation-contracts (v2.2.0): Loading from cache
  - Installing symfony/translation (v5.1.5): Loading from cache
  - Installing nesbot/carbon (2.40.0): Downloading (100%)         
  - Installing hyperf/paginator (v2.0.3): Downloading (100%)         
  - Installing hyperf/database (v2.0.11): Downloading (100%)         
  - Installing hyperf/model-listener (v2.0.3): Downloading (100%)         
  - Installing hyperf/db-connection (v2.0.10): Downloading (100%)         
  - Installing hyperf/model-cache (v2.0.10): Downloading (100%)         
  - Installing react/promise (v2.8.0): Downloading (100%)         
  - Installing ezimuel/guzzlestreams (3.0.1): Downloading (100%)         
  - Installing ezimuel/ringphp (1.1.2): Downloading (100%)         
  - Installing elasticsearch/elasticsearch (v7.9.0):Downloading (100%)         )
  - Installing symfony/polyfill-php72 (v1.18.1): Loading from cache
  - Installing paragonie/random_compat (v9.99.99): Loading from cache
  - Installing symfony/polyfill-php70 (v1.18.1): Loading from cache
  - Installing symfony/polyfill-intl-idn (v1.18.1): Loading from cache
  - Installing ralouphie/getallheaders (3.0.3): Loading from cache
  - Installing guzzlehttp/psr7 (1.6.1): Loading from cache
  - Installing guzzlehttp/promises (v1.3.1): Loading from cache
  - Installing guzzlehttp/guzzle (6.5.5): Loading from cache
  - Installing hyperf/guzzle (v2.0.11): Downloading (100%)         
  - Installing hyperf/elasticsearch (v2.0.10): Downloading (100%)         
  - Installing opentracing/opentracing (1.0.0-beta5): Downloading (100%)          - Installing openzipkin/zipkin (1.3.6): Downloading (100%)         
  - Installing jcchavezs/zipkin-opentracing (0.1.5):Downloading (100%)         )
  - Installing hyperf/tracer (v2.0.3): Downloading (100%)         
  - Installing swoole/ide-helper (4.5.4): Downloading (100%)         
  - Installing symfony/stopwatch (v5.1.5): Downloading (100%)         
  - Installing symfony/process (v5.1.5): Loading from cache
  - Installing symfony/deprecation-contracts (v2.2.0): Loading from cache
  - Installing symfony/options-resolver (v5.1.5): Downloading (100%)         
  - Installing symfony/filesystem (v5.1.5): Downloading (100%)         
  - Installing symfony/event-dispatcher-contracts (v2.2.0): Loading from cache
  - Installing symfony/event-dispatcher (v5.1.5): Loading from cache
  - Installing php-cs-fixer/diff (v1.3.0): Downloading (100%)         
  - Installing composer/xdebug-handler (1.4.3): Downloading (100%)         
  - Installing composer/semver (1.7.0): Downloading (100%)         
  - Installing friendsofphp/php-cs-fixer (v2.16.4): Downloading (100%)         
  - Installing hamcrest/hamcrest-php (v2.0.1): Loading from cache
  - Installing mockery/mockery (1.3.3): Downloading (100%)         
  - Installing phpstan/phpstan (0.12.42): Downloading (100%)         
  - Installing hyperf/devtool (v2.0.10): Downloading (100%)         
  - Installing sebastian/version (2.0.1): Loading from cache
  - Installing sebastian/resource-operations (2.0.1): Loading from cache
  - Installing sebastian/recursion-context (3.0.0): Loading from cache
  - Installing sebastian/object-reflector (1.1.1): Loading from cache
  - Installing sebastian/object-enumerator (3.0.3): Loading from cache
  - Installing sebastian/global-state (2.0.0): Downloading (100%)         
  - Installing sebastian/exporter (3.1.2): Loading from cache
  - Installing sebastian/environment (4.2.3): Loading from cache
  - Installing sebastian/diff (3.0.2): Loading from cache
  - Installing sebastian/comparator (3.0.2): Loading from cache
  - Installing phpunit/php-timer (2.1.2): Loading from cache
  - Installing phpunit/php-text-template (1.2.1): Loading from cache
  - Installing phpunit/php-file-iterator (2.0.2): Loading from cache
  - Installing theseer/tokenizer (1.2.0): Loading from cache
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Loading from cache
  - Installing phpunit/php-token-stream (3.1.1): Loading from cache
  - Installing phpunit/php-code-coverage (6.1.4): Downloading (100%)         
  - Installing phpspec/prophecy (1.11.1): Loading from cache
  - Installing phar-io/version (2.0.1): Loading from cache
  - Installing phar-io/manifest (1.0.3): Loading from cache
  - Installing myclabs/deep-copy (1.10.1): Loading from cache
  - Installing phpunit/phpunit (7.5.20): Downloading (100%)         
  - Installing hyperf/testing (v2.0.3): Downloading (100%)         
hyperf/utils suggests installing symfony/var-dumper (Required to use the dd function (^5.0).)
hyperf/utils suggests installing symfony/serializer (Required to use SymfonyNormalizer (^5.0))
hyperf/utils suggests installing symfony/property-access (Required to use SymfonyNormalizer (^5.0))
monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongodb (Allow sending log messages to a MongoDB server (via driver))
monolog/monolog suggests installing mongodb/mongodb (Allow sending log messages to a MongoDB server (via library))
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
monolog/monolog suggests installing php-console/php-console (Allow sending log messages to Google Chrome)
laminas/laminas-mime suggests installing laminas/laminas-mail (Laminas\Mail component)
symfony/polyfill-intl-normalizer suggests installing ext-intl (For best performance)
symfony/polyfill-intl-grapheme suggests installing ext-intl (For best performance)
symfony/service-contracts suggests installing symfony/service-implementation
symfony/console suggests installing symfony/lock
roave/better-reflection suggests installing composer/composer (Required to use the ComposerSourceLocator)
hyperf/constants suggests installing hyperf/translation (Required to use translation.)
phpseclib/phpseclib suggests installing ext-libsodium (SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.)
phpseclib/phpseclib suggests installing ext-mcrypt (Install the Mcrypt extension in order to speed up a few other cryptographic operations.)
phpseclib/phpseclib suggests installing ext-gmp (Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.)
symfony/translation suggests installing symfony/config
symfony/translation suggests installing symfony/yaml
hyperf/database suggests installing doctrine/dbal (Required to rename columns (^2.6).)
paragonie/random_compat suggests installing ext-libsodium (Provides a modern crypto API that can be used to generate random bytes.)
symfony/polyfill-intl-idn suggests installing ext-intl (For best performance)
guzzlehttp/psr7 suggests installing zendframework/zend-httphandlerrunner (Emit PSR-7 responses)
hyperf/tracer suggests installing jonahgeorge/jaeger-client-php (Required to use jaeger tracing.)
symfony/event-dispatcher suggests installing symfony/dependency-injection
symfony/event-dispatcher suggests installing symfony/http-kernel
friendsofphp/php-cs-fixer suggests installing php-cs-fixer/phpunit-constraint-isidenticalstring (For IsIdenticalString constraint.)
friendsofphp/php-cs-fixer suggests installing php-cs-fixer/phpunit-constraint-xmlmatchesxsd (For XmlMatchesXsd constraint.)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.6.0)
phpunit/phpunit suggests installing phpunit/php-invoker (^2.0)
phpunit/phpunit suggests installing ext-xdebug (*)
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
> rm -rf runtime/container
39 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

然后启动:

# 进入安装好的 Hyperf 项目目录
cd hyperf-skeleton
# 启动 Hyperf
php bin/hyperf.php start
% php bin/hyperf.php start
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Config\Listener\RegisterPropertyHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\SocketIOServer\Listener\AddRouteListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Paginator\Listener\PageResolverListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\ExceptionHandler\Listener\ExceptionHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\DbConnection\Listener\RegisterConnectionResolverListener listener.
[DEBUG] Event Hyperf\Framework\Event\BeforeMainServerStart handled by Hyperf\Amqp\Listener\BeforeMainServerStartListener listener.
[DEBUG] Event Hyperf\Framework\Event\BeforeMainServerStart handled by Hyperf\SocketIOServer\Listener\ServerIdListener listener.
[DEBUG] Event Hyperf\Framework\Event\BeforeMainServerStart handled by Hyperf\Process\Listener\BootProcessListener listener.
[DEBUG] Event Hyperf\Framework\Event\OnManagerStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener.
[DEBUG] Event Hyperf\Framework\Event\OnStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener.
[DEBUG] Event Hyperf\Framework\Event\BeforeWorkerStart handled by Hyperf\ConfigApollo\Listener\BootProcessListener listener.
[DEBUG] Event Hyperf\Process\Event\BeforeProcessHandle handled by Hyperf\ConfigApollo\Listener\BootProcessListener listener.
[DEBUG] Event Hyperf\Process\Event\BeforeProcessHandle handled by Hyperf\Server\Listener\InitProcessTitleListener listener.
[INFO] Process[queue.default.0] start.
[DEBUG] Event Hyperf\Process\Event\BeforeProcessHandle handled by Hyperf\Process\Listener\LogBeforeProcessStartListener listener.
[DEBUG] Event Hyperf\Framework\Event\MainWorkerStart handled by Hyperf\Amqp\Listener\MainWorkerStartListener listener.
[DEBUG] Event Hyperf\Framework\Event\MainWorkerStart handled by Hyperf\SocketIOServer\Listener\StartSubscriberListener listener.
[INFO] Worker#0 started.
[INFO] HTTP Server listening at 0.0.0.0:9501
[DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\AfterWorkerStartListener listener.
[DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\WebSocketServer\Listener\InitSenderListener listener.
[DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener.

启动hyperf后就发现MAC的风扇开始狂转,通过活动资源监视器查看如下:

php的进程占用的CPU资源一直是73%左右,把hyperf停掉,php的进程就没了,资源占用骤降。

百思不得其解,主要是安装完我还未进行任何配置和开发,启动后资源占用就这么高,那还得了,之后在hyperf微信交流4群我把的情况一说才知道原来hyperf设计的是安装时询问是否安装各种package,如果选择了y就必要要配置相关连接参数,如果不配置,由于hyperf是采用注解方式在hyperf服务一启动时,那些选择过y的package服务就自动启动了,包括我安装过程中我选择的redis异步队列,之后按照群里面一个人的建议,把位于:App/Process/AsyncQueueConsumer.php文件中的注解给去掉,然后再启动hyperf问题解决了。

hyperf开源项目创始人黄朝晖解释道由于安装时选择了安装redis异步队列服务( async-queue),在启动hyperf前又没有配置连接参数,陷入死循环,不停的重试,最终导致CPU资源占用过高。

主要是hyperf这安装说明也没提示那些选择要的package服务,只要选择安装了,就必须配置,我还以为是只是多安装几个库,需要时再在配置文件中通过配置相关连接参数再启用。这和之前使用的easyswoole的风格截然不同。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值