diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index 2aaa2971a..25e7de507 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -69,7 +69,11 @@ class ProxySQL_Poll { volatile int pending_listener_del; ProxySQL_Poll() { +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK + loop_counters=new StatCounters(15,10); +#else loop_counters=new StatCounters(15,10,false); +#endif poll_timeout=0; loops=0; len=0; diff --git a/include/StatCounters.h b/include/StatCounters.h index 7f8e6206d..0b36ecd0f 100644 --- a/include/StatCounters.h +++ b/include/StatCounters.h @@ -1,10 +1,15 @@ #ifndef __CLASS_STAT_COUNTERS_H #define __CLASS_STAT_COUNTERS_H #include "proxysql_atomic.h" + +#define PROXYSQL_STATSCOUNTERS_NOLOCK class StatCounters { private: +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK +#else bool with_lock; rwlock_t _lock; +#endif int last; int keep; void cleanup() { @@ -26,10 +31,14 @@ class StatCounters { public: int len; int *val; +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK + StatCounters(int _l, int _k) { +#else StatCounters(int _l, int _k, bool _wl=false) { with_lock=_wl; if (with_lock) spinlock_rwlock_init(&_lock); +#endif last=0; keep=_k; len=_l; @@ -43,40 +52,61 @@ class StatCounters { free(val); } void set(int _i, int _v) { +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK +#else if (with_lock) spin_wrlock(&_lock); +#endif if ( _i > last ) { last=_i; cleanup(); } val[_i%len]=_v; +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK +#else if (with_lock) spin_wrunlock(&_lock); +#endif } void incr(int _i) { +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK +#else if (with_lock) spin_wrlock(&_lock); +#endif if ( _i > last ) { if ( _i > last + keep ) val[_i%len]=0; last=_i; cleanup(); } val[_i%len]++; +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK +#else if (with_lock) spin_wrunlock(&_lock); +#endif } void decr(int _i) { +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK +#else if (with_lock) spin_wrlock(&_lock); +#endif if ( _i > last ) { if ( _i > last + keep ) val[_i%len]=0; last=_i; cleanup(); } val[_i%len]--; +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK +#else if (with_lock) spin_wrunlock(&_lock); +#endif } int sum(int _i, int _k) { +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK +#else if (with_lock) spin_wrlock(&_lock); +#endif if ( _i > last ) { if ( _i > last + keep ) val[_i%len]=0; last=_i; cleanup(); @@ -86,8 +116,11 @@ class StatCounters { for (i=0; i<_k; i++) { ret+=val[(_i-i)%len]; } +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK +#else if (with_lock) spin_wrunlock(&_lock); +#endif return ret; } }; diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 6b40ddfe4..a6fbb7bd6 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -229,7 +229,11 @@ MySQL_Session::MySQL_Session() { pause_until=0; qpo=new Query_Processor_Output(); start_time=0; +#ifdef PROXYSQL_STATSCOUNTERS_NOLOCK + command_counters=new StatCounters(15,10); +#else command_counters=new StatCounters(15,10,false); +#endif healthy=1; autocommit=true; autocommit_on_hostgroup=-1;