MXS-1549: Count RO and RW transactions in readwritesplit

Readwritesplit now keeps track of how many read-only and read-write
transactions have been executed. This allows a coarse estimation of how
widely read-only transactions are done even without explicit read-only
transactions being used (i.e. START TRANSACTION READ ONLY).
This commit is contained in:
Markus Mäkelä
2018-06-23 09:52:30 +03:00
parent b59f607471
commit e610b285b9
3 changed files with 21 additions and 18 deletions

View File

@ -370,6 +370,10 @@ void RWSplit::diagnostics(DCB *dcb)
stats().n_slave, slave_pct);
dcb_printf(dcb, "\tNumber of queries forwarded to all: %" PRIu64 " (%.2f%%)\n",
stats().n_all, all_pct);
dcb_printf(dcb, "\tNumber of read-write transactions: %" PRIu64 "\n",
stats().n_rw_trx);
dcb_printf(dcb, "\tNumber of read-only transactions: %" PRIu64 "\n",
stats().n_ro_trx);
dcb_printf(dcb, "\tNumber of replayed transactions: %" PRIu64 "\n",
stats().n_trx_replay);
@ -401,6 +405,8 @@ json_t* RWSplit::diagnostics_json() const
json_object_set_new(rval, "route_master", json_integer(stats().n_master));
json_object_set_new(rval, "route_slave", json_integer(stats().n_slave));
json_object_set_new(rval, "route_all", json_integer(stats().n_all));
json_object_set_new(rval, "rw_transactions", json_integer(stats().n_rw_trx));
json_object_set_new(rval, "ro_transactions", json_integer(stats().n_ro_trx));
json_object_set_new(rval, "replayed_transactions", json_integer(stats().n_trx_replay));
const char *weightby = serviceGetWeightingParameter(service());

View File

@ -203,24 +203,14 @@ struct Config
*/
struct Stats
{
public:
Stats():
n_sessions(0),
n_queries(0),
n_master(0),
n_slave(0),
n_all(0),
n_trx_replay(0)
{
}
uint64_t n_sessions; /**< Number sessions created */
uint64_t n_queries; /**< Number of queries forwarded */
uint64_t n_master; /**< Number of stmts sent to master */
uint64_t n_slave; /**< Number of stmts sent to slave */
uint64_t n_all; /**< Number of stmts sent to all */
uint64_t n_trx_replay; /**< Number of replayed transactions */
uint64_t n_sessions = 0; /**< Number sessions created */
uint64_t n_queries = 0; /**< Number of queries forwarded */
uint64_t n_master = 0; /**< Number of stmts sent to master */
uint64_t n_slave = 0; /**< Number of stmts sent to slave */
uint64_t n_all = 0; /**< Number of stmts sent to all */
uint64_t n_trx_replay = 0; /**< Number of replayed transactions */
uint64_t n_ro_trx = 0; /**< Read-only transaction count */
uint64_t n_rw_trx = 0; /**< Read-write transaction count */
};
class RWSplitSession;

View File

@ -185,6 +185,13 @@ bool RWSplitSession::route_single_stmt(GWBUF *querybuf)
}
else
{
if (session_trx_is_ending(m_client->session))
{
atomic_add_uint64(m_qc.is_trx_still_read_only() ?
&m_router->stats().n_ro_trx :
&m_router->stats().n_rw_trx, 1);
}
// If delayed query retry is enabled, we need to store the current statement
bool store_stmt = m_config.delayed_retry;