• LagDetector
    14 replies, posted
GMod Server Lag Detection Routine [url]https://github.com/100acrebb/thab_tools/tree/master/lua/autorun/server[/url] [url]http://steamcommunity.com/sharedfiles/filedetails/?id=654334461[/url] LagDetector is a simple tool to help detect and manage server-side lag. It uses differences between SysTime() and CurTime() to detect unexpected server lag, and once these deltas have exceeded a certain threshold, action can be taken to help correct. Been playing with it for a while and it serves its purpose well, so thought it time to pay it forward. These thresholds and actions are configurable through cvars: [CODE]lagdet_range if the delta of SysTime and CurTime grows by this value from one second to the next, we have detected frame lag and the system increments the lag counter. Default is 0.07 lagdet_count if the lag counter reaches this value, we have detected server lag and we execute lagdet_execute. Default is 5 lagdet_quiet indicates how long we must go (in seconds) with no frame lag before our lag counter resets to 0. lagdet_execute the console command(s) to execute if we detect server lag. Default is a simple say lagcount_meltdown if we detect this many frame lags without a reset, we execute lagexecute_meltdown. Default is 100 lagexecute_meltdown these console command(s) are executed in the event of massive lag. Server is probably in a collision loop or something. Good time to restart the map. Default is a simple say [/CODE] In addition to running console commands, LagDetector provides three hooks that you can use to extend functionality and execute custom code based on detections. Example implementation: [CODE] hook.Add( "LagDetectorDetected", "MyLagDetectorDetected", function() print("Lag has been detected.") end) hook.Add( "LagDetectorQuiet", "MyLagDetectorQuiet", function() print("The server has settled down.") end) hook.Add( "LagDetectorMeltdown", "MyLagDetectorMeltdown", function() print("ErMuhGerd, the server haz gone boom!") end) [/CODE] Using the defaults out of the box.. * LagDetector will compare SysTime and CurTime every second. If the difference between the two grows by >= 0.07, the lag counter increases. * If we go 15 seconds without detecting frame lag, the lag counter resets to 0 and the associated hook is called. * If the lag counter hits 5, we execute the commands in lagdet_execute (if any) and the associated hook is called. * If the lag counter hits 100, we execute the commands in lagexecute_meltdown (if any) and the associated hook is called.
Really nice implementation!
Nice. I can see uses for it in DarkRP.
Would work great for my BuildRP! Do you think you can make it auto-freeze all props on the map when it reaches a limit?
I've purposely left the response part of the addon fairly open-ended, since the requirements might be vastly different for different servers. So yes -- anything you can do through a series of server-side console commands (or anything you can do through Lua directly, with some modifications to the LagDetector code directly) are doable. I'm not entirely sure about the concept of 'reaching a limit', though. That sounds more in the domain of traditional prop management / protection systems. What limit were you talking about? An actual prop count, or just the detection of lag based (presumably) around high prop counts? On a related note, I should probably provide a hook to allow better extensibility than simple console commands.
Hey Nice idea, Maybe you should replace your commands with hooks.
[QUOTE=Myrage2000;50104337]Hey Nice idea, Maybe you should replace your commands with hooks.[/QUOTE] Indeed, hooks would be better to directly call them from Lua, than making a extra concommand for it just to do something.
Agreed. On my radar. My responses to high lag have thus far been generally simplistic --- alert the admins, reset the map or restart the map. But this obviously won't do for others who might want to do something a little more interesting/complex. Thanks.
Im talking about once the server becomes laggy, it automatically freezes all props.
Added hooks: In addition to running console commands, LagDetector provides three hooks that you can use to extend functionality and execute custom code based on detections. Example implementation: hook.Add( "LagDetectorDetected", "MyLagDetectorDetected", function() print("Lag has been detected.") end) hook.Add( "LagDetectorQuiet", "MyLagDetectorQuiet", function() print("The server has settled down.") end) hook.Add( "LagDetectorMeltdown", "MyLagDetectorMeltdown", function() print("ErMuhGerd, the server haz gone boom!") end)
Very good addition to net_graph
This could be useful for Sandbox build servers. Nice job!
Just an FYI. Anything that uses game.SetTimeScale() may create false positives for the duration of the non-standard timescale. This isn't surprising, when you think about how the detection works (CurTime v SysTime). Discovered this when chasing weird detections in Extreme Football Throwdown, which uses SetTimeScale as part of the touchdown celebration. I can probably compensate by feeding the timescale back into the detection calculation. A rainy day task.
Is there any way to integrate a auto cleanup portion that will clean up the map if the lag detector goes off several consecutive times? Im loving this mod, easy to see if there is issues with a server from RCON.
Sure. At a very basic, brute-force level, you could set the lagdet_execute cvar to clean up the map, or use the hook... [CODE]lagdet_execute "gmod_admin_cleanup"[/CODE] [CODE]hook.Add( "LagDetectorDetected", "MyLagDetectorDetected", function() RunConsoleCommand("gmod_admin_cleanup") end)[/CODE] ... assuming you've tuned the config values to something appropriate for your server (ie, the sensitivity you want).
Sorry, you need to Log In to post a reply to this thread.