beanstalkd

PHP-Beanstalkd消息队列 延迟队列的搭建使用

喜夏-厌秋 提交于 2020-08-05 04:43:33
一安装 >=PHP7.0 >=Centos7.0 yum install beanstalkd --enablerepo=epel 启动: /usr/bin/beanstalkd -l 0.0.0.0 -p11300 -b /var/lib/beanstalkd/binlog -F & 参数: /usr/bin/beanstalkd -h Use:/usr/bin/beanstalkd [OPTIONS] Options: -b 开启binlog,断电后重启会自动恢复任务。 -f MS fsync最多每MS毫秒-F从不fsync(默认) -l ADDR侦听地址(默认为0.0.0.0) -p端口侦听端口(默认为11300) -u USER成为用户和组 -z BYTES设置最大作业大小(以字节为单位)(默认值为65535) -s BYTES设置每个wal文件的大小(默认为10485760) (将被舍入到512字节的倍数) -c压缩binlog(默认) - n 不要压缩binlog -v显示版本信息 -V增加冗长度 -h显示这个帮助 配置文件: /etc/sysconfig/beanstalkd 二PHP操作 来源: oschina 链接: https://my.oschina.net/songms/blog/4347999

轻量级消息队列benastalkd

杀马特。学长 韩版系。学妹 提交于 2020-02-28 12:42:43
Beanstalkd设计里面的核心概念: ◆ job 一个需要异步处理的任务,是Beanstalkd中的基本单元,需要放在一个tube中。 ◆ tube 一个有名的任务队列,用来存储统一类型的job,是producer和consumer操作的对象。 ◆ producer Job的生产者,通过put命令来将一个job放到一个tube中。 ◆ consumer Job的消费者,通过reserve/release/bury/delete命令来获取job或改变job的状态。 Beanstalkd中一个job的生命周期如图所示。一个job有READY, RESERVED, DELAYED, BURIED四种状态。当producer直接put一个job时,job就处于READY状态,等待consumer来处理,如果选择延迟put,job就先到DELAYED状态,等待时间过后才迁移到READY状态。consumer获取了当前READY的job后,该job的状态就迁移到RESERVED,这样其他的consumer就不能再操作该job。当consumer完成该job后,可以选择delete, release或者bury操作;delete之后,job从系统消亡,之后不能再获取;release操作可以重新把该job状态迁移回READY(也可以延迟该状态迁移操作)

【面试必备】聊聊高性能延时队列应用

元气小坏坏 提交于 2020-02-27 08:14:26
延时队列的应用场景: 下单后,30分钟内未付款就自动取消订单等; 支付后,24小时未评论自动好评; 在我们实际开发过程中,应用场景很多... 基于Redis Zset 实现 实现原理 Redis由于其自身的Zset数据结构,也同样可以实现延时的操作。 Zset本质就是Set结构上加了个排序的功能,除了添加数据value之外,还提供另一属性score,这一属性在添加元素时候可以指定, 每次指定score后,Zset会自动重新按新的值调整顺序 。 如果score代表的是想要执行时间的 时间戳 ,在某个时间将它插入Zset集合中,它会按照时间戳大小进行排序,也就是对执行时间前后进行排序。 > ZADD delay_queue 1581309229 taskId_1 (integer) 1 > ZADD delay_queue 1581309129 taskId_2 (integer) 1 > ZADD delay_queue 1581309329 taskId_3 (integer) 1 不断地进行取第一个key值,如果当前 时间戳 大于等于该key值的socre就将它取出来进行消费删除,就可以达到延时执行的目的。 注意不需要遍历整个Zset集合,以免造成性能浪费。 > ZRANGE delay_queue 0 -1 withscores 1) "taskId_2" 2)

PHP使用Beanstalkd实例

