From cbdc6a4ac1f1a019adce2ed79459f5694b5792e0 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Fri, 22 Jan 2016 00:00:00 -0800 Subject: [PATCH 1/2] Makes the MC avoid triggering the byond bug that causes lag. See http://www.byond.com/forum/?post=2021963#comment18164837 Higher fps when cpu goes over 120 causes issues. I have it scaling around 100 to give us a buffer, and not going back down until it drops below 75 to avoid it jumping too much. This is a bit of a mess, but all of it can removed once the bug is fixed on byond's end. --- code/controllers/master.dm | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/code/controllers/master.dm b/code/controllers/master.dm index db25833d75f..c413b2bd8ad 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -21,7 +21,8 @@ var/global/datum/controller/master/Master = new() var/iteration = 0 // The cost (in deciseconds) of the MC loop. var/cost = 0 - + // The old fps when we slow it down to prevent lag. + var/old_fps // A list of subsystems to process(). var/list/subsystems = list() // The cost of running the subsystems (in deciseconds). @@ -127,6 +128,12 @@ var/global/datum/controller/master/Master = new() var/ran_subsystems = 0 for(var/datum/subsystem/SS in subsystems) + if(world.cpu >= 100) + //if world.cpu gets above 120, + //byond will pause most client updates for (about) 1.6 seconds. + //(1.6 seconds worth of ticks) + //We just stop running subsystems to avoid that. + break; if(SS.can_fire > 0) if(SS.next_fire <= world.time && SS.last_fire + (SS.wait * 0.5) <= world.time) // Check if it's time. ran_subsystems = 1 @@ -166,9 +173,20 @@ var/global/datum/controller/master/Master = new() if(startingtick < world.time || start_time + 1 < world.timeofday) extrasleep += world.tick_lag * 2 // If we are loading the server too much, sleep a bit extra... - if(world.cpu > 80) - extrasleep += extrasleep + processing_interval + if(world.cpu >= 75) + extrasleep += (1 + extrasleep + processing_interval) * ((world.cpu-50)/10) + if(world.cpu >= 100) + extrasleep += extrasleep //double it, we are close to triggering a byond bug. + if(!old_fps) + old_fps = world.fps + //byond bug, if we go over 120 fps and world.fps is higher then 10, the bad things that happen are made worst. + world.fps = 10 + else if(old_fps && world.cpu < 75) + world.fps = old_fps + old_fps = null + sleep(processing_interval + extrasleep) + else sleep(50) #undef MC_AVERAGE From fcae050052decb90e57800720d3b1f8b71b1b956 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Fri, 22 Jan 2016 11:12:33 -0800 Subject: [PATCH 2/2] Make up missed SS ticks less aggressively. Don't attempt to make up missed subsystem ticks on dynamic wait subsystem Only make them up 25% at a time. (Also tweaks high cpu delaying a bit) --- code/controllers/master.dm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/code/controllers/master.dm b/code/controllers/master.dm index c413b2bd8ad..063552d3769 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -133,9 +133,9 @@ var/global/datum/controller/master/Master = new() //byond will pause most client updates for (about) 1.6 seconds. //(1.6 seconds worth of ticks) //We just stop running subsystems to avoid that. - break; + break if(SS.can_fire > 0) - if(SS.next_fire <= world.time && SS.last_fire + (SS.wait * 0.5) <= world.time) // Check if it's time. + if(SS.next_fire <= world.time && SS.last_fire + (SS.wait * 0.75) <= world.time) // Check if it's time. ran_subsystems = 1 timer = world.timeofday last_type_processed = SS.type @@ -151,7 +151,9 @@ var/global/datum/controller/master/Master = new() SS.wait = Clamp(newwait, SS.dwait_lower, SS.dwait_upper) if(oldwait != SS.wait) processing_interval = calculate_gcd() - SS.next_fire += SS.wait + SS.next_fire = world.time + SS.wait + else + SS.next_fire += SS.wait ++SS.times_fired // If we caused BYOND to miss a tick, stop processing for a bit... if(startingtick < world.time || start_time + 1 < world.timeofday) @@ -174,14 +176,14 @@ var/global/datum/controller/master/Master = new() extrasleep += world.tick_lag * 2 // If we are loading the server too much, sleep a bit extra... if(world.cpu >= 75) - extrasleep += (1 + extrasleep + processing_interval) * ((world.cpu-50)/10) + extrasleep += (extrasleep + processing_interval) * ((world.cpu-50)/10) + if(world.cpu >= 100) - extrasleep += extrasleep //double it, we are close to triggering a byond bug. if(!old_fps) old_fps = world.fps //byond bug, if we go over 120 fps and world.fps is higher then 10, the bad things that happen are made worst. world.fps = 10 - else if(old_fps && world.cpu < 75) + else if(old_fps && world.cpu < 50) world.fps = old_fps old_fps = null