Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 带Autobahn Testsuite的Websocket应力测试_Python 2.7_Websocket_Autobahn - Fatal编程技术网

Python 2.7 带Autobahn Testsuite的Websocket应力测试

Python 2.7 带Autobahn Testsuite的Websocket应力测试,python-2.7,websocket,autobahn,Python 2.7,Websocket,Autobahn,我尝试对我的websocket服务器进行一些压力测试。在客户端,我运行以下脚本: 导入时间,系统 从twisted.internet导入延迟,反应器 从twisted.internet.defer导入Deferred、returnValue、inlineCallbacks 从autobahn.twisted.websocket导入connectWS\ WebSocketClientFactory\ WebSocketClientProtocol 类MassConnectProtocol(WebS

我尝试对我的websocket服务器进行一些压力测试。在客户端,我运行以下脚本:

导入时间,系统 从twisted.internet导入延迟,反应器 从twisted.internet.defer导入Deferred、returnValue、inlineCallbacks 从autobahn.twisted.websocket导入connectWS\ WebSocketClientFactory\ WebSocketClientProtocol 类MassConnectProtocol(WebSocketClientProtocol): 握手=假 def onOpen(自我): 打印(“websocket连接已打开”) self.factory.test.onConnected() self.factory.test.protos.append(self) self.didHandshake=True 类别MassConnectFactory(WebSocketClientFactory): 协议=MassConnectProtocol def客户端连接失败(自身、连接器、原因): 如果self.test.onFailed(): reactor.callLater(浮动(自恢复延迟)/1000,连接器连接) def clientConnectionLost(自身、连接器、原因): 如果self.test.onLost(): reactor.callLater(浮动(自恢复延迟)/1000,连接器连接) MassConnect类: def u uu init uuuuuu(self、name、uri、connections、batchsize、batchdelay、retrydelay): 打印('MassConnect init') self.name=名称 self.uri=uri self.batchsize=batchsize self.batchdelay=batchdelay self.retrydelay=retrydelay self.failed=0 self.lost=0 self.targetCnt=连接 self.currentCnt=0 self.actual=0 self.protos=[] def运行(自): 打印('MassConnect已运行') self.d=延迟() self.started=time.clock() self.connectBunch() 返回自我 def onFailed(自我): self.failed+=1 sys.stdout.write(“!”) 返回真值 def onLost(自我): self.lost+=1 #sys.stdout.write(“*”) 返回错误 返回真值 def未连接(自): 打印(“未连接”) self.actual+=1 如果self.actual%self.batchsize==0: 系统标准写入(“.”) 如果self.actual==self.targetCnt: self.end=time.clock() 持续时间=自结束-自开始 打印“在%s秒内将%d个客户端连接到%s(重试%d=失败%d+丢失%d)”%(self.currentCnt、self.name、self.uri、duration、self.failed+self.lost、self.failed、self.lost) 结果={'name':self.name, 'uri':self.uri, “连接”:self.targetCnt, “重试”:self.failed+self.lost, “迷失”:自我迷失, “失败”:self.failed, “持续时间”:持续时间} 对于self.protos中的p: p、 sendClose() #self.d.callback(结果) def连接束(自身): 如果self.currentCnt+self.batchsize 但是在运行此脚本之后,服务器端没有建立任何连接。服务器似乎配置正确,因为当我使用不同的客户端(例如web浏览器)连接到服务器时,它工作正常,并且建立了websocket连接。我还检查了网络嗅探器,似乎该脚本不生成任何websocket连接。
我在这个脚本中做错了什么?

您使用的
massconnect.py
脚本应该从autobahntestsuite的另一部分调用,例如
wstest
命令:

$ echo '{"servers": [{"name": "test", "uri":"ws://127.0.0.1:8080"} ], "options": {"connections": 1000,"batchsize": 500, "batchdelay": 1000, "retrydelay": 200 }}' > spec.json
$ wstest -m massconnect --spec spec.json
如果要直接复制
massconnect
,我认为它缺少启动任务的命令:

if __name__ == '__main__':
  spec = {}
  spec['servers'] = [{'name': 'test', 'uri':"ws://127.0.0.1:8080"} ]
  spec['options'] ={'connections': 1000,'batchsize': 500, 'batchdelay': 1000, 'retrydelay': 200 }
  startClient(spec,False)
  reactor.run() # <-- add this
如果uuuu name_uuuu=='\uuuuuuu main\uuuuuu':
spec={}
spec['servers']=[{'name':'test','uri':“ws://127.0.0.1:8080”}]
spec['options']={'connections':1000,'batchsize':500,'batchdelay':1000,'retrydelay':200}
startClient(规范,错误)

reactor.run()#thx寻求帮助和时间。添加这一行后,它现在可以工作了
reactor.run()
if __name__ == '__main__':
  spec = {}
  spec['servers'] = [{'name': 'test', 'uri':"ws://127.0.0.1:8080"} ]
  spec['options'] ={'connections': 1000,'batchsize': 500, 'batchdelay': 1000, 'retrydelay': 200 }
  startClient(spec,False)
  reactor.run() # <-- add this