aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMachiavelli <none@none>2010-09-25 01:05:24 +0200
committerMachiavelli <none@none>2010-09-25 01:05:24 +0200
commit62946f9ef643e33adbb0b4fe1d5139a1cb37dae1 (patch)
tree2bd1bc4cd742d42f188dcc1164525244225f47fa /src
parent154d11acc0afdf3639e6a07c931e35674102e44a (diff)
Core/DBLayer:
- Rewrite KeepAlive method for DatabaseWorkerPool. Use mysql_ping instead of explicit select queries, and also schedule KeepAlives for asynchronous threads. NOTE: While the function is implemented and previous keepalive calls were transformed, it´s possible the keepalive call will need to be placed in several other locations in the code. Please leave feedback on whether or not this fixes your timeout issues. Update issue #4062 --HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/server/authserver/Main.cpp2
-rw-r--r--src/server/shared/Database/DatabaseWorkerPool.h31
-rw-r--r--src/server/shared/Database/MySQLConnection.h1
-rw-r--r--src/server/worldserver/Master.cpp2
4 files changed, 34 insertions, 2 deletions
diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp
index dfc04f58512..d23aecf3313 100644
--- a/src/server/authserver/Main.cpp
+++ b/src/server/authserver/Main.cpp
@@ -314,7 +314,7 @@ extern int main(int argc, char **argv)
{
loopCounter = 0;
sLog.outDetail("Ping MySQL to keep connection alive");
- LoginDatabase.Query("SELECT 1 FROM realmlist");
+ LoginDatabase.KeepAlive();
}
#ifdef _WIN32
if (m_ServiceStatus == 0) stopEvent = true;
diff --git a/src/server/shared/Database/DatabaseWorkerPool.h b/src/server/shared/Database/DatabaseWorkerPool.h
index 6092381f86f..2c6afa2e9e2 100644
--- a/src/server/shared/Database/DatabaseWorkerPool.h
+++ b/src/server/shared/Database/DatabaseWorkerPool.h
@@ -43,6 +43,16 @@ enum MySQLThreadBundle
MYSQL_BUNDLE_ALL = MYSQL_BUNDLE_RA | MYSQL_BUNDLE_RAR | MYSQL_BUNDLE_WORLD,
};
+class PingOperation : public SQLOperation
+{
+ /// Operation for idle delaythreads
+ bool Execute()
+ {
+ m_conn->Ping();
+ return true;
+ }
+};
+
template <class T>
class DatabaseWorkerPool
{
@@ -304,6 +314,27 @@ class DatabaseWorkerPool
return PreparedQueryResult(ret);
}
+ void KeepAlive()
+ {
+ ConnectionMap::const_iterator itr;
+ {
+ /*! MapUpdate + unbundled threads */
+ ACE_Guard<ACE_Thread_Mutex> guard(m_connectionMap_mtx);
+ itr = m_sync_connections.find(ACE_Based::Thread::current());
+ if (itr != m_sync_connections.end())
+ itr->second->Ping();
+ }
+
+ if (m_bundle_conn)
+ m_bundle_conn->Ping();
+
+ /// Assuming all worker threads are free, every worker thread will receive 1 ping operation request
+ /// If one or more worker threads are busy, the ping operations will not be split evenly, but this doesn't matter
+ /// as the sole purpose is to prevent connections from idling.
+ for (size_t i = 0; i < m_async_connections.size(); ++i)
+ Enqueue(new PingOperation);
+ }
+
private:
unsigned long escape_string(char *to, const char *from, unsigned long length)
{
diff --git a/src/server/shared/Database/MySQLConnection.h b/src/server/shared/Database/MySQLConnection.h
index 09c30e7073e..93812421c8a 100644
--- a/src/server/shared/Database/MySQLConnection.h
+++ b/src/server/shared/Database/MySQLConnection.h
@@ -50,6 +50,7 @@ class MySQLConnection
void CommitTransaction();
operator bool () const { return m_Mysql != NULL; }
+ void Ping() { mysql_ping(m_Mysql); }
protected:
MYSQL* GetHandle() { return m_Mysql; }
diff --git a/src/server/worldserver/Master.cpp b/src/server/worldserver/Master.cpp
index f9f9c1450d4..3dca8d3935b 100644
--- a/src/server/worldserver/Master.cpp
+++ b/src/server/worldserver/Master.cpp
@@ -135,7 +135,7 @@ public:
{
loopCounter = 0;
sLog.outDetail ("Ping MySQL to keep connection alive");
- LoginDatabase.Query ("SELECT 1 FROM realmlist LIMIT 1");
+ LoginDatabase.KeepAlive();
}
}