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)
This commit is contained in:
Giacomo Pozzoni
2022-03-11 19:32:22 +01:00
committed by Shauren
parent 21177487ea
commit 51f0294c18
6 changed files with 268 additions and 22 deletions
+248 -22
View File
@@ -29,7 +29,7 @@
"gnetId": null, "gnetId": null,
"graphTooltip": 0, "graphTooltip": 0,
"id": 15, "id": 15,
"iteration": 1596541749733, "iteration": 1626984445687,
"links": [], "links": [],
"panels": [ "panels": [
{ {
@@ -42,7 +42,7 @@
"error": false, "error": false,
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
"custom": {} "links": []
}, },
"overrides": [] "overrides": []
}, },
@@ -79,9 +79,10 @@
"links": [], "links": [],
"nullPointMode": "connected", "nullPointMode": "connected",
"options": { "options": {
"dataLinks": [] "alertThreshold": true
}, },
"percentage": false, "percentage": false,
"pluginVersion": "8.0.3",
"pointradius": 5, "pointradius": 5,
"points": false, "points": false,
"renderer": "flot", "renderer": "flot",
@@ -193,7 +194,7 @@
"datasource": null, "datasource": null,
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
"custom": {} "links": []
}, },
"overrides": [] "overrides": []
}, },
@@ -224,9 +225,10 @@
"linewidth": 2, "linewidth": 2,
"nullPointMode": "connected", "nullPointMode": "connected",
"options": { "options": {
"dataLinks": [] "alertThreshold": true
}, },
"percentage": false, "percentage": false,
"pluginVersion": "8.0.3",
"pointradius": 2, "pointradius": 2,
"points": false, "points": false,
"renderer": "flot", "renderer": "flot",
@@ -381,7 +383,7 @@
"datasource": null, "datasource": null,
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
"custom": {} "links": []
}, },
"overrides": [] "overrides": []
}, },
@@ -412,9 +414,10 @@
"linewidth": 0, "linewidth": 0,
"nullPointMode": "connected", "nullPointMode": "connected",
"options": { "options": {
"dataLinks": [] "alertThreshold": true
}, },
"percentage": false, "percentage": false,
"pluginVersion": "8.0.3",
"pointradius": 2, "pointradius": 2,
"points": false, "points": false,
"renderer": "flot", "renderer": "flot",
@@ -530,7 +533,7 @@
"datasource": null, "datasource": null,
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
"custom": {} "links": []
}, },
"overrides": [] "overrides": []
}, },
@@ -561,9 +564,10 @@
"linewidth": 2, "linewidth": 2,
"nullPointMode": "connected", "nullPointMode": "connected",
"options": { "options": {
"dataLinks": [] "alertThreshold": true
}, },
"percentage": false, "percentage": false,
"pluginVersion": "8.0.3",
"pointradius": 2, "pointradius": 2,
"points": false, "points": false,
"renderer": "flot", "renderer": "flot",
@@ -673,7 +677,7 @@
"datasource": null, "datasource": null,
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
"custom": {} "links": []
}, },
"overrides": [] "overrides": []
}, },
@@ -704,9 +708,10 @@
"linewidth": 0, "linewidth": 0,
"nullPointMode": "connected", "nullPointMode": "connected",
"options": { "options": {
"dataLinks": [] "alertThreshold": true
}, },
"percentage": false, "percentage": false,
"pluginVersion": "8.0.3",
"pointradius": 2, "pointradius": 2,
"points": false, "points": false,
"renderer": "flot", "renderer": "flot",
@@ -816,7 +821,7 @@
"datasource": null, "datasource": null,
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
"custom": {} "links": []
}, },
"overrides": [] "overrides": []
}, },
@@ -849,9 +854,10 @@
"linewidth": 2, "linewidth": 2,
"nullPointMode": "connected", "nullPointMode": "connected",
"options": { "options": {
"dataLinks": [] "alertThreshold": true
}, },
"percentage": false, "percentage": false,
"pluginVersion": "8.0.3",
"pointradius": 2, "pointradius": 2,
"points": false, "points": false,
"renderer": "flot", "renderer": "flot",
@@ -961,7 +967,7 @@
"datasource": null, "datasource": null,
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
"custom": {} "links": []
}, },
"overrides": [] "overrides": []
}, },
@@ -994,9 +1000,10 @@
"linewidth": 2, "linewidth": 2,
"nullPointMode": "null", "nullPointMode": "null",
"options": { "options": {
"dataLinks": [] "alertThreshold": true
}, },
"percentage": false, "percentage": false,
"pluginVersion": "8.0.3",
"pointradius": 2, "pointradius": 2,
"points": true, "points": true,
"renderer": "flot", "renderer": "flot",
@@ -1106,7 +1113,7 @@
"datasource": null, "datasource": null,
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
"custom": {} "links": []
}, },
"overrides": [] "overrides": []
}, },
@@ -1137,9 +1144,10 @@
"linewidth": 1, "linewidth": 1,
"nullPointMode": "null", "nullPointMode": "null",
"options": { "options": {
"dataLinks": [] "alertThreshold": true
}, },
"percentage": false, "percentage": false,
"pluginVersion": "8.0.3",
"pointradius": 2, "pointradius": 2,
"points": false, "points": false,
"renderer": "flot", "renderer": "flot",
@@ -1253,7 +1261,7 @@
"datasource": null, "datasource": null,
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
"custom": {} "links": []
}, },
"overrides": [] "overrides": []
}, },
@@ -1284,9 +1292,10 @@
"linewidth": 1, "linewidth": 1,
"nullPointMode": "null", "nullPointMode": "null",
"options": { "options": {
"dataLinks": [] "alertThreshold": true
}, },
"percentage": false, "percentage": false,
"pluginVersion": "8.0.3",
"pointradius": 2, "pointradius": 2,
"points": false, "points": false,
"renderer": "flot", "renderer": "flot",
@@ -1391,10 +1400,226 @@
"align": false, "align": false,
"alignLevel": null "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", "refresh": "1m",
"schemaVersion": 25, "schemaVersion": 30,
"style": "dark", "style": "dark",
"tags": [], "tags": [],
"templating": { "templating": {
@@ -1408,6 +1633,8 @@
}, },
"datasource": "Influx", "datasource": "Influx",
"definition": "show tag values from events with key = realm", "definition": "show tag values from events with key = realm",
"description": null,
"error": null,
"hide": 0, "hide": 0,
"includeAll": false, "includeAll": false,
"label": null, "label": null,
@@ -1420,7 +1647,6 @@
"skipUrlSync": false, "skipUrlSync": false,
"sort": 0, "sort": 0,
"tagValuesQuery": "", "tagValuesQuery": "",
"tags": [],
"tagsQuery": "", "tagsQuery": "",
"type": "query", "type": "query",
"useTags": false "useTags": false
@@ -1447,5 +1673,5 @@
"timezone": "", "timezone": "",
"title": "Performance profiling", "title": "Performance profiling",
"uid": "IRRL03nMk", "uid": "IRRL03nMk",
"version": 8 "version": 9
} }
@@ -52,6 +52,11 @@ public:
return _queue.empty(); return _queue.empty();
} }
size_t Size() const
{
return _queue.size();
}
bool Pop(T& value) bool Pop(T& value)
{ {
std::lock_guard<std::mutex> lock(_queueLock); std::lock_guard<std::mutex> lock(_queueLock);
@@ -414,6 +414,12 @@ void DatabaseWorkerPool<T>::Enqueue(SQLOperation* op)
_queue->Push(op); _queue->Push(op);
} }
template <class T>
size_t DatabaseWorkerPool<T>::QueueSize() const
{
return _queue->Size();
}
template <class T> template <class T>
T* DatabaseWorkerPool<T>::GetFreeConnection() T* DatabaseWorkerPool<T>::GetFreeConnection()
{ {
@@ -213,6 +213,8 @@ class DatabaseWorkerPool
#endif #endif
} }
size_t QueueSize() const;
private: private:
uint32 OpenConnections(InternalIndex type, uint8 numConnections); uint32 OpenConnections(InternalIndex type, uint8 numConnections);
@@ -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 %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("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; return true;
} }
+3
View File
@@ -281,6 +281,9 @@ extern int main(int argc, char** argv)
sMetric->Initialize(realm.Name, *ioContext, []() sMetric->Initialize(realm.Name, *ioContext, []()
{ {
TC_METRIC_VALUE("online_players", sWorld->GetPlayerCount()); 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", ""); TC_METRIC_EVENT("events", "Worldserver started", "");