mirror of
https://github.com/mangosfour/server.git
synced 2025-12-18 10:37:01 +00:00
[11045] Rewrite internals of DB layer. Simplify code and use less locking. Spawn and use separate connections for sync and async DB requests. Implement database connection pool for SELECT queries. Up to maximum 16 connections supported. Disable 'autocommit' mode for MySQL.
UPDATE YOUR CONFIGS! Defaults: LoginDatabaseConnections = 1 WorldDatabaseConnections = 1 CharacterDatabaseConnections = 1 If you are not using <mtmaps> patch do not change the default settings - this is useless. You can try following option in your MySQL config to squeeze even more performance from your DB: [mysqld] transaction-isolation = READ-COMMITTED Great thanks to Undergarun, kero99 and selector for making tests and providing very useful feedback and DB statistics! Have fun :) Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
parent
9bc37afa28
commit
631ce36680
19 changed files with 655 additions and 547 deletions
|
|
@ -34,6 +34,31 @@
|
|||
#include <mysql.h>
|
||||
#endif
|
||||
|
||||
class MANGOS_DLL_SPEC MySQLConnection : public SqlConnection
|
||||
{
|
||||
public:
|
||||
MySQLConnection() : mMysql(NULL) {}
|
||||
~MySQLConnection() { mysql_close(mMysql); }
|
||||
|
||||
bool Initialize(const char *infoString);
|
||||
|
||||
QueryResult* Query(const char *sql);
|
||||
QueryNamedResult* QueryNamed(const char *sql);
|
||||
bool Execute(const char *sql);
|
||||
|
||||
unsigned long escape_string(char *to, const char *from, unsigned long length);
|
||||
|
||||
bool BeginTransaction();
|
||||
bool CommitTransaction();
|
||||
bool RollbackTransaction();
|
||||
|
||||
private:
|
||||
bool _TransactionCmd(const char *sql);
|
||||
bool _Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount);
|
||||
|
||||
MYSQL *mMysql;
|
||||
};
|
||||
|
||||
class MANGOS_DLL_SPEC DatabaseMysql : public Database
|
||||
{
|
||||
friend class MaNGOS::OperatorNew<DatabaseMysql>;
|
||||
|
|
@ -44,38 +69,18 @@ class MANGOS_DLL_SPEC DatabaseMysql : public Database
|
|||
|
||||
//! Initializes Mysql and connects to a server.
|
||||
/*! infoString should be formated like hostname;username;password;database. */
|
||||
bool Initialize(const char *infoString);
|
||||
void InitDelayThread();
|
||||
void HaltDelayThread();
|
||||
QueryResult* Query(const char *sql);
|
||||
QueryNamedResult* QueryNamed(const char *sql);
|
||||
bool Execute(const char *sql);
|
||||
bool DirectExecute(const char* sql);
|
||||
bool BeginTransaction();
|
||||
bool CommitTransaction();
|
||||
bool RollbackTransaction();
|
||||
|
||||
operator bool () const { return mMysql != NULL; }
|
||||
|
||||
unsigned long escape_string(char *to, const char *from, unsigned long length);
|
||||
using Database::escape_string;
|
||||
|
||||
// must be call before first query in thread
|
||||
void ThreadStart();
|
||||
// must be call before finish thread run
|
||||
void ThreadEnd();
|
||||
|
||||
protected:
|
||||
virtual SqlConnection * CreateConnection();
|
||||
|
||||
private:
|
||||
ACE_Thread_Mutex mMutex; // For thread safe operations between core and mySQL server
|
||||
ACE_Thread_Mutex nMutex; // For thread safe operations on m_transQueues
|
||||
|
||||
ACE_Based::Thread * tranThread;
|
||||
|
||||
MYSQL *mMysql;
|
||||
|
||||
static size_t db_count;
|
||||
|
||||
bool _TransactionCmd(const char *sql);
|
||||
bool _Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue