Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
new-socketemulator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李远洪
new-socketemulator
Commits
c4fd6987
Commit
c4fd6987
authored
Mar 13, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
周末备份提交
parent
a6ee3ca6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
6 deletions
+12
-6
lib/multiThread/SendMultMsgThread_m500.py
lib/multiThread/SendMultMsgThread_m500.py
+12
-6
No files found.
lib/multiThread/SendMultMsgThread_m500.py
View file @
c4fd6987
...
...
@@ -18,17 +18,19 @@ class SendMultMsgThread():
self
.
msg
=
msg
self
.
timeOut
=
30
#socket超时时间
self
.
BUF_SIZE
=
1024
#接收消息缓存
self
.
threadCount
=
6
000
#并发线程数
self
.
threadCount
=
7
000
#并发线程数
self
.
totalTime
=
0
#所有线程的运行总和
self
.
threadArr
=
{}
#保存每个线程的信息
self
.
failThreadCount
=
0
#失败线程数
self
.
durThreads
=
[]
#持续发送线程数组,当数组为空,表示所有线程已经结束
self
.
durTime
=
120
#线程持续时间
dt
=
1
*
30
*
60
self
.
durTime
=
dt
#线程持续时间
self
.
connectTimeoutNum
=
0
#连接超时线程数
self
.
sendTimeoutNum
=
0
#发送超时线程数
self
.
reviceTimeoutNum
=
0
#接收超时线程数
self
.
sucessNum
=
0
#成功线程数
self
.
messageCon
=
[]
#用来统计每个线程所发的消息数
self
.
messageCons
=
0
# 用来统计每个线程所发的消息数
pass
############################################
...
...
@@ -119,6 +121,7 @@ class SendMultMsgThread():
try
:
client
.
send
(
binascii
.
a2b_hex
(
msg
))
msgCon
=
msgCon
+
1
self
.
messageCons
=
self
.
messageCons
+
1
except
BaseException
as
e
:
client
.
close
()
self
.
durThreads
.
remove
(
threadName
)
...
...
@@ -188,9 +191,9 @@ class SendMultMsgThread():
def
startThreadContinuous
(
self
):
timeStart
=
int
(
time
.
time
()
*
1000
)
for
i
in
range
(
0
,
self
.
threadCount
):
threadName
=
"thread-"
+
str
(
i
)
threadName
=
"thread-"
+
str
(
31500
+
i
)
print
(
threadName
)
carid
=
201912000000
+
i
carid
=
201912000000
+
i
+
31500
theThread
=
threading
.
Thread
(
target
=
self
.
sendMsgContinuous
,
args
=
(
carid
,
threadName
,))
# 数据写死,心跳
threadInfo
=
{}
threadInfo
[
"name"
]
=
threadName
...
...
@@ -201,8 +204,10 @@ class SendMultMsgThread():
timeExpend
=
timeEnd
-
timeStart
print
(
"耗时:"
+
str
(
timeExpend
)
+
" 毫秒产生了"
+
str
(
self
.
threadCount
)
+
"线程"
)
time
.
sleep
(
0.5
)
#防止启动的时候溜掉某些启动比较慢的线程
tmp
=
1
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
)
testStart
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
timeArray
)
timeCur
=
int
(
time
.
time
()
*
1000
)
...
...
@@ -218,8 +223,9 @@ class SendMultMsgThread():
info_9
=
"发送失败:"
+
str
(
self
.
sendTimeoutNum
)
info_10
=
"接收失败:"
+
str
(
self
.
reviceTimeoutNum
)
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
=
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
)
time
.
sleep
(
5
)
timeArray
=
time
.
localtime
(
timeStart
/
1000
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment