Commit 3a646deaf18d32a8152cfb93a5f45eaae9601cf0

Authored by zhouhaihai
1 parent a7de05c2

拆分网关

robot/robot.conf
1 1 root = "./"
2   -thread = 8
  2 +thread = 4
3 3 logger = nil
4 4 harbor = 0
5   -start = "start" -- main script
  5 +start = "robot_main" -- main script
6 6 bootstrap = "snlua bootstrap" -- The service for bootstrap
7 7  
8 8 lua_path = root .."skynet/lualib/?.lua;"..root.."robot/?.lua;"..root.."src/?.lua"
... ...
robot/robot_main.lua 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +local skynet = require "skynet"
  2 +local config = require "robot_config"
  3 +
  4 +local preOnlineCount = 10
  5 +
  6 +
  7 +skynet.start(function()
  8 + local need = math.ceil(config.online / preOnlineCount)
  9 + local inpre = math.ceil(config.inpre / need)
  10 + local idRange = math.ceil(config.max / need)
  11 + local curId = 1
  12 + for i = 1, need do
  13 + skynet.newservice("start", preOnlineCount, curId, curId + idRange - 1, inpre)
  14 + curId = curId + idRange
  15 + end
  16 + skynet.exit()
  17 +end)
0 18 \ No newline at end of file
... ...
robot/start.lua
... ... @@ -7,11 +7,17 @@ local netpack = require "skynet.netpack"
7 7 local socketdriver = require "skynet.socketdriver"
8 8 local string_format = string.format
9 9  
  10 +local onlineCount, startId, endId, inpre = ...
  11 +onlineCount = tonumber(onlineCount)
  12 +startId = tonumber(startId)
  13 +endId = tonumber(endId)
  14 +inpre = tonumber(inpre)
  15 +
10 16 local queue = {}
11 17 local fd2serv = {}
12 18 local id2fd = {}
13 19 local MSG = {}
14   -local id_max = 0 -- robot id
  20 +local id_max = startId - 1 -- robot id
15 21  
16 22  
17 23 function MSG.open( ... )
... ... @@ -76,9 +82,9 @@ local function add_robot()
76 82 local fd = socketdriver.connect(config.host, config.port)
77 83 socketdriver.start(fd)
78 84 local id
79   - if id_max >= config.max then
  85 + if id_max >= endId then
80 86 while true do
81   - id = math.randomInt(1, config.max)
  87 + id = math.randomInt(startId, endId)
82 88 if not id2fd[id] then
83 89 break
84 90 end
... ... @@ -89,7 +95,7 @@ local function add_robot()
89 95 end
90 96 fd2serv[fd] = {agent = robot, id = id}
91 97 id2fd[id] = fd
92   - pcall(skynet.call, robot, "lua", "start", fd, id)
  98 + pcall(skynet.call, robot, "lua", "start", fd, id, prefix)
93 99 log(string_format("login %s", fd2serv[fd].id))
94 100  
95 101 -- 定时下线
... ... @@ -106,8 +112,8 @@ local function online()
106 112 end
107 113  
108 114 -- 及时补充人数
109   - if curCount < config.online then
110   - for i = curCount + 1, config.online do
  115 + if curCount < onlineCount then
  116 + for i = curCount + 1, onlineCount do
111 117 add_robot()
112 118 end
113 119 end
... ... @@ -119,8 +125,8 @@ end
119 125 local function start()
120 126 log("start testing ...")
121 127  
122   - for i = 1, config.online, config.inpre do
123   - for j = 1, config.inpre do
  128 + for i = 1, onlineCount, inpre do
  129 + for j = 1, inpre do
124 130 add_robot()
125 131 end
126 132 skynet.sleep(100)
... ...
robot/unitTest/item.lua
... ... @@ -14,7 +14,7 @@ end
14 14 local taskMap = {
15 15 saleItem = {100},
16 16 openItem = {100},
17   - openTimeBox = {100},
  17 + -- openTimeBox = {100},
18 18 }
19 19  
20 20 function _M:task()
... ...