From 40519e9ee147044c09e50bad10b6d21ada61416e Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Wed, 30 Jul 2014 14:54:18 +0800 Subject: [PATCH] add response test mode --- lualib/skynet.lua | 17 +++++++++++++++++ test/testecho.lua | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 test/testecho.lua diff --git a/lualib/skynet.lua b/lualib/skynet.lua index a5d2caf5..f0f7d74c 100644 --- a/lualib/skynet.lua +++ b/lualib/skynet.lua @@ -178,6 +178,23 @@ function suspend(co, result, command, param, size) end local f = param local function response(ok, ...) + if ok == "TEST" then + if dead_service[co_address] then + release_watching(co_address) + f = false + return false + else + return true + end + end + if not f then + if f == false then + f = nil + return false + end + error "Can't response more than once" + end + local ret if not dead_service[co_address] then if ok then diff --git a/test/testecho.lua b/test/testecho.lua new file mode 100644 index 00000000..a6b265ef --- /dev/null +++ b/test/testecho.lua @@ -0,0 +1,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