Skip to content

Commit

Permalink
Adjust serverstatus command (#4162)
Browse files Browse the repository at this point in the history
Swap out GetBiotaCount for GetEstimatedBiotaCount to explicit counting of all db records.

See https://mariadb.com/kb/en/incredibly-slow-count-on-mariadb-mysql/
  • Loading branch information
LtRipley36706 authored May 12, 2024
1 parent 8932bbe commit dd3f148
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
27 changes: 27 additions & 0 deletions Source/ACE.Database/ShardDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,33 @@ public int GetBiotaCount()
return context.Biota.Count();
}

public int GetEstimatedBiotaCount(string dbName)
{
// https://mariadb.com/kb/en/incredibly-slow-count-on-mariadb-mysql/

var sql = $"SELECT TABLE_ROWS FROM information_schema.tables" + Environment.NewLine +
$"WHERE TABLE_SCHEMA = '{dbName}'" + Environment.NewLine +
$"AND TABLE_NAME = 'biota';";

using (var context = new ShardDbContext())
{
var connection = context.Database.GetDbConnection();
connection.Open();
var command = connection.CreateCommand();
command.CommandText = sql;
var reader = command.ExecuteReader();

var biotaEstimatedCount = 0;

while (reader.Read())
{
biotaEstimatedCount = reader.GetFieldValue<int>(0);
}

return biotaEstimatedCount;
}
}

[Flags]
public enum PopulatedCollectionFlags
{
Expand Down
5 changes: 3 additions & 2 deletions Source/ACE.Server/Command/Handlers/AdminStatCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public static void HandleServerStatus(Session session, params string[] parameter
sb.Append($"Total Server Objects: {ServerObjectManager.ServerObjects.Count:N0}{'\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.BaseDatabase.GetBiotaCount():N0}{'\n'}");
//sb.Append($"Shard DB Counts - Biotas: {DatabaseManager.Shard.BaseDatabase.GetBiotaCount():N0}{'\n'}");
sb.Append($"Shard DB Counts - Biotas: ~{DatabaseManager.Shard.BaseDatabase.GetEstimatedBiotaCount(ConfigManager.Config.MySql.Shard.Database):N0}{'\n'}");
if (DatabaseManager.Shard.BaseDatabase is ShardDatabaseWithCaching shardDatabaseWithCaching)
{
var biotaIds = shardDatabaseWithCaching.GetBiotaCacheKeys();
Expand All @@ -155,7 +156,7 @@ public static void HandleServerStatus(Session session, params string[] parameter
CommandHandlerHelper.WriteOutputInfo(session, $"{sb}");
}

// serverstatus
// serverperformance
[CommandHandler("serverperformance", AccessLevel.Advocate, CommandHandlerFlag.None, 0, "Displays a summary of server performance statistics")]
public static void HandleServerPerformance(Session session, params string[] parameters)
{
Expand Down

0 comments on commit dd3f148

Please sign in to comment.