莊周夢(mèng)蝶

          生活、程序、未來(lái)
             :: 首頁(yè) ::  ::  :: 聚合  :: 管理
              前面一篇博客介紹了我在github上的一個(gè)metaq分支,今天下午寫了個(gè)metaq的python客戶端,目前僅支持發(fā)送消息功能,不過(guò)麻雀雖小,五臟俱全,客戶端和zookeeper的交互和連接管理之類都還具備,不出意外,我們會(huì)首先用上。第一次正兒八經(jīng)地寫python代碼,寫的不好的地方請(qǐng)盡管拍磚,多謝。
              項(xiàng)目叫meta-python,仍然放在github上:https://github.com/killme2008/meta-python

              使用需要先安裝zkpython這個(gè)庫(kù),具體安裝這篇博客,使用很簡(jiǎn)單,發(fā)送消息:
              from metamorphosis import Message,MessageProducer,SendResult
              p=MessageProducer("topic")
              message=Message("topic","message body")
              print p.send(message)
              p.close()

              
          MessageProducer就是消息發(fā)送者,它的構(gòu)造函數(shù)接受至少一個(gè)topic,默認(rèn)的zk_servers為localhost:2181,可以通過(guò)zk_servers參數(shù)指定你的zookeeper集群:

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

          更多參數(shù)請(qǐng)直接看源碼吧。一個(gè)本機(jī)的性能測(cè)試(meta和客戶端都跑在我的機(jī)器上,機(jī)器是Mac MC700,osx 10.7,磁盤沒(méi)有升級(jí)過(guò)):
          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()

           結(jié)果:


          duration:1.85962295532 seconds
          tps:5377.43415749 msgs/second

          評(píng)論

          # re: 淘寶開(kāi)源metaq的python客戶端[未登錄](méi)  回復(fù)  更多評(píng)論   

          2012-11-28 17:11 by colin
          大俠,你們metaq的java客戶端性能測(cè)試如何,
          我試用了下,
          單線程的話,
          發(fā)送 tps: 50 msgs/second
          接收 tps: 28000 msgs/second

          發(fā)送接收差異這么大,感覺(jué)很奇怪,是不是還有一些特殊的設(shè)置?
          主站蜘蛛池模板: 年辖:市辖区| 万盛区| 成都市| 阳泉市| 库伦旗| 梨树县| 武义县| 灵川县| 碌曲县| 光泽县| 九江市| 韶关市| 易门县| 深圳市| 永仁县| 岳普湖县| 连城县| 建瓯市| 兴隆县| 北辰区| 石河子市| 永济市| 双城市| 奉化市| 麻江县| 江门市| 永嘉县| 天峻县| 衡南县| 乌拉特后旗| 建宁县| 彰化县| 宿迁市| 宜川县| 德州市| 伊宁市| 东城区| 白山市| 沭阳县| 靖安县| 伊川县|