Remedy connection type query at every login (#2298)
Fix #2285 This change adds an internal counter for each tcp/web socket connection that the server makes and queries the stored memory count at login rather than the previous way that quired the database during each login. Each login that quired the DB put a significant load on the server as the user base grew.
This commit is contained in:
parent
a6f1f4c01d
commit
f86b9e0be7
3 changed files with 19 additions and 4 deletions
|
@ -38,7 +38,7 @@
|
|||
#include <QDebug>
|
||||
|
||||
Server::Server(QObject *parent)
|
||||
: QObject(parent), nextLocalGameId(0)
|
||||
: QObject(parent), nextLocalGameId(0), tcpUserCount(0), webSocketUserCount(0)
|
||||
{
|
||||
qRegisterMetaType<ServerInfo_Ban>("ServerInfo_Ban");
|
||||
qRegisterMetaType<ServerInfo_Game>("ServerInfo_Game");
|
||||
|
@ -202,12 +202,25 @@ Server_AbstractUserInterface *Server::findUser(const QString &userName) const
|
|||
|
||||
void Server::addClient(Server_ProtocolHandler *client)
|
||||
{
|
||||
if (client->getConnectionType() == "tcp")
|
||||
tcpUserCount++;
|
||||
|
||||
if (client->getConnectionType() == "websocket")
|
||||
webSocketUserCount++;
|
||||
|
||||
QWriteLocker locker(&clientsLock);
|
||||
clients << client;
|
||||
}
|
||||
|
||||
void Server::removeClient(Server_ProtocolHandler *client)
|
||||
{
|
||||
|
||||
if (client->getConnectionType() == "tcp")
|
||||
tcpUserCount--;
|
||||
|
||||
if (client->getConnectionType() == "websocket")
|
||||
webSocketUserCount--;
|
||||
|
||||
QWriteLocker locker(&clientsLock);
|
||||
clients.removeAt(clients.indexOf(client));
|
||||
ServerInfo_User *data = client->getUserInfo();
|
||||
|
|
|
@ -97,10 +97,12 @@ public:
|
|||
QList<PlayerReference> getPersistentPlayerReferences(const QString &userName) const;
|
||||
int getUsersCount() const;
|
||||
int getGamesCount() const;
|
||||
int getTCPUserCount() const { return tcpUserCount; }
|
||||
int getWebSocketUserCount() const { return webSocketUserCount; }
|
||||
private:
|
||||
QMultiMap<QString, PlayerReference> persistentPlayers;
|
||||
mutable QReadWriteLock persistentPlayersLock;
|
||||
int nextLocalGameId;
|
||||
int nextLocalGameId, tcpUserCount, webSocketUserCount;
|
||||
QMutex nextLocalGameIdMutex;
|
||||
|
||||
protected slots:
|
||||
|
|
|
@ -1259,7 +1259,7 @@ bool TcpServerSocketInterface::initTcpSession()
|
|||
bool enforceUserLimit = settingsCache->value("security/enable_max_user_limit", false).toBool();
|
||||
if (enforceUserLimit) {
|
||||
int userLimit = settingsCache->value("security/max_users_tcp", 500).toInt();
|
||||
int playerCount = (databaseInterface->getActiveUserCount(getConnectionType()) + 1);
|
||||
int playerCount = (server->getTCPUserCount() + 1);
|
||||
if (playerCount > userLimit){
|
||||
std::cerr << "Max Tcp Users Limit Reached, please increase the max_users_tcp setting." << std::endl;
|
||||
logger->logMessage(QString("Max Tcp Users Limit Reached, please increase the max_users_tcp setting."), this);
|
||||
|
@ -1313,7 +1313,7 @@ bool WebsocketServerSocketInterface::initWebsocketSession()
|
|||
bool enforceUserLimit = settingsCache->value("security/enable_max_user_limit", false).toBool();
|
||||
if (enforceUserLimit) {
|
||||
int userLimit = settingsCache->value("security/max_users_websocket", 500).toInt();
|
||||
int playerCount = (databaseInterface->getActiveUserCount(getConnectionType()) + 1);
|
||||
int playerCount = (server->getWebSocketUserCount() + 1);
|
||||
if (playerCount > userLimit){
|
||||
std::cerr << "Max Websocket Users Limit Reached, please increase the max_users_websocket setting." << std::endl;
|
||||
logger->logMessage(QString("Max Websocket Users Limit Reached, please increase the max_users_websocket setting."), this);
|
||||
|
|
Loading…
Reference in a new issue