Commit c4fd6987 authored by liyuanhong's avatar liyuanhong

周末备份提交

parent a6ee3ca6
...@@ -18,17 +18,19 @@ class SendMultMsgThread(): ...@@ -18,17 +18,19 @@ class SendMultMsgThread():
self.msg = msg self.msg = msg
self.timeOut = 30 #socket超时时间 self.timeOut = 30 #socket超时时间
self.BUF_SIZE = 1024 #接收消息缓存 self.BUF_SIZE = 1024 #接收消息缓存
self.threadCount = 6000 #并发线程数 self.threadCount = 7000 #并发线程数
self.totalTime = 0 #所有线程的运行总和 self.totalTime = 0 #所有线程的运行总和
self.threadArr = {} #保存每个线程的信息 self.threadArr = {} #保存每个线程的信息
self.failThreadCount = 0 #失败线程数 self.failThreadCount = 0 #失败线程数
self.durThreads = [] #持续发送线程数组,当数组为空,表示所有线程已经结束 self.durThreads = [] #持续发送线程数组,当数组为空,表示所有线程已经结束
self.durTime = 120 #线程持续时间 dt = 1 * 30 * 60
self.durTime = dt #线程持续时间
self.connectTimeoutNum = 0 #连接超时线程数 self.connectTimeoutNum = 0 #连接超时线程数
self.sendTimeoutNum = 0 #发送超时线程数 self.sendTimeoutNum = 0 #发送超时线程数
self.reviceTimeoutNum = 0 #接收超时线程数 self.reviceTimeoutNum = 0 #接收超时线程数
self.sucessNum = 0 #成功线程数 self.sucessNum = 0 #成功线程数
self.messageCon = [] #用来统计每个线程所发的消息数 self.messageCon = [] #用来统计每个线程所发的消息数
self.messageCons = 0 # 用来统计每个线程所发的消息数
pass pass
############################################ ############################################
...@@ -119,6 +121,7 @@ class SendMultMsgThread(): ...@@ -119,6 +121,7 @@ class SendMultMsgThread():
try: try:
client.send(binascii.a2b_hex(msg)) client.send(binascii.a2b_hex(msg))
msgCon = msgCon + 1 msgCon = msgCon + 1
self.messageCons = self.messageCons + 1
except BaseException as e: except BaseException as e:
client.close() client.close()
self.durThreads.remove(threadName) self.durThreads.remove(threadName)
...@@ -188,9 +191,9 @@ class SendMultMsgThread(): ...@@ -188,9 +191,9 @@ class SendMultMsgThread():
def startThreadContinuous(self): def startThreadContinuous(self):
timeStart = int(time.time() * 1000) timeStart = int(time.time() * 1000)
for i in range(0,self.threadCount): for i in range(0,self.threadCount):
threadName = "thread-" + str(i) threadName = "thread-" + str(31500 + i)
print(threadName) print(threadName)
carid = 201912000000 + i carid = 201912000000 + i + 31500
theThread = threading.Thread(target=self.sendMsgContinuous, args=(carid,threadName,)) # 数据写死,心跳 theThread = threading.Thread(target=self.sendMsgContinuous, args=(carid,threadName,)) # 数据写死,心跳
threadInfo = {} threadInfo = {}
threadInfo["name"] = threadName threadInfo["name"] = threadName
...@@ -201,8 +204,10 @@ class SendMultMsgThread(): ...@@ -201,8 +204,10 @@ class SendMultMsgThread():
timeExpend = timeEnd - timeStart timeExpend = timeEnd - timeStart
print("耗时:" + str(timeExpend) + " 毫秒产生了" + str(self.threadCount) + "线程") print("耗时:" + str(timeExpend) + " 毫秒产生了" + str(self.threadCount) + "线程")
time.sleep(0.5) #防止启动的时候溜掉某些启动比较慢的线程 time.sleep(0.5) #防止启动的时候溜掉某些启动比较慢的线程
tmp = 1
while len(self.durThreads) != 0: while len(self.durThreads) != 0:
print("剩余线程数:" + str(len(self.durThreads))) print("剩余线程数_" + str(tmp) + ":" + str(len(self.durThreads)))
tmp = tmp + 1
timeArray = time.localtime(timeStart / 1000) timeArray = time.localtime(timeStart / 1000)
testStart = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) testStart = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
timeCur = int(time.time() * 1000) timeCur = int(time.time() * 1000)
...@@ -218,8 +223,9 @@ class SendMultMsgThread(): ...@@ -218,8 +223,9 @@ class SendMultMsgThread():
info_9 = "发送失败:" + str(self.sendTimeoutNum) info_9 = "发送失败:" + str(self.sendTimeoutNum)
info_10 = "接收失败:" + str(self.reviceTimeoutNum) info_10 = "接收失败:" + str(self.reviceTimeoutNum)
info_11 = "当前写入时间:" + testCur info_11 = "当前写入时间:" + testCur
info_12 = "当前发送消息总数:" + str(self.messageCons)
result = info_0 + "\n" + info_1 + "\n" + info_2 + "\n" + info_4 + "\n" + info_5 + "\n" + info_6 + "\n" result = info_0 + "\n" + info_1 + "\n" + info_2 + "\n" + info_4 + "\n" + info_5 + "\n" + info_6 + "\n"
result = result + info_8 + "\n" + info_9 + "\n" + info_10 + "\n" + info_11 + "\n" result = result + info_8 + "\n" + info_9 + "\n" + info_10 + "\n" + info_11 + "\n" + info_12 + "\n"
self.writeToFile("./result_pre.txt",result) self.writeToFile("./result_pre.txt",result)
time.sleep(5) time.sleep(5)
timeArray = time.localtime(timeStart / 1000) timeArray = time.localtime(timeStart / 1000)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment