Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / mds / balancers / greedyspill.lua
1 local metrics = {"auth.meta_load", "all.meta_load", "req_rate", "queue_len", "cpu_load_avg"}
2
3 -- Metric for balancing is the workload; also dumps metrics
4 local function mds_load()
5   for rank, mds in pairs(mds) do
6     local s = "MDS"..rank..": < "
7     for _, metric in ipairs(metrics) do
8       s = s..metric.."="..mds[metric].." "
9     end
10     mds.load = mds["all.meta_load"]
11     BAL_LOG(5, s.."> load="..mds.load)
12   end
13 end
14
15 -- Shed load when you have load and your neighbor doesn't
16 local function when()
17   if not mds[whoami+1] then
18     -- i'm the last rank
19     BAL_LOG(5, "when: not migrating! I am the last rank, nothing to spill to.");
20     return false
21   end
22   my_load = mds[whoami]["load"]
23   his_load = mds[whoami+1]["load"]
24   if my_load > 0.01 and his_load < 0.01 then
25     BAL_LOG(5, "when: migrating! my_load="..my_load.." hisload="..his_load)
26     return true
27   end
28   BAL_LOG(5, "when: not migrating! my_load="..my_load.." hisload="..his_load)
29   return false
30 end
31
32 -- Shed half your load to your neighbor
33 -- neighbor=whoami+2 because Lua tables are indexed starting at 1
34 local function where(targets)
35   targets[whoami+1] = mds[whoami]["load"]/2
36   return targets
37 end
38
39 local targets = {}
40 for rank in pairs(mds) do
41   targets[rank] = 0
42 end
43
44 mds_load()
45 if when() then
46   where(targets)
47 end
48
49 return targets