forked from cloudwu/skynet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestecho.lua
44 lines (35 loc) · 815 Bytes
/
testecho.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local skynet = require "skynet"
local mode = ...
if mode == "slave" then
skynet.start(function()
skynet.dispatch("lua", function(_,_, ...)
skynet.ret(skynet.pack(...))
end)
end)
else
skynet.start(function()
local slave = skynet.newservice(SERVICE_NAME, "slave")
local n = 100000
local start = skynet.now()
print("call salve", n, "times in queue")
for i=1,n do
skynet.call(slave, "lua")
end
print("qps = ", n/ (skynet.now() - start) * 100)
start = skynet.now()
local worker = 10
local task = n/worker
print("call salve", n, "times in parallel, worker = ", worker)
for i=1,worker do
skynet.fork(function()
for i=1,task do
skynet.call(slave, "lua")
end
worker = worker -1
if worker == 0 then
print("qps = ", n/ (skynet.now() - start) * 100)
end
end)
end
end)
end