喜你入骨 提交于 2020-02-26 10:53:08
有关Beanstalkd的基本概念,编译和yum的安装方法已经在上述笔记中记录了,今天练习下PHP使用Beanstalkd的过程,我选择的是使用Pheanstalk类来连接Beanstalkd 1.使用Composer安装Pheanstalk composer require pda/pheanstalk 2.实现代码 php查看beanstalkd状态脚本 Status.php <?php /** * Created by PhpStorm. * User: jmsite.cn * Date: 2019/1/21 * Time: 10:32 */ require "../vendor/autoload.php" ; use Pheanstalk \ Pheanstalk ; $pheanstalk = new Pheanstalk( '192.168.75.135' , 11300 ); print_r($pheanstalk->stats()); 生产者代码 Producter.php <?php /** * Created by PhpStorm. * User: jmsite.cn * Date: 2019/1/20 * Time: 16:30 */ require "../vendor/autoload.php" ; use Pheanstalk \ Pheanstalk

Database Backed Work Queue

痴心易碎 提交于 2020-01-13 06:34:10
问题 My situation ... I have a set of workers that are scheduled to run periodically, each at different intervals, and would like to find a good implementation to manage their execution. Example: Let's say I have a worker that goes to the store and buys me milk once a week. I would like to store this job and it's configuration in a mysql table. But, it seems like a really bad idea to poll the table (every second?) and see which jobs are ready to be put into the execution pipeline. All of my

Laravel 4 Queue - [InvalidArgumentException] There are no commands defined in the “queue” namespace

99封情书 提交于 2020-01-07 03:39:47
问题 I'm using Laravel 4 + Beanstalk + Supervisor on a CentOS 6 VPS. It was already a pain to install both beanstalk and supervisor on the VPS, but I got through it (I have done this same installation on my local server, a Macbook Pro, and it's working fine there). I want to take advantage of Laravel 4's Queues and Beanstalk to send email asynchronously. I have made a "program" for supervisor that basically runs the command php artisan queue:listen --env=production but the process associated to

Laravel & Laravel Forge returns “MaxAttemptsExceededException:” even when tries are set at 1

怎甘沉沦 提交于 2019-12-24 18:32:05
问题 My error log is getting filled with this useless text, I have set my job to only try once and the time out to 0 because the jobs can be really long and it depends on the user. So the job has tries set at 1 timeout at 0, on laravel forge I have set my worker to have max tries at 1 and timeout 0, and still it gives me this error in the logs: Illuminate\Queue\MaxAttemptsExceededException: A queued job has been attempted too many times. The job may have previously timed out. in /home/forge

Obtaining result from async API

为君一笑 提交于 2019-12-24 14:10:28
问题 I am building API for processing with Lumen, the processing job is taking around 1-3 seconds per request. So far i did it with job queue and beanstalkd and it is asynchronous, meaning i return job_id that i can check later for the result. I am also writing PHP client to utilize the API and for that i am wondering if i should include 'wait' parameter server side or client side? If wait is implemented serverside i will need to sleep and check the database for results once the job is dispatched

Beanstalkd / Pheanstalk security issue

馋奶兔 提交于 2019-12-24 14:02:03
问题 I have just started using beanstalkd and pheanstalk and I am curious whether the following situation is a security issue (and if not, why not?): When designing a queue that will contain jobs for an eventual worker script to pick up and preform SQL database queries, I asked a friend what I could do to prevent an online user from going into port 11300 of my server, and inserting a job into the queue himself and hence causing the job to be executed with malicious code. I was told that I could

How to monitor Redis as a queue engine using cli similar to beanstalkd?

半腔热情 提交于 2019-12-24 00:38:46
问题 Background We used Laravel Queues on top of beanstalkd on two ec2 instances (behind a load balancer). As the system scaled we decided to use redis instead of beanstalkd, and host it on an AWS elastic cache instance (with a cluster of a master node and two replicas). With beanstalkd, I used beanstalk utilities to monitor the health of the queue; for example if the queue was getting clogged, I could easily see that by running a command like this: ./beanstalk-queue-stats.rb localhost:11300 Which