庄周梦蝶

生活、程序、未来
   :: 首页 ::  ::  :: 聚合  :: 管理

淘宝开源metaq的python客户端

Posted on 2012-03-21 19:08 dennis 阅读(5533) 评论(1)  编辑  收藏 所属分类: javamy open-sourceHadoop与分布式
    前面一篇博客介绍了我在github上的一个metaq分支,今天下午写了个metaq的python客户端,目前仅支持发送消息功能,不过麻雀虽小,五脏俱全,客户端和zookeeper的交互和连接管理之类都还具备,不出意外,我们会首先用上。第一次正儿八经地写python代码,写的不好的地方请尽管拍砖,多谢。
    项目叫meta-python,仍然放在github上:https://github.com/killme2008/meta-python

    使用需要先安装zkpython这个库,具体安装这篇博客,使用很简单,发送消息:
    from metamorphosis import Message,MessageProducer,SendResult
    p=MessageProducer("topic")
    message=Message("topic","message body")
    print p.send(message)
    p.close()

    
MessageProducer就是消息发送者,它的构造函数接受至少一个topic,默认的zk_servers为localhost:2181,可以通过zk_servers参数指定你的zookeeper集群:

p=MessageProducer("topic",zk_servers="192.168.1.100:2191,192.168.1.101:2181")

更多参数请直接看源码吧。一个本机的性能测试(meta和客户端都跑在我的机器上,机器是Mac MC700,osx 10.7,磁盘没有升级过):
from metamorphosis import Message,MessageProducer
from time import time
p=MessageProducer("avos-fetch-tasks")
message=Message("avos-fetch-tasks","http://www.taobao.com")
start=time()
for i in range(0,10000):
    sent=p.send(message)
    if not sent.success:
        print "send failed"
finish=time()
secs=finish-start
print "duration:%s seconds" % (secs)
print "tps:%s msgs/second" % (10000/secs)
p.close()

 结果:


duration:1.85962295532 seconds
tps:5377.43415749 msgs/second

评论

# re: 淘宝开源metaq的python客户端[未登录]  回复  更多评论   

2012-11-28 17:11 by colin
大侠,你们metaq的java客户端性能测试如何,
我试用了下,
单线程的话,
发送 tps: 50 msgs/second
接收 tps: 28000 msgs/second

发送接收差异这么大,感觉很奇怪,是不是还有一些特殊的设置?

只有注册用户登录后才能发表评论。


网站导航: