我想同时模拟数千个客户端与我的服务器的连接,看看它是否可以处理它?我只是想使用我的iPhone和iPhone模拟器来创建连接,但它不是实时模拟。我该如何进行负载测试?
以下是我的服务器代码示例:
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import defer
class STSFactory(Factory):
def __init__(self,conn):
self.conn = conn
self.protocol = STSProtocol
class STSProtocol(Protocol):
def log(self, message):
print "%s: %s" % (self, message)
def connectionMade(self):
self.log("Connection made")
def connectionLost(self, reason):
self.factory.clients.remove(self)
self.log("Connection Lost")
@defer.inlineCallbacks
def getUser(self,user):
val = yield self.factory.conn.hgetall("user:%s"%user)
def dataReceived(self, data):
cmd = data.split(':')
command = cmd[0]
arg1 = cmd[1]
arg2 = cmd[2]
if arg1 == "logon":
self.getUser(arg2)
if __name__ == '__main__':
from twisted.internet import reactor
import redis
conn = redis.Redis(unix_socket_path='/tmp/redis.sock')
factory = STSFactory(conn)
factory.clients = []
print "Server started"
reactor.listenTCP(11000,factory)
reactor.listenTCP(11001,factory)
reactor.listenTCP(11002,factory)
reactor.run()
答案 0 :(得分:3)
有一个很棒的负载测试工具,名为Locust。您可以在python中编写测试场景,它可以扩展,甚至可以根据需要使用基于Web的GUI。
答案 1 :(得分:1)
托管服务器的方式和位置?在一个简单的例子中,您可以使用本地计算机中的Siege(围攻将成为大多数请求的网址)http://www.joedog.org/index/siege-home
您还可以使用Blitz.io http://blitz.io/等服务,然后可以从不同的地理区域加载服务(这会对性能产生巨大影响)。有很多这样的服务只是搜索Web负载测试。我喜欢闪电战,因为我使用Heroku并且它很好地与它集成。