Make keepalive ping checks more efficient

The code now only checks the need for a keepalive ping once every
keepalive interval. Reduced the number of mxs_clock calls to one so that
all servers use the same value.
This commit is contained in:
Markus Mäkelä 2018-12-09 14:33:50 +02:00
parent 5420bf618d
commit 1fa3b133c7
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
3 changed files with 20 additions and 14 deletions

View File

@ -41,23 +41,27 @@ void RWSplitSession::handle_connection_keepalive(SRWBackend& target)
mxb_assert(target);
MXB_AT_DEBUG(int nserv = 0);
/** Each heartbeat is 1/10th of a second */
int keepalive = m_config.connection_keepalive * 10;
int64_t keepalive = m_config.connection_keepalive * 10;
int64_t now = mxs_clock();
for (auto it = m_backends.begin(); it != m_backends.end(); it++)
if (now - m_last_keepalive_check > keepalive)
{
SRWBackend backend = *it;
if (backend->in_use() && backend != target && !backend->is_waiting_result())
for (auto it = m_backends.begin(); it != m_backends.end(); it++)
{
MXB_AT_DEBUG(nserv++);
int diff = mxs_clock() - backend->dcb()->last_read;
SRWBackend backend = *it;
if (diff > keepalive)
if (backend->in_use() && backend != target && !backend->is_waiting_result())
{
MXS_INFO("Pinging %s, idle for %ld seconds",
backend->name(),
MXS_CLOCK_TO_SEC(diff));
modutil_ignorable_ping(backend->dcb());
MXB_AT_DEBUG(nserv++);
int64_t diff = now - backend->dcb()->last_read;
if (diff > keepalive)
{
MXS_INFO("Pinging %s, idle for %ld seconds",
backend->name(),
MXS_CLOCK_TO_SEC(diff));
modutil_ignorable_ping(backend->dcb());
}
}
}
}

View File

@ -17,6 +17,7 @@
#include <maxscale/modutil.hh>
#include <maxscale/poll.h>
#include <maxscale/clock.h>
using namespace maxscale;
@ -28,11 +29,11 @@ RWSplitSession::RWSplitSession(RWSplit* instance,
, m_backends(backends)
, m_current_master(master)
, m_config(instance->config())
, m_last_keepalive_check(mxs_clock())
, m_nbackends(instance->service()->n_dbref)
, m_client(session->client_dcb)
, m_sescmd_count(1)
, // Needs to be a positive number to work
m_expected_responses(0)
, m_expected_responses(0)
, m_query_queue(NULL)
, m_router(instance)
, m_sent_sescmd(0)

View File

@ -136,6 +136,7 @@ public:
mxs::SRWBackend m_target_node; /**< The currently locked target node */
mxs::SRWBackend m_prev_target; /**< The previous target where a query was sent */
Config m_config; /**< Configuration for this session */
int m_last_keepalive_check; /**< When the last ping was done */
int m_nbackends; /**< Number of backend servers (obsolete) */
DCB* m_client; /**< The client DCB */
uint64_t m_sescmd_count; /**< Number of executed session commands */