laravel队列系统是否适合大型项目? [英] Is laravel queue system suitable for big projects?

查看:331
本文介绍了laravel队列系统是否适合大型项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道laravel 5队列管理系统是否适合大型项目(拥有约100.000用户).我想每天一次执行类似消息传递(不是垃圾邮件:))用户的操作.
Redis是否足以胜任这项工作(排队)?还是最好使用专门用于排队的库(例如beantalkd)?

I needed to know if laravel 5 queue management system is suitable for big projects (having about 100.000 users). I want to do something like messaging (not spam :) ) users at once each day.
Is redis good enough for this job (queuing)? Or it is better to use a lib that is specially for queuing (like beanstalkd)?

推荐答案

为了公平起见,并尝试对此问题发布合理的答案,我们应该考虑以下几点:

To be fair and to try and post a reasonable answer to this question we should consider the following:

  • 订户数量
  • 要交付的内容
  • 同时运行队列所需的系统资源

100,000个订阅的电子邮件将需要在RAM中存储100,000 x [数据],因此让电子邮件地址的平均长度为32个字符(字节).

100,000 subscribed emails would require storing 100,000 x [data] in RAM, so lets average out the email address length to 32 characters (bytes).

100,000 x 32字节= 3.2MB

100,000 x 32 bytes = 3.2MB

当然,Laravel的队列系统会序列化对象,因此实际内存使用率可能会更高(Redis内存用于Laravel队列),但不足以引起您的关注.

Of course, Laravel's queue system serialises objects, so actual memory usage will probably be higher (Redis memory used for Laravel queue), but not enough to concern yourself with.

我曾经建议过,看似成功的设置用于发送已订阅的电子邮件消息将在以下条件下运行:

I've advised in the past that a seemingly successful setup for sending out subscribed email messages would run on the following:

  • 最低2GB RAM
  • 2个处理器/内核

Laravel运行的队列系统在服务器上的负担不是很大.与往常一样,根据需求扩展.

The queue system Laravel runs is not too taxing on a server. As always, scale with requirements.

用于此类软件(使用Laravel)的软件将包括以下内容:

The software for such (using Laravel) would consist of the following:

  • Redis
  • 主管

将Redis设置为Laravel的队列驱动程序.记住要composer require predis/predis.

Set up Redis as Laravel's queue driver. Remember to composer require predis/predis.

您还需要创建一个迁移以存储失败的作业. Laravel默认内置了一个:

You will also need to create a migration for storing failed jobs. Laravel has one built in by default:

php artisan queue:failed-table

php artisan migrate

一旦安装了Supervisor,请在/etc/supervisor/conf.d中创建一个conf文件,以便Supervisor可以选择队列的配置:

Once Supervisor is installed, create a conf file in /etc/supervisor/conf.d so that Supervisor can pick up on the configuration for your queue:

touch /etc/supervisor/conf.d/myprojectqueue.conf nano /etc/supervisor/conf.d/myprojectqueue.conf

在此布局适合您环境的配置.在下面的演示设置中,将在您的队列上同时执行4个队列运行器:

In there, lay out a configuration to suit your environment. In the following demo set up, 4 queue runners will execute on your queue at once:

    [program:myprojectqueue]
    command=php /path/to/project/artisan queue:listen --tries=1
    directory=/path/to/project
    stdout_logfile=/path/to/project/storage/logs/supervisord.log
    redirect_stderr=true
    autostart=true
    autorestart=true
    numprocs = 4
    process_name = %(program_name)s%(process_num)s

保存conf文件.启动/重新启动主管.

Save the conf file. Start / Restart Supervisor.

有关更多信息:

https://laravel.com/docs/master/queues

https://laravel.com/docs/master/queues#supervisor-configuration

https://laravel.com/docs/master/mail#queueing-mail

https://laravel.com/docs/master/scheduling

这篇关于laravel队列系统是否适合大型项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