Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/serverperformance command (Server Performance Monitor) #1642

Merged
merged 3 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Source/ACE.Common/GameConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class GameConfiguration

public string DatFilesDirectory { get; set; }

[System.ComponentModel.DefaultValue(false)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool ServerPerformanceMonitorAutoStart { get; set; }

[System.ComponentModel.DefaultValue(false)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool WorldDatabasePrecaching { get; set; }
Expand Down
22 changes: 21 additions & 1 deletion Source/ACE.Common/RateMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,40 @@ public class RateMonitor
/// </summary>
public double AverageEventDuration => TotalSeconds / TotalEvents;

public void ResetEvent()
{
stopwatch.Reset();
}

public void RegisterEventStart()
{
stopwatch.Reset();
stopwatch.Start();
}

public void PauseEvent()
{
stopwatch.Stop();
}

public void ResumeEvent()
{
stopwatch.Start();
}

/// <summary>
/// returns the elapsed seconds for this event
/// </summary>
public double RegisterEventEnd()
{
stopwatch.Stop();

LastEvent = stopwatch.Elapsed.TotalSeconds;
return RegisterEvent(stopwatch.Elapsed.TotalSeconds);
}

public double RegisterEvent(double totalSeconds)
{
LastEvent = totalSeconds;

TotalEvents++;
TotalSeconds += LastEvent;
Expand Down
43 changes: 41 additions & 2 deletions Source/ACE.Server/Command/Handlers/AdminCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,8 +2060,10 @@ public static void HandleServerStatus(Session session, params string[] parameter
sb.Append($"{activeLandblocks.Count:N0} active landblocks - Players: {players:N0}, Creatures: {creatures:N0}, Missiles: {missiles:N0}, Other: {other:N0}, Total: {total:N0}.{'\n'}"); // 11 total blocks loaded. 11 active. 0 pending dormancy. 0 dormant. 314 unloaded.
// 11 total blocks loaded. 11 active. 0 pending dormancy. 0 dormant. 314 unloaded.

sb.Append($"UpdateGameWorld {(DateTime.UtcNow - WorldManager.UpdateGameWorld5MinLastReset).TotalMinutes:N2} min - {WorldManager.UpdateGameWorld5MinRM}.{'\n'}");
sb.Append($"UpdateGameWorld {(DateTime.UtcNow - WorldManager.UpdateGameWorld60MinLastReset).TotalMinutes:N2} min - {WorldManager.UpdateGameWorld60MinRM}.{'\n'}");
if (ServerPerformanceMonitor.IsRunning)
sb.Append($"Server Performance Monitor - UpdateGameWorld ~5m {ServerPerformanceMonitor.GetMonitor5m(ServerPerformanceMonitor.MonitorType.UpdateGameWorld_Entire).AverageEventDuration:N3}, ~1h {ServerPerformanceMonitor.GetMonitor1h(ServerPerformanceMonitor.MonitorType.UpdateGameWorld_Entire).AverageEventDuration:N3} s{'\n'}");
else
sb.Append($"Server Performance Monitor - Not running. To start use /serverperformance start{'\n'}");

sb.Append($"World DB Cache Counts - Weenies: {DatabaseManager.World.GetWeenieCacheCount():N0}, LandblockInstances: {DatabaseManager.World.GetLandblockInstancesCacheCount():N0}, PointsOfInterest: {DatabaseManager.World.GetPointsOfInterestCacheCount():N0}, Cookbooks: {DatabaseManager.World.GetCookbookCacheCount():N0}, Spells: {DatabaseManager.World.GetSpellCacheCount():N0}, Encounters: {DatabaseManager.World.GetEncounterCacheCount():N0}, Events: {DatabaseManager.World.GetEventsCacheCount():N0}{'\n'}");
sb.Append($"Shard DB Counts - Biotas: {DatabaseManager.Shard.GetBiotaCount():N0}{'\n'}");
Expand All @@ -2072,6 +2074,43 @@ public static void HandleServerStatus(Session session, params string[] parameter
CommandHandlerHelper.WriteOutputInfo(session, $"{sb}");
}

// serverstatus
[CommandHandler("serverperformance", AccessLevel.Advocate, CommandHandlerFlag.None, 0, "Displays a summary of server performance statistics")]
public static void HandleServerPerformance(Session session, params string[] parameters)
{
if (parameters != null && parameters.Length == 1)
{
if (parameters[0].ToLower() == "start")
{
ServerPerformanceMonitor.Start();
CommandHandlerHelper.WriteOutputInfo(session, "Server Performance Monitor started");
return;
}

if (parameters[0].ToLower() == "stop")
{
ServerPerformanceMonitor.Stop();
CommandHandlerHelper.WriteOutputInfo(session, "Server Performance Monitor stopped");
return;
}

if (parameters[0].ToLower() == "reset")
{
ServerPerformanceMonitor.Reset();
CommandHandlerHelper.WriteOutputInfo(session, "Server Performance Monitor reset");
return;
}
}

if (!ServerPerformanceMonitor.IsRunning)
{
CommandHandlerHelper.WriteOutputInfo(session, "Server Performance Monitor not running. To start use /serverperformance start");
return;
}

CommandHandlerHelper.WriteOutputInfo(session, ServerPerformanceMonitor.ToString());
}

[CommandHandler("modifybool", AccessLevel.Admin, CommandHandlerFlag.None, 2, "Modifies a server property that is a bool", "modifybool (string) (bool)")]
public static void HandleModifyServerBoolProperty(Session session, params string[] paramters)
{
Expand Down
1 change: 1 addition & 0 deletions Source/ACE.Server/Config.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"DatFilesDirectory": "c:\\ACE\\",
"ShutdownInterval": "60",
"ServerPerformanceMonitorAutoStart": false,
"WorldDatabasePrecaching": false,
"LandblockPreloading": true,
"PreloadedLandblocks": [
Expand Down
14 changes: 14 additions & 0 deletions Source/ACE.Server/Entity/Landblock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,20 @@ private void LoadScenery()

public void Tick(double currentUnixTime)
{
ServerPerformanceMonitor.ResumeEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_RunActions);
actionQueue.RunActions();
ServerPerformanceMonitor.PauseEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_RunActions);

ProcessPendingWorldObjectAdditionsAndRemovals();

// When a WorldObject Ticks, it can end up adding additional WorldObjects to this landblock

ServerPerformanceMonitor.ResumeEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_Player_Tick);
foreach (var player in players)
player.Player_Tick(currentUnixTime);
ServerPerformanceMonitor.PauseEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_Player_Tick);

ServerPerformanceMonitor.ResumeEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_Monster_Tick);
while (sortedCreaturesByNextTick.Count > 0) // Monster_Tick()
{
var first = sortedCreaturesByNextTick.First.Value;
Expand All @@ -331,7 +336,9 @@ public void Tick(double currentUnixTime)
break;
}
}
ServerPerformanceMonitor.PauseEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_Monster_Tick);

ServerPerformanceMonitor.ResumeEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_WorldObject_Heartbeat);
while (sortedWorldObjectsByNextHeartbeat.Count > 0) // Heartbeat()
{
var first = sortedWorldObjectsByNextHeartbeat.First.Value;
Expand All @@ -348,7 +355,9 @@ public void Tick(double currentUnixTime)
break;
}
}
ServerPerformanceMonitor.PauseEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_WorldObject_Heartbeat);

ServerPerformanceMonitor.ResumeEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_GeneratorHeartbeat);
while (sortedGeneratorsByNextGeneratorHeartbeat.Count > 0) // GeneratorHeartbeat()
{
var first = sortedGeneratorsByNextGeneratorHeartbeat.First.Value;
Expand All @@ -365,8 +374,10 @@ public void Tick(double currentUnixTime)
break;
}
}
ServerPerformanceMonitor.PauseEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_GeneratorHeartbeat);

// Heartbeat
ServerPerformanceMonitor.ResumeEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_Heartbeat);
if (lastHeartBeat + heartbeatInterval <= DateTime.UtcNow)
{
var thisHeartBeat = DateTime.UtcNow;
Expand All @@ -385,15 +396,18 @@ public void Tick(double currentUnixTime)

lastHeartBeat = thisHeartBeat;
}
ServerPerformanceMonitor.PauseEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_Heartbeat);

// Database Save
ServerPerformanceMonitor.ResumeEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_Database_Save);
if (lastDatabaseSave + databaseSaveInterval <= DateTime.UtcNow)
{
ProcessPendingWorldObjectAdditionsAndRemovals();

SaveDB();
lastDatabaseSave = DateTime.UtcNow;
}
ServerPerformanceMonitor.PauseEvent(ServerPerformanceMonitor.MonitorType.Landblock_Tick_Database_Save);
}

private void ProcessPendingWorldObjectAdditionsAndRemovals()
Expand Down
Loading