diff options
author | Giacomo Pozzoni <giacomopoz@gmail.com> | 2021-07-24 14:50:30 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-03-11 19:32:22 +0100 |
commit | 51f0294c18a32f5e299b17576e673d6c92bf0201 (patch) | |
tree | 97d892d94f2bb0426fab1ea6e65466bf54219b62 | |
parent | 21177487ea9476cb4db3f498353c340181d87e14 (diff) |
Core/DBLayer: Add QueueSize() method (#26733)
* Core/DBLayer: Add QueueSize() method
Add QueueSize() method to database objects (Login, Character and World) that returns how many tasks are queued.
Include the queue size of the 3 databases in ".server debug" command
* Make the code less threadsafe
* Send data to InfluxDB
* Update grafana dashboard
(cherry picked from commit 96dc110f4a353871ac74c82ff4b1bcc4c34156f3)
-rw-r--r-- | contrib/grafana/4_Performance_profiling.json | 270 | ||||
-rw-r--r-- | src/common/Threading/ProducerConsumerQueue.h | 5 | ||||
-rw-r--r-- | src/server/database/Database/DatabaseWorkerPool.cpp | 6 | ||||
-rw-r--r-- | src/server/database/Database/DatabaseWorkerPool.h | 2 | ||||
-rw-r--r-- | src/server/scripts/Commands/cs_server.cpp | 4 | ||||
-rw-r--r-- | src/server/worldserver/Main.cpp | 3 |
6 files changed, 268 insertions, 22 deletions
diff --git a/contrib/grafana/4_Performance_profiling.json b/contrib/grafana/4_Performance_profiling.json index 65eff659ae8..af0440f2245 100644 --- a/contrib/grafana/4_Performance_profiling.json +++ b/contrib/grafana/4_Performance_profiling.json @@ -29,7 +29,7 @@ "gnetId": null, "graphTooltip": 0, "id": 15, - "iteration": 1596541749733, + "iteration": 1626984445687, "links": [], "panels": [ { @@ -42,7 +42,7 @@ "error": false, "fieldConfig": { "defaults": { - "custom": {} + "links": [] }, "overrides": [] }, @@ -79,9 +79,10 @@ "links": [], "nullPointMode": "connected", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.0.3", "pointradius": 5, "points": false, "renderer": "flot", @@ -193,7 +194,7 @@ "datasource": null, "fieldConfig": { "defaults": { - "custom": {} + "links": [] }, "overrides": [] }, @@ -224,9 +225,10 @@ "linewidth": 2, "nullPointMode": "connected", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.0.3", "pointradius": 2, "points": false, "renderer": "flot", @@ -381,7 +383,7 @@ "datasource": null, "fieldConfig": { "defaults": { - "custom": {} + "links": [] }, "overrides": [] }, @@ -412,9 +414,10 @@ "linewidth": 0, "nullPointMode": "connected", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.0.3", "pointradius": 2, "points": false, "renderer": "flot", @@ -530,7 +533,7 @@ "datasource": null, "fieldConfig": { "defaults": { - "custom": {} + "links": [] }, "overrides": [] }, @@ -561,9 +564,10 @@ "linewidth": 2, "nullPointMode": "connected", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.0.3", "pointradius": 2, "points": false, "renderer": "flot", @@ -673,7 +677,7 @@ "datasource": null, "fieldConfig": { "defaults": { - "custom": {} + "links": [] }, "overrides": [] }, @@ -704,9 +708,10 @@ "linewidth": 0, "nullPointMode": "connected", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.0.3", "pointradius": 2, "points": false, "renderer": "flot", @@ -816,7 +821,7 @@ "datasource": null, "fieldConfig": { "defaults": { - "custom": {} + "links": [] }, "overrides": [] }, @@ -849,9 +854,10 @@ "linewidth": 2, "nullPointMode": "connected", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.0.3", "pointradius": 2, "points": false, "renderer": "flot", @@ -961,7 +967,7 @@ "datasource": null, "fieldConfig": { "defaults": { - "custom": {} + "links": [] }, "overrides": [] }, @@ -994,9 +1000,10 @@ "linewidth": 2, "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.0.3", "pointradius": 2, "points": true, "renderer": "flot", @@ -1106,7 +1113,7 @@ "datasource": null, "fieldConfig": { "defaults": { - "custom": {} + "links": [] }, "overrides": [] }, @@ -1137,9 +1144,10 @@ "linewidth": 1, "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.0.3", "pointradius": 2, "points": false, "renderer": "flot", @@ -1253,7 +1261,7 @@ "datasource": null, "fieldConfig": { "defaults": { - "custom": {} + "links": [] }, "overrides": [] }, @@ -1284,9 +1292,10 @@ "linewidth": 1, "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.0.3", "pointradius": 2, "points": false, "renderer": "flot", @@ -1391,10 +1400,226 @@ "align": false, "alignLevel": null } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 39 + }, + "hiddenSeries": false, + "id": 17, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 2, + "nullPointMode": "connected", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "8.0.3", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "alias": "Login DB", + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "db_queue_login", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "max" + } + ] + ], + "tags": [ + { + "key": "realm", + "operator": "=~", + "value": "/^$realm$/" + } + ] + }, + { + "alias": "Character DB", + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "hide": false, + "measurement": "db_queue_character", + "orderByTime": "ASC", + "policy": "default", + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "max" + } + ] + ], + "tags": [ + { + "key": "realm", + "operator": "=~", + "value": "/^$realm$/" + } + ] + }, + { + "alias": "World DB", + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "hide": false, + "measurement": "db_queue_world", + "orderByTime": "ASC", + "policy": "default", + "refId": "C", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "max" + } + ] + ], + "tags": [ + { + "key": "realm", + "operator": "=~", + "value": "/^$realm$/" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Database queue", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:102", + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "$$hashKey": "object:103", + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } } ], "refresh": "1m", - "schemaVersion": 25, + "schemaVersion": 30, "style": "dark", "tags": [], "templating": { @@ -1408,6 +1633,8 @@ }, "datasource": "Influx", "definition": "show tag values from events with key = realm", + "description": null, + "error": null, "hide": 0, "includeAll": false, "label": null, @@ -1420,7 +1647,6 @@ "skipUrlSync": false, "sort": 0, "tagValuesQuery": "", - "tags": [], "tagsQuery": "", "type": "query", "useTags": false @@ -1447,5 +1673,5 @@ "timezone": "", "title": "Performance profiling", "uid": "IRRL03nMk", - "version": 8 + "version": 9 }
\ No newline at end of file diff --git a/src/common/Threading/ProducerConsumerQueue.h b/src/common/Threading/ProducerConsumerQueue.h index 1341bd26747..778f434e9de 100644 --- a/src/common/Threading/ProducerConsumerQueue.h +++ b/src/common/Threading/ProducerConsumerQueue.h @@ -52,6 +52,11 @@ public: return _queue.empty(); } + size_t Size() const + { + return _queue.size(); + } + bool Pop(T& value) { std::lock_guard<std::mutex> lock(_queueLock); diff --git a/src/server/database/Database/DatabaseWorkerPool.cpp b/src/server/database/Database/DatabaseWorkerPool.cpp index 043db148a1e..7aa1a1e46d1 100644 --- a/src/server/database/Database/DatabaseWorkerPool.cpp +++ b/src/server/database/Database/DatabaseWorkerPool.cpp @@ -415,6 +415,12 @@ void DatabaseWorkerPool<T>::Enqueue(SQLOperation* op) } template <class T> +size_t DatabaseWorkerPool<T>::QueueSize() const +{ + return _queue->Size(); +} + +template <class T> T* DatabaseWorkerPool<T>::GetFreeConnection() { #ifdef TRINITY_DEBUG diff --git a/src/server/database/Database/DatabaseWorkerPool.h b/src/server/database/Database/DatabaseWorkerPool.h index 9852ded374e..66d5a55dffa 100644 --- a/src/server/database/Database/DatabaseWorkerPool.h +++ b/src/server/database/Database/DatabaseWorkerPool.h @@ -213,6 +213,8 @@ class DatabaseWorkerPool #endif } + size_t QueueSize() const; + private: uint32 OpenConnections(InternalIndex type, uint8 numConnections); diff --git a/src/server/scripts/Commands/cs_server.cpp b/src/server/scripts/Commands/cs_server.cpp index 20b7961f13c..7306b73554c 100644 --- a/src/server/scripts/Commands/cs_server.cpp +++ b/src/server/scripts/Commands/cs_server.cpp @@ -249,6 +249,10 @@ public: handler->PSendSysMessage("Using %s DBC Locale as default. All available DBC locales: %s", localeNames[defaultLocale], availableLocales.c_str()); handler->PSendSysMessage("Using World DB: %s", sWorld->GetDBVersion()); + + handler->PSendSysMessage("LoginDatabase queue size: %zu", LoginDatabase.QueueSize()); + handler->PSendSysMessage("CharacterDatabase queue size: %zu", CharacterDatabase.QueueSize()); + handler->PSendSysMessage("WorldDatabase queue size: %zu", WorldDatabase.QueueSize()); return true; } diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 96d81f98f17..1fe51079f6b 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -281,6 +281,9 @@ extern int main(int argc, char** argv) sMetric->Initialize(realm.Name, *ioContext, []() { TC_METRIC_VALUE("online_players", sWorld->GetPlayerCount()); + TC_METRIC_VALUE("db_queue_login", LoginDatabase.QueueSize()); + TC_METRIC_VALUE("db_queue_character", CharacterDatabase.QueueSize()); + TC_METRIC_VALUE("db_queue_world", WorldDatabase.QueueSize()); }); TC_METRIC_EVENT("events", "Worldserver started", ""); |