Commit 3f604f2e3e304ecede4626a554528ab3473d437f
1 parent
1b6307bc
扩容 redis 和 log服务
Showing
13 changed files
with
68 additions
and
44 deletions
Show diff stats
src/agent.lua
@@ -356,11 +356,6 @@ skynet.start(function() | @@ -356,11 +356,6 @@ skynet.start(function() | ||
356 | return info | 356 | return info |
357 | end) | 357 | end) |
358 | 358 | ||
359 | - redisd = skynet.localname(".redis") | ||
360 | - if tonumber(skynet.getenv "logd") == 1 then | ||
361 | - logd = skynet.localname(".log") | ||
362 | - end | ||
363 | - | ||
364 | cs = queue() | 359 | cs = queue() |
365 | 360 | ||
366 | pvpd = skynet.localname(".pvpcross") | 361 | pvpd = skynet.localname(".pvpcross") |
src/main.lua
@@ -2,23 +2,41 @@ local skynet = require "skynet" | @@ -2,23 +2,41 @@ local skynet = require "skynet" | ||
2 | 2 | ||
3 | local max_client = tonumber(skynet.getenv("max_client")) | 3 | local max_client = tonumber(skynet.getenv("max_client")) |
4 | local max_queue = tonumber(skynet.getenv("max_queue")) | 4 | local max_queue = tonumber(skynet.getenv("max_queue")) |
5 | +local work_count = tonumber(skynet.getenv("thread")) | ||
6 | +local use_logd = tonumber(skynet.getenv("logd")) | ||
5 | 7 | ||
6 | skynet.start(function() | 8 | skynet.start(function() |
7 | print("Server start") | 9 | print("Server start") |
8 | skynet.newservice("debug_console", tonumber(skynet.getenv("debug_port"))) | 10 | skynet.newservice("debug_console", tonumber(skynet.getenv("debug_port"))) |
9 | 11 | ||
12 | + | ||
13 | + -- 启动redis | ||
14 | + for i = 1, work_count do | ||
15 | + local redisd = skynet.newservice("services/redisd", i) | ||
16 | + skynet.call(redisd, "lua", "open", { | ||
17 | + redishost = skynet.getenv("redis_host"), | ||
18 | + redisport = tonumber(skynet.getenv("redis_port")), | ||
19 | + redisdb = tonumber(skynet.getenv("redis_db")), | ||
20 | + auth = skynet.getenv("redis_auth") | ||
21 | + }) | ||
22 | + end | ||
23 | + | ||
24 | + --启动log | ||
25 | + if use_logd == 1 then | ||
26 | + for i = 1, work_count do | ||
27 | + local logd = skynet.newservice("services/logd", i) | ||
28 | + skynet.call(logd, "lua", "open") | ||
29 | + end | ||
30 | + end | ||
31 | + | ||
10 | local httpd = skynet.newservice("services/httpweb", tonumber(skynet.getenv("httpweb_port"))) | 32 | local httpd = skynet.newservice("services/httpweb", tonumber(skynet.getenv("httpweb_port"))) |
11 | local watchdog = skynet.newservice("services/watchdog", max_client) | 33 | local watchdog = skynet.newservice("services/watchdog", max_client) |
12 | 34 | ||
35 | + | ||
13 | skynet.call(watchdog, "lua", "start", { | 36 | skynet.call(watchdog, "lua", "start", { |
14 | port = tonumber(skynet.getenv("server_port")), | 37 | port = tonumber(skynet.getenv("server_port")), |
15 | maxclient = max_client + max_queue + 10, | 38 | maxclient = max_client + max_queue + 10, |
16 | httpd = httpd, | 39 | httpd = httpd, |
17 | - | ||
18 | - redishost = skynet.getenv("redis_host"), | ||
19 | - redisport = tonumber(skynet.getenv("redis_port")), | ||
20 | - redisdb = tonumber(skynet.getenv("redis_db")), | ||
21 | - auth = skynet.getenv("redis_auth"), | ||
22 | }) | 40 | }) |
23 | 41 | ||
24 | skynet.exit() | 42 | skynet.exit() |
src/models/RoleLog.lua
1 | local serverId = skynet.getenv("servId") | 1 | local serverId = skynet.getenv("servId") |
2 | local server_id = (skynet.getenv("serverType") or "localtest") .. "_" .. serverId | 2 | local server_id = (skynet.getenv("serverType") or "localtest") .. "_" .. serverId |
3 | +local logproxy = require "shared.logproxy" | ||
3 | 4 | ||
4 | --[[ | 5 | --[[ |
5 | 100 购买/兑换行为 | 6 | 100 购买/兑换行为 |
@@ -765,8 +766,7 @@ function RoleLog.bind(Role) | @@ -765,8 +766,7 @@ function RoleLog.bind(Role) | ||
765 | end | 766 | end |
766 | end | 767 | end |
767 | end | 768 | end |
768 | - if not logd then return end | ||
769 | - pcall(skynet.send, logd, "lua", "log", doc, "bi") | 769 | + logproxy:log(doc, "bi") |
770 | end | 770 | end |
771 | 771 | ||
772 | function Role:logItems(itemId, before, after, log) | 772 | function Role:logItems(itemId, before, after, log) |
@@ -825,8 +825,7 @@ function RoleLog.bind(Role) | @@ -825,8 +825,7 @@ function RoleLog.bind(Role) | ||
825 | end | 825 | end |
826 | end | 826 | end |
827 | doc["@type"] = logType | 827 | doc["@type"] = logType |
828 | - if not logd then return end | ||
829 | - pcall(skynet.send, logd, "lua", "log", doc, "log") | 828 | + logproxy:log(doc, "log") |
830 | end | 829 | end |
831 | 830 | ||
832 | 831 |
src/services/agent_ctrl.lua
@@ -6,6 +6,7 @@ local xxtea = require "xxtea" | @@ -6,6 +6,7 @@ local xxtea = require "xxtea" | ||
6 | local deque = require "deque" | 6 | local deque = require "deque" |
7 | local datacenter = require "skynet.datacenter" | 7 | local datacenter = require "skynet.datacenter" |
8 | local agent_queued = require "services.agent_queued" | 8 | local agent_queued = require "services.agent_queued" |
9 | +local logproxy = require "shared.logproxy" | ||
9 | 10 | ||
10 | local pcall = pcall | 11 | local pcall = pcall |
11 | local string_format = string.format | 12 | local string_format = string.format |
@@ -139,11 +140,11 @@ function _M:check_agent_status() | @@ -139,11 +140,11 @@ function _M:check_agent_status() | ||
139 | end | 140 | end |
140 | end | 141 | end |
141 | 142 | ||
142 | - if now >= next_log_time and now % 60 == 0 and logd then | 143 | + if now >= next_log_time and now % 60 == 0 then |
143 | next_log_time = now + 60 | 144 | next_log_time = now + 60 |
144 | local count = table_nums(self.u2f) | 145 | local count = table_nums(self.u2f) |
145 | datacenter.set("onlineCount", count) | 146 | datacenter.set("onlineCount", count) |
146 | - pcall(skynet.send, logd, "lua", "log", {["@type"] = "online", count = count}, "log") | 147 | + logproxy:log({["@type"] = "online", count = count}, "log") |
147 | end | 148 | end |
148 | end | 149 | end |
149 | 150 |
src/services/dbseed.lua
@@ -34,8 +34,6 @@ local steps = { | @@ -34,8 +34,6 @@ local steps = { | ||
34 | } | 34 | } |
35 | 35 | ||
36 | skynet.start(function () | 36 | skynet.start(function () |
37 | - redisd = skynet.localname(".redis") | ||
38 | - | ||
39 | redisproxy = require("shared.redisproxy") | 37 | redisproxy = require("shared.redisproxy") |
40 | 38 | ||
41 | local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1 | 39 | local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1 |
src/services/globald.lua
src/services/httpweb.lua
@@ -53,12 +53,8 @@ end | @@ -53,12 +53,8 @@ end | ||
53 | local CMD = require "actions.HttpAction" | 53 | local CMD = require "actions.HttpAction" |
54 | 54 | ||
55 | local function start() | 55 | local function start() |
56 | - redisd = skynet.localname(".redis") | ||
57 | globalCsv = csvdb["GlobalDefineCsv"] | 56 | globalCsv = csvdb["GlobalDefineCsv"] |
58 | 57 | ||
59 | - if tonumber(skynet.getenv "logd") == 1 then | ||
60 | - logd = skynet.localname(".log") | ||
61 | - end | ||
62 | 58 | ||
63 | local listen_socket = socket.listen("0.0.0.0", port) | 59 | local listen_socket = socket.listen("0.0.0.0", port) |
64 | print("Listen web port " .. port) | 60 | print("Listen web port " .. port) |
src/services/logd.lua
@@ -2,12 +2,12 @@ local skynet = require "skynet" | @@ -2,12 +2,12 @@ local skynet = require "skynet" | ||
2 | local queue = require "skynet.queue" | 2 | local queue = require "skynet.queue" |
3 | local bson = require "bson" | 3 | local bson = require "bson" |
4 | local socketdriver = require "skynet.socketdriver" | 4 | local socketdriver = require "skynet.socketdriver" |
5 | - | ||
6 | local serverId = tonumber(skynet.getenv("servId")) | 5 | local serverId = tonumber(skynet.getenv("servId")) |
7 | 6 | ||
8 | require "shared.init" | 7 | require "shared.init" |
9 | require "skynet.manager" | 8 | require "skynet.manager" |
10 | 9 | ||
10 | +local logdIdx = ... | ||
11 | local table_insert = table.insert | 11 | local table_insert = table.insert |
12 | local pairs = pairs | 12 | local pairs = pairs |
13 | local ipairs = ipairs | 13 | local ipairs = ipairs |
@@ -15,6 +15,7 @@ local string_format = string.format | @@ -15,6 +15,7 @@ local string_format = string.format | ||
15 | 15 | ||
16 | local logId = 0 | 16 | local logId = 0 |
17 | local CMD, cs = {} | 17 | local CMD, cs = {} |
18 | +local prefix = "wasteland" .. logdIdx .. "S" .. serverId .. "C" | ||
18 | 19 | ||
19 | local logHandle = { | 20 | local logHandle = { |
20 | bi = { | 21 | bi = { |
@@ -33,7 +34,7 @@ local logHandle = { | @@ -33,7 +34,7 @@ local logHandle = { | ||
33 | doc["game_name"] = "wasteland" | 34 | doc["game_name"] = "wasteland" |
34 | doc["env"] = "cb" | 35 | doc["env"] = "cb" |
35 | doc["game_name_type"] = "guaji" | 36 | doc["game_name_type"] = "guaji" |
36 | - doc["log_id"] = "wastelandC" .. logId .. "S" .. serverId .. "T" .. now | 37 | + doc["log_id"] = prefix .. logId .. "T" .. now |
37 | logId = (logId + 1) % 10000000 | 38 | logId = (logId + 1) % 10000000 |
38 | end | 39 | end |
39 | }, | 40 | }, |
@@ -135,7 +136,7 @@ local function __init__() | @@ -135,7 +136,7 @@ local function __init__() | ||
135 | end) | 136 | end) |
136 | cs = queue() | 137 | cs = queue() |
137 | 138 | ||
138 | - skynet.register(".log") | 139 | + skynet.register(".logd" .. logdIdx) |
139 | end | 140 | end |
140 | 141 | ||
141 | skynet.start(__init__) | 142 | skynet.start(__init__) |
src/services/pvpd.lua
@@ -289,7 +289,6 @@ end | @@ -289,7 +289,6 @@ end | ||
289 | 289 | ||
290 | ------------------------------------------------------ | 290 | ------------------------------------------------------ |
291 | function CMD.start() | 291 | function CMD.start() |
292 | - redisd = skynet.localname(".redis") | ||
293 | globalCsv = csvdb["GlobalDefineCsv"] | 292 | globalCsv = csvdb["GlobalDefineCsv"] |
294 | 293 | ||
295 | pvpInfo = require("models.Pvpd").new({key = "cross:pvpInfo"}) | 294 | pvpInfo = require("models.Pvpd").new({key = "cross:pvpInfo"}) |
src/services/redisd.lua
@@ -3,7 +3,7 @@ require "skynet.manager" | @@ -3,7 +3,7 @@ require "skynet.manager" | ||
3 | local redis = require "skynet.db.redis" | 3 | local redis = require "skynet.db.redis" |
4 | 4 | ||
5 | local db | 5 | local db |
6 | - | 6 | +local idx = ... |
7 | local command = {} | 7 | local command = {} |
8 | 8 | ||
9 | function command.open(conf) | 9 | function command.open(conf) |
@@ -27,5 +27,5 @@ skynet.start(function() | @@ -27,5 +27,5 @@ skynet.start(function() | ||
27 | skynet.info_func(function() | 27 | skynet.info_func(function() |
28 | return skynet.stat("mqlen") | 28 | return skynet.stat("mqlen") |
29 | end) | 29 | end) |
30 | - skynet.register ".redis" | 30 | + skynet.register(".redis" .. idx) |
31 | end) | 31 | end) |
32 | \ No newline at end of file | 32 | \ No newline at end of file |
src/services/watchdog.lua
1 | local skynet = require "skynet" | 1 | local skynet = require "skynet" |
2 | require "skynet.manager" | 2 | require "skynet.manager" |
3 | -local redisproxy = require "shared.redisproxy" | ||
4 | local socket = require "skynet.socket" | 3 | local socket = require "skynet.socket" |
5 | local netpack = require "skynet.netpack" | 4 | local netpack = require "skynet.netpack" |
6 | local datacenter = require "skynet.datacenter" | 5 | local datacenter = require "skynet.datacenter" |
@@ -47,7 +46,7 @@ function SOCKET.data(fd, msg) | @@ -47,7 +46,7 @@ function SOCKET.data(fd, msg) | ||
47 | end | 46 | end |
48 | end | 47 | end |
49 | 48 | ||
50 | -local use_logd = tonumber(skynet.getenv "logd") | 49 | + |
51 | 50 | ||
52 | -- @desc: agent状态定时检测 | 51 | -- @desc: agent状态定时检测 |
53 | function check_agent_status() | 52 | function check_agent_status() |
@@ -65,11 +64,7 @@ end | @@ -65,11 +64,7 @@ end | ||
65 | 64 | ||
66 | function CMD.start(conf) | 65 | function CMD.start(conf) |
67 | skynet.call(gate_serv, "lua", "open" , conf) | 66 | skynet.call(gate_serv, "lua", "open" , conf) |
68 | - skynet.call(redisd, "lua", "open", conf) | ||
69 | - | ||
70 | - if use_logd == 1 then | ||
71 | - skynet.call(logd, "lua", "open") | ||
72 | - end | 67 | + |
73 | skynet.call(pvpd, "lua", "start") | 68 | skynet.call(pvpd, "lua", "start") |
74 | -- 开启agent状态检测定时器 | 69 | -- 开启agent状态检测定时器 |
75 | check_agent_status() | 70 | check_agent_status() |
@@ -110,17 +105,11 @@ skynet.start(function() | @@ -110,17 +105,11 @@ skynet.start(function() | ||
110 | end | 105 | end |
111 | end) | 106 | end) |
112 | skynet.register ".watchdog" | 107 | skynet.register ".watchdog" |
113 | - -- 数据库服务 | ||
114 | - redisd = skynet.newservice("services/redisd") | ||
115 | 108 | ||
116 | -- 提前加载好 | 109 | -- 提前加载好 |
117 | csvdata.init() | 110 | csvdata.init() |
118 | print("launch csvdatad ...") | 111 | print("launch csvdatad ...") |
119 | 112 | ||
120 | - -- 日志服务 | ||
121 | - if use_logd == 1 then | ||
122 | - logd = skynet.newservice("services/logd") | ||
123 | - end | ||
124 | -- pvp 服务 | 113 | -- pvp 服务 |
125 | pvpd = skynet.newservice("services/pvpd") | 114 | pvpd = skynet.newservice("services/pvpd") |
126 | cluster.register("pvpd", pvpd) | 115 | cluster.register("pvpd", pvpd) |
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | + | ||
2 | +local skynet = require "skynet" | ||
3 | +local logd_count = tonumber(skynet.getenv("thread")) | ||
4 | +local use_logd = tonumber(skynet.getenv("logd")) | ||
5 | + | ||
6 | + | ||
7 | +local logd | ||
8 | +skynet.init(function() | ||
9 | + if use_logd then | ||
10 | + local idx = math.randomInt(1, logd_count) | ||
11 | + logd = skynet.localname(".logd" .. idx) | ||
12 | + end | ||
13 | +end) | ||
14 | + | ||
15 | +local logproxy = {} | ||
16 | + | ||
17 | +function logproxy:log(doc, logTo) | ||
18 | + if use_logd and logd then | ||
19 | + pcall(skynet.send, logd, "lua", "log", doc, logTo) | ||
20 | + end | ||
21 | +end | ||
22 | + | ||
23 | +return logproxy | ||
0 | \ No newline at end of file | 24 | \ No newline at end of file |
src/shared/redisproxy.lua
1 | local skynet = require "skynet" | 1 | local skynet = require "skynet" |
2 | -local harbor = require "skynet.harbor" | 2 | +require "utils.init" |
3 | + | ||
4 | +local redisd_count = tonumber(skynet.getenv("thread")) | ||
5 | +local redisd | ||
6 | +skynet.init(function() | ||
7 | + local idx = math.randomInt(1, redisd_count) | ||
8 | + redisd = skynet.localname(".redis" .. idx) | ||
9 | +end) | ||
3 | 10 | ||
4 | local table_insert = table.insert | 11 | local table_insert = table.insert |
5 | 12 | ||
6 | local redisproxy = {} | 13 | local redisproxy = {} |
7 | 14 | ||
8 | - | ||
9 | local isUsePika = false | 15 | local isUsePika = false |
10 | 16 | ||
11 | 17 |