一个高性能分布式内存队列系统

来源:互联网 发布:隐藏php版本 编辑:程序博客网 时间:2024/05/29 19:47








(http://www.slideshare.net/friedo/building-scalable-distributed-job-queues-with-redis-and-redisclient)


SIMPLE MESSAGE QUEUE USING REDIS

http://xicojunior.wordpress.com/2014/01/23/simple-message-queue-using-redis/


消息队列中间件的技术分析:

http://blog.fity.cn/post/377/



http://csrd.aliapp.com/?p=1201

Beanstalkd 一个高性能分布式内存队列系统


http://restmq.com/

RestMQ

Redis based message queue

RestMQ is a message queue which uses HTTP as transport, JSON to format a minimalist protocol and is organized as REST resources. It stands on the shoulder of giants, built over Python, Twisted, Cyclone (a Tornado implementation over twisted) and Redis.
Message queues are created on the fly, as a message is sent to them. They are simple to use as a curl request can be.

There is a simple JSON-based protocol for those looking for a more formal syntax, but it is not mandatory.



李会军•宁静致远 | Redis作为消息队列与RabbitMQ的性能对比

周末测试了一下RabbitMQ的性能,RabbitMQ是使用Erlang编写的一个开源的消息队列,本身支持很多的协议:AMQP,XMPP, SMTP, STOMP,也正是如此,使的它变的非常重量级,更适合于企业级的开发。个人认为,在互联网开发中,使用消息队列,更多的因为在高并发环境下,由于来不及同步处理,请求会发生堵塞,所以我们需要一个队列服务来进行异步的处理,在这种场景下,只要队列服务满足最基本的Push/Pop已经足够了。

Redis是一个Key-Value的NoSQL数据库,开发维护很活跃,虽然它是一个Key-Value数据库存储系统,但它本身支持list数据结构的操作,所以完全可以当做一个轻量级的队列服务来使用。

本文简单对比了Redis作为消息队列和RabbitMQ的性能表现情况。

测试环境

1. 硬件环境:在个人笔记本上测试,Server和Client使用同一台机器,硬件信息如下

Processor : Inter(R) Core(TM)2 Duo CPU P8400 @2.26GHzRAM : 4.00GBOperating System : 32-bit Ubuntu 10.10

2. 软件化境:RabbitMQ和Redis的Server启动都是用默认配置,客户端使用Java,JVM启动使用默认参数:

RabbitMQ Server 2.2.0RabbitMQ Java Client 2.2.0Redis 2.0 StableJedis

对于RabbitMQ和Redis的入队和出队操作,各执行100万次,每10万次记录一次执行时间。测试数据分为128Bytes、512Bytes、1K和10K四个不同大小的数据。

入队性能对比

四种不同大小的数据入队性能对比(RPS):

mqperformance_001

测试结果:

mq_table_001

可以看到对于入队操作,当数据比较小时Redis的性能要高于RabbitMQ,而如果数据大小超过了10K,Redis慢的无法忍受。

出队性能对比

四种不同大小的数据出队对比(PRS):

mqperformance_002

测试结果:

mq_table_002

可以看到对于出队操作,无论数据大小,Redis都表现出非常好的性能,而RabbitMQ的出队性能则远低于Redis。

Redis入队和出队对比

针对Redis入队和出队对比(RPS):

mqperformance_003

测试数据:

mq_table_003

不管数据大小,Redis的出队性能都表现的非常优秀,而入队性能在数据比较大时,慢的无法忍受。

RabbitMQ入队和出队对比

针对RabbitMQ的入队和出队对比(RPS):

mqperformance_004

测试数据:

mq_table_004

不管数据大小,RabbitMQ的入队和出队性能都保持一个均衡的状态,但总体上,出队性能远低于入队性能。

总结

总体看来,Redis比较适合在Web场景下作为队列服务使用,但当数据比较大的时候,入队性能有些问题,也可能是我配置上不正确,所以还需要进一步研究。而RabbitMQ本身支持太多的协议,不适合在Web环境中使用。另外有一个MySQL的插件Q4M,可以使用SQL语法来操作消息队列,只不过性能表现怎么样,还需要进一步测试。


(http://stackoverflow.com/questions/7241310/job-queue-with-redis-using-blpop)

Job queue with redis using BLPOP

up vote10down votefavorite
5

Im trying to create infinite job queue using redis and ruby eventmachine. To achieve that Im using redis BLPOP command with 0 timeout. After successful BLPOP I run it again.

Am I on the right way or there is a better way to create job queue with redis?

share|improve this question
 

2 Answers

activeoldestvotes
up vote16down voteaccepted

There are several articles/resources regarding this scenario, here is one:

  • Redis Queues: An Emerging Usecase
share|improve this answer
 
 
Second link is wrong. –  djechlin Jul 10 '13 at 20:04
up vote4down vote

If you use BLPOP alone to remove a message from the queue, and your message consumer fails to process it, the message will have to be re-queued, lest it disappear forever along with the failed consumer.

For more durable message processing, a list of messages being processed must be maintained so they can be re-queued in the event of failure.

[B]RPOPLPUSH is perfect for this scenario; it can atomically pop a message from the message queue and pushes it onto a processing queue so that the application can respond in the case of a failure on the consumer's end.

http://redis.io/commands/rpoplpush

Actual re-queueing is left to the application, but this redis command provides the foundations to do so.

There are also some drop-in-place implementations of queues using redis floating around the web, such as RestMQ [ http://www.restmq.com/ ]




















































在网络服务器运行的时候,可能会碰到这样的需求,主程序处理会很耗时,

           1,网络流量很大,但有紧急情况需要发送邮件通知别人,这时如果在程序中发送邮件,将会很费时,但又必须做

           2,处理客户端请求后,剩下的事情跟正常逻辑没有关系,但有些耗时的操作需要完成

遇到这样的情况,可以有几种办法:

           1,开一个线程跑这些数据,主程序继续处理其他的任务

           2,用redis阻塞队列,将消息传到队列中,其他的事情由别的程序来重redis中读取队列中的消息, 并进行处理


1,开一个线程处理:

           如果这样的操作很多的话,对程序影响很大的,因为每次涉及到线程资源的申请和销毁,这些都要占用一些主程序时间,并且这样破坏了主要逻辑的流程

2,用redis的阻塞队列实现:

           先说一下环境:处理客户端请求用php,处理redis的消息队列用python脚本

           实现方法:由php向redis中写人的队列写入消息,由python脚本读redis中的队列中的消息,可能有朋友会考虑说让python这样一直跑不也占系统资源吗,但redis中有一个阻塞队列,使用该方法,当python读取队列 的时候,如果为空,则阻塞,如果有消息,则唤醒并执行,效果很好

           补充:

  redis中,python调用的一个方法为blpop(key, timeout) .当把timeout致为0时表示永久不超时,这样的话,这个python进程就是类似一个监听进程,当有消息的时候他就努力工作,没有的时候就看着

示例代码:




0 0
原创粉丝点击