问题描述
我正在使用 laravel 地平线来监控我的队列。我只有两个队列,我在我的实例上使用 redis 和 supervisor。当我的 ec2 实例为 micro
或 nano
时它不起作用我不得不使用 small
实例之后我将进程数从 5 减少到 1。现在它正在使用 nano实例。但是由于后台进程只有两个工作,我认为它也应该适用于微实例。
请看看我的 horizon.PHP 和主管 conf 文件,让我知道我是否可以再做更多
<?PHP
return [
/*
|--------------------------------------------------------------------------
| Horizon Domain
|--------------------------------------------------------------------------
|
| This is the subdomain where Horizon will be accessible from. If this
| setting is null,Horizon will reside under the same domain as the
| application. Otherwise,this value will serve as the subdomain.
|
*/
'domain' => null,/*
|--------------------------------------------------------------------------
| Horizon Path
|--------------------------------------------------------------------------
|
| This is the URI path where Horizon will be accessible from. Feel free
| to change this path to anything you like. Note that the URI will not
| affect the paths of its internal API that aren't exposed to users.
|
*/
'path' => 'horizon',/*
|--------------------------------------------------------------------------
| Horizon Redis Connection
|--------------------------------------------------------------------------
|
| This is the name of the Redis connection where Horizon will store the
| Meta information required for it to function. It includes the list
| of supervisors,Failed jobs,job metrics,and other information.
|
*/
'use' => 'default',/*
|--------------------------------------------------------------------------
| Horizon Redis Prefix
|--------------------------------------------------------------------------
|
| This prefix will be used when storing all Horizon data in Redis. You
| may modify the prefix when you are running multiple installations
| of Horizon on the same server so that they don't have problems.
|
*/
'prefix' => env('HORIZON_PREFIX','horizon:'),/*
|--------------------------------------------------------------------------
| Horizon Route Middleware
|--------------------------------------------------------------------------
|
| These middleware will get attached onto each Horizon route,giving you
| the chance to add your own middleware to this list or change any of
| the existing middleware. Or,you can simply stick with this list.
|
*/
'middleware' => ['web','auth'],/*
|--------------------------------------------------------------------------
| Queue Wait Time Thresholds
|--------------------------------------------------------------------------
|
| This option allows you to configure when the LongWaitDetected event
| will be fired. Every connection / queue combination may have its
| own,unique threshold (in seconds) before this event is fired.
|
*/
'waits' => [
'redis:default' => 60,],/*
|--------------------------------------------------------------------------
| Job Trimming Times
|--------------------------------------------------------------------------
|
| Here you can configure for how long (in minutes) you desire Horizon to
| persist the recent and Failed jobs. Typically,recent jobs are kept
| for one hour while all Failed jobs are stored for an entire week.
|
*/
'trim' => [
'recent' => 60,'completed' => 60,'recent_Failed' => 10080,'Failed' => 10080,'monitored' => 10080,/*
|--------------------------------------------------------------------------
| Fast Termination
|--------------------------------------------------------------------------
|
| When this option is enabled,Horizon's "terminate" command will not
| wait on all of the workers to terminate unless the --wait option
| is provided. Fast termination can shorten deployment delay by
| allowing a new instance of Horizon to start while the last
| instance will continue to terminate each of its workers.
|
*/
'fast_termination' => false,/*
|--------------------------------------------------------------------------
| Memory Limit (MB)
|--------------------------------------------------------------------------
|
| This value describes the maximum amount of memory the Horizon worker
| may consume before it is terminated and restarted. You should set
| this value according to the resources available to your server.
|
*/
'memory_limit' => 64,/*
|--------------------------------------------------------------------------
| Queue Worker Configuration
|--------------------------------------------------------------------------
|
| Here you may define the queue worker settings used by your application
| in all environments. These supervisors and settings handle all your
| queued jobs and will be provisioned by Horizon during deployment.
|
*/
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis','queue' => ['default'],'balance' => 'auto','processes' => 1,'tries' => 2,'local' => [
'supervisor-1' => [
'connection' => 'redis',];
主管确认
[program:queue-worker]
process_name=%(program_name)s_%(process_num)02d
command=PHP /var/www/html/coldxcoldxlogistics/artisan horizon
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/html/coldxcoldxlogistics/worker.log
解决方法
我将 memory_limit
设置为 10mb
并将进程从 5 减少到 1。现在系统在 micro
实例上运行良好
您的 supervisor.conf numprocs=8 将启动 8 个地平线主进程。然后每个 Horizon 主进程将启动 1 个进程。这是 8 个过程。
这就是消耗 cpu 周期的原因,可能不是预期的结果。您可以通过从 supervisor.conf 中删除 numprocs 来解决它