summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-30 00:51:53 +0800
committerruki <[email protected]>2022-07-30 00:51:53 +0800
commitf007e83c6fe3027b453e56d522a8dab15b8cd2bc (patch)
treeb7b9fbf2f500ca176ec244615de73d08d10847fe
parent0fc00866ab00a5713a3a86d449fd1fbc8250c7fc (diff)
improve distcc for cpu/mem
-rw-r--r--xmake/modules/private/service/distcc_build/client.lua11
-rw-r--r--xmake/modules/private/service/distcc_build/client_session.lua13
-rw-r--r--xmake/modules/private/service/distcc_build/server_session.lua4
3 files changed, 23 insertions, 5 deletions
diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua
index 7520be46b..bb4daf7a5 100644
--- a/xmake/modules/private/service/distcc_build/client.lua
+++ b/xmake/modules/private/service/distcc_build/client.lua
@@ -418,7 +418,10 @@ function distcc_build_client:_host_status_update(host_status)
end
host_status.running = running
host_status.freejobs = host_status.njob - host_status.running
- host_status.weight = host_status.freejobs
+ host_status.weight = host_status.freejobs * (1.0 - (host_status.cpurate or 0))
+ if host_status.memrate and host_status.memrate > 0.9 then
+ host_status.weight = host_status.weight * (1.0 - (host_status.memrate or 0))
+ end
end
-- lock host status
@@ -461,7 +464,7 @@ function distcc_build_client:_host_status_session_open(host_status)
local session = free_sessions[#free_sessions]
if session and not session:is_opened() then
table.remove(free_sessions)
- session:open()
+ session:open(host_status)
return session
end
end
@@ -472,10 +475,10 @@ function distcc_build_client:_host_status_session_open(host_status)
session = client_session(self, host_status.session_id, host_status.token, host_status.addr, host_status.port,
{send_timeout = self:send_timeout(), recv_timeout = self:recv_timeout(), connect_timeout = self:connect_timeout()})
host_status.sessions[i] = session
- session:open()
+ session:open(host_status)
return session
elseif not session:is_opened() then
- session:open()
+ session:open(host_status)
return session
end
end
diff --git a/xmake/modules/private/service/distcc_build/client_session.lua b/xmake/modules/private/service/distcc_build/client_session.lua
index d913878fa..2048531fc 100644
--- a/xmake/modules/private/service/distcc_build/client_session.lua
+++ b/xmake/modules/private/service/distcc_build/client_session.lua
@@ -100,9 +100,10 @@ function client_session:stream()
end
-- open session
-function client_session:open()
+function client_session:open(host_status)
assert(not self:is_opened(), "%s: has been opened!", self)
self._OPENED = true
+ self._HOST_STATUS = host_status
end
-- close session
@@ -115,6 +116,13 @@ function client_session:is_opened()
return self._OPENED
end
+-- get host status
+function client_session:host_status()
+ return self._HOST_STATUS
+end
+
+
+
-- run compilation job
function client_session:compile(sourcefile, objectfile, cppfile, cppflags, opt)
assert(self:is_opened(), "%s: has been not opened!", self)
@@ -128,6 +136,7 @@ function client_session:compile(sourcefile, objectfile, cppfile, cppflags, opt)
local cachekey = opt.cachekey
local toolchain = tool:toolchain():name()
local stream = self:stream()
+ local host_status = self:host_status()
local outdata, errdata
if stream:send_msg(message.new_compile(self:id(), toolname, toolkind, plat, arch, toolchain,
cppflags, path.filename(sourcefile), {token = self:token(), cachekey = cachekey})) and
@@ -140,6 +149,8 @@ function client_session:compile(sourcefile, objectfile, cppfile, cppflags, opt)
local body = msg:body()
outdata = body.outdata
errdata = body.errdata
+ host_status.cpurate = body.cpurate
+ host_status.memrate = body.memrate
ok = true
else
errors = msg:errors()
diff --git a/xmake/modules/private/service/distcc_build/server_session.lua b/xmake/modules/private/service/distcc_build/server_session.lua
index b614069a6..913cc1eca 100644
--- a/xmake/modules/private/service/distcc_build/server_session.lua
+++ b/xmake/modules/private/service/distcc_build/server_session.lua
@@ -169,6 +169,10 @@ function server_session:compile(respmsg)
end
end
+ -- send current server stats
+ body.cpurate = os.cpuinfo("usagerate")
+ body.memrate = os.meminfo("usagerate")
+
-- remove files
os.tryrm(sourcefile)
if not cachekey then