登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Code@Pig Home

喜欢背着一袋Code傻笑的Pig .. 忧美.欢笑.记忆.忘却 .之. 角落

 
 
 

日志

 
 

[twisted] tcp 与 domain socket 性能对比  

2010-07-06 16:31:26|  分类: net_Twisted |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
在 twisted 基础上,测试了下 tcp 与 unix domain socket 的性能对比。
扣除 python/twisted 本身的消耗,下面的数据还是能一定的参考意义的。

测试结果
在3台机器上跑了测试,比较诡异的是,有一台机器的 tcp 速度既然有点慢,哈。
128 bytes / line     1024*8 lines   一共 1Mb 数据

CPU: Intel(R) Xeon(R) CPU            5130  @ 2.00GHz (1995.01-MHz 686-class CPU)
real memory  = 3488677888 (3327 MB)
TCP 需要 0.230 s
Domain Socket 需要 0.064 s

CPU: Intel(R) Xeon(R) CPU            5130  @ 2.00GHz (1995.01-MHz 686-class CPU)
real memory  = 3488677888 (3327 MB)
TCP 需要 0.133 s
Domain Socket 需要 0.064 s

CPU: Intel(R) Xeon(R) CPU           E5405  @ 2.00GHz (1995.01-MHz 686-class CPU)
real memory  = 3220992000 (3071 MB)
TCP 需要 0.130 s
Domain Socket 需要 0.062 s

测试程序
----------------------------- tcpsvr.py --------------------------------
# vim: tabstop=4 expandtab :

import time, sys
from twisted.internet.protocol import Factory
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
from twisted.python import log

class MyTCPProto(LineReceiver):
    def lineReceived(self, line):
        if line == "profile_start":
            self.factory.start_time = time.time()
            log.msg("start: %f" % self.factory.start_time)
        elif line == "profile_end":
            end_time = time.time()
            log.msg("end: %f, delta: %f" % (end_time, end_time - self.factory.start_time))

        # do nothing

class MyTCPFactory(Factory):
    protocol = MyTCPProto

log.startLogging(sys.stdout)

f = MyTCPFactory()
reactor.listenTCP(2100, f, interface="127.0.0.1")
# reactor.listenUNIX("/tmp/foobar", f)
reactor.run()
---------------------------- tcpcli.py ---------------------------------
# vim: tabstop=4 expandtab :

from twisted.internet import reactor, protocol

class MyTCPProto(protocol.Protocol):
    def connectionMade(self):
        self.transport.write("profile_start\r\n")
        data = ("a"*128 + "\r\n") * 1024 * 8
        self.transport.write(data)
        self.transport.write("profile_end\r\n")

class MyTCPFactory(protocol.ClientFactory):
    protocol = MyTCPProto

f = MyTCPFactory()
reactor.connectTCP("127.0.0.1", 2100, f)
# reactor.connectUNIX("/tmp/foobar", f)
reactor.run()
-------------------------------------------------------------------------

结论
对于数据量不大的情况下,还是足够了的。
  评论这张
 
阅读(2638)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018