diff options
| author | Machiavelli <none@none> | 2010-08-18 02:25:52 +0200 |
|---|---|---|
| committer | Machiavelli <none@none> | 2010-08-18 02:25:52 +0200 |
| commit | 87218eadcdeac5ba86a035edfd079958405cb24f (patch) | |
| tree | b72020ed0d390953b70d2026bf4c0b16c8271d11 /src/server/worldserver | |
| parent | 1ab2bd6d58adf35090ca3a9ef82eee00a14ff507 (diff) | |
* HIGHLY EXPERIMENTAL - USE AT OWN RISK *
Database Layer:
- Implement connection pooling: Instead of 1 delay thread per database, you can configure between 1 and 32 worker threads that have a seperate thread in the core and have a seperate connection to the MySQL server (based on raczman/Albator´s database layer for Trinitycore3)
- Implement a configurable thread bundle for synchroneous requests from seperate core threads (see worldserver.conf.dist for more info)
- Every mapupdate thread now has its seperate MySQL connection to the world and characters database
- Drop inconsistent PExecuteLog function - query logging will be implemented CONSISTENTLY later
- Drop current prepared statement interface - this will be done *properly* later
- You´ll need to update your worldserver.conf and authserver.conf
- You´re recommended to make a backup of your databases before using this.
* HIGHLY EXPERIMENTAL - USE AT OWN RISK *
* HIGHLY EXPERIMENTAL - USE AT OWN RISK *
etc.
--HG--
branch : trunk
Diffstat (limited to 'src/server/worldserver')
| -rw-r--r-- | src/server/worldserver/CommandLine/CliRunnable.cpp | 36 | ||||
| -rw-r--r-- | src/server/worldserver/Master.cpp | 47 | ||||
| -rw-r--r-- | src/server/worldserver/WorldThread/WorldRunnable.cpp | 37 | ||||
| -rw-r--r-- | src/server/worldserver/worldserver.conf.dist | 30 |
4 files changed, 129 insertions, 21 deletions
diff --git a/src/server/worldserver/CommandLine/CliRunnable.cpp b/src/server/worldserver/CommandLine/CliRunnable.cpp index d105f29f3c2..e44ec1ada94 100644 --- a/src/server/worldserver/CommandLine/CliRunnable.cpp +++ b/src/server/worldserver/CommandLine/CliRunnable.cpp @@ -690,8 +690,28 @@ int kb_hit_return() /// %Thread start void CliRunnable::run() { - ///- Init new SQL thread for the world database (one connection call enough) - WorldDatabase.ThreadStart(); // let thread do safe mySQL requests + ///- Init MySQL threads or connections + bool needInit = true; + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_WORLDDB) & MYSQL_BUNDLE_RA)) + { + WorldDatabase.Init_MySQL_Connection(); + needInit = false; + } + + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_LOGINDB) & MYSQL_BUNDLE_RA)) + { + LoginDatabase.Init_MySQL_Connection(); + needInit = false; + } + + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_CHARDB) & MYSQL_BUNDLE_RA)) + { + CharacterDatabase.Init_MySQL_Connection(); + needInit = false; + } + + if (needInit) + MySQL::Thread_Init(); char commandbuf[256]; @@ -759,6 +779,14 @@ void CliRunnable::run() } - ///- End the database thread - WorldDatabase.ThreadEnd(); // free mySQL thread resources + ///- Free MySQL thread resources and deallocate lingering connections + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_WORLDDB) & MYSQL_BUNDLE_RA)) + WorldDatabase.End_MySQL_Connection(); + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_LOGINDB) & MYSQL_BUNDLE_RA)) + LoginDatabase.End_MySQL_Connection(); + + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_CHARDB) & MYSQL_BUNDLE_RA)) + CharacterDatabase.End_MySQL_Connection(); + if (needInit) + MySQL::Thread_End(); } diff --git a/src/server/worldserver/Master.cpp b/src/server/worldserver/Master.cpp index ce2f442fa8f..ab906cb9b42 100644 --- a/src/server/worldserver/Master.cpp +++ b/src/server/worldserver/Master.cpp @@ -370,9 +370,9 @@ int Master::Run() clearOnlineAccounts(); ///- Wait for delay threads to end - CharacterDatabase.HaltDelayThread(); - WorldDatabase.HaltDelayThread(); - LoginDatabase.HaltDelayThread(); + CharacterDatabase.Close(); + WorldDatabase.Close(); + LoginDatabase.Close(); sLog.outString( "Halting process..." ); @@ -439,8 +439,8 @@ bool Master::_StartDB() { sLog.SetLogDB(false); std::string dbstring; + uint8 num_threads; - ///- Get world database info from configuration file dbstring = sConfig.GetStringDefault("WorldDatabaseInfo", ""); if (dbstring.empty()) { @@ -448,13 +448,20 @@ bool Master::_StartDB() return false; } - ///- Initialise the world database - if( !WorldDatabase.Initialize(dbstring.c_str())) + num_threads = sConfig.GetIntDefault("WorldDatabase.WorkerThreads", 1); + if (num_threads < 1 || num_threads > 32) { - sLog.outError("Cannot connect to world database %s",dbstring.c_str()); + sLog.outError("World database: invalid number of worker threads specified. " + "Please pick a value between 1 and 32."); return false; } + ///- Initialise the world database + if (!WorldDatabase.Open(dbstring, num_threads)) + { + sLog.outError("Cannot connect to world database %s", dbstring.c_str()); + return false; + } ///- Get character database info from configuration file dbstring = sConfig.GetStringDefault("CharacterDatabaseInfo", ""); if (dbstring.empty()) @@ -463,13 +470,20 @@ bool Master::_StartDB() return false; } - ///- Initialise the Character database - if (!CharacterDatabase.Initialize(dbstring.c_str())) + num_threads = sConfig.GetIntDefault("CharacterDatabase.WorkerThreads", 1); + if (num_threads < 1 || num_threads > 32) { - sLog.outError("Cannot connect to Character database %s",dbstring.c_str()); + sLog.outError("Character database: invalid number of worker threads specified. " + "Please pick a value between 1 and 32."); return false; } + ///- Initialise the Character database + if (!CharacterDatabase.Open(dbstring, num_threads)) + { + sLog.outError("Cannot connect to Character database %s", dbstring.c_str()); + return false; + } ///- Get login database info from configuration file dbstring = sConfig.GetStringDefault("LoginDatabaseInfo", ""); if (dbstring.empty()) @@ -478,13 +492,20 @@ bool Master::_StartDB() return false; } - ///- Initialise the login database - if (!LoginDatabase.Initialize(dbstring.c_str())) + num_threads = sConfig.GetIntDefault("LoginDatabase.WorkerThreads", 1); + if (num_threads < 1 || num_threads > 32) { - sLog.outError("Cannot connect to login database %s",dbstring.c_str()); + sLog.outError("Login database: invalid number of worker threads specified. " + "Please pick a value between 1 and 32."); return false; } + ///- Initialise the login database + if (!LoginDatabase.Open(dbstring, num_threads)) + { + sLog.outError("Cannot connect to login database %s", dbstring.c_str()); + return false; + } ///- Get the realm Id from the configuration file realmID = sConfig.GetIntDefault("RealmID", 0); if (!realmID) diff --git a/src/server/worldserver/WorldThread/WorldRunnable.cpp b/src/server/worldserver/WorldThread/WorldRunnable.cpp index 67a3937b97d..555f174b6c8 100644 --- a/src/server/worldserver/WorldThread/WorldRunnable.cpp +++ b/src/server/worldserver/WorldThread/WorldRunnable.cpp @@ -43,8 +43,27 @@ extern int m_ServiceStatus; /// Heartbeat for the World void WorldRunnable::run() { - ///- Init new SQL thread for the world database - WorldDatabase.ThreadStart(); // let thread do safe mySQL requests (one connection call enough) + ///- Init MySQL threads or connections + bool needInit = true; + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_WORLDDB) & MYSQL_BUNDLE_RA)) + { + WorldDatabase.Init_MySQL_Connection(); + needInit = false; + } + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_LOGINDB) & MYSQL_BUNDLE_RA)) + { + LoginDatabase.Init_MySQL_Connection(); + needInit = false; + } + + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_CHARDB) & MYSQL_BUNDLE_RA)) + { + CharacterDatabase.Init_MySQL_Connection(); + needInit = false; + } + + if (needInit) + MySQL::Thread_Init(); sWorld.InitResultQueue(); @@ -99,6 +118,16 @@ void WorldRunnable::run() sMapMgr.UnloadAll(); // unload all grids (including locked in memory) - ///- End the database thread - WorldDatabase.ThreadEnd(); // free mySQL thread resources + ///- Free MySQL thread resources and deallocate lingering connections + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_WORLDDB) & MYSQL_BUNDLE_RA)) + WorldDatabase.End_MySQL_Connection(); + + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_LOGINDB) & MYSQL_BUNDLE_RA)) + LoginDatabase.End_MySQL_Connection(); + + if (!(sWorld.getConfig(CONFIG_MYSQL_BUNDLE_CHARDB) & MYSQL_BUNDLE_RA)) + CharacterDatabase.End_MySQL_Connection(); + + if (needInit) + MySQL::Thread_End(); } diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist index 90a520529cc..d847a7c0467 100644 --- a/src/server/worldserver/worldserver.conf.dist +++ b/src/server/worldserver/worldserver.conf.dist @@ -36,6 +36,30 @@ # .;/path/to/unix_socket;username;password;database # - use Unix sockets in Unix/Linux # +# LoginDatabase.WorkerThreads +# WorldDatabase.WorkerThreads +# CharacterDatabase.WorkerThreads +# The amount of worker threads spawned to handle +# asynchroneous MySQL statements +# Each worker thread is mirrored with its own +# connection to the MySQL server and their own +# thread on the MySQL server. +# Default: 1 +# +# LoginDatabase.ThreadBundleMask +# WorldDatabase.ThreadBundleMask +# CharacterDatabase.ThreadBundleMask +# Defines which runnable threads are bundled into one synchroneous +# connection. Runnables not specified in the mask will have their +# seperate connection to the MySQL server. +# Value is a bitmask consisting of: +# MYSQL_BUNDLE_NONE = 0, Each task will run their own MySQL connection +# MYSQL_BUNDLE_CLI = 1, Commandline interface thread +# MYSQL_BUNDLE_RA = 2, Remote admin thread +# MYSQL_BUNDLE_RAR = 4, Reactor runnable thread +# MYSQL_BUNDLE_WORLD = 8, WorldRunnable +# MYSQL_BUNDLE_ALL = 15, All bundled together +# # MaxPingTime # Settings for maximum database-ping interval (minutes between pings) # @@ -53,6 +77,12 @@ LogsDir = "" LoginDatabaseInfo = "127.0.0.1;3306;trinity;trinity;auth" WorldDatabaseInfo = "127.0.0.1;3306;trinity;trinity;world" CharacterDatabaseInfo = "127.0.0.1;3306;trinity;trinity;characters" +LoginDatabase.WorkerThreads = 1 +WorldDatabase.WorkerThreads = 1 +CharacterDatabase.WorkerThreads = 1 +LoginDatabase.ThreadBundleMask = 15 +WorldDatabase.ThreadBundleMask = 15 +CharacterDatabase.ThreadBundleMask = 15 MaxPingTime = 30 WorldServerPort = 8085 BindIP = "0.0.0.0" |
