Skip to content

Commit

Permalink
Remove spinlock from StatCounters (unused) #977
Browse files Browse the repository at this point in the history
  • Loading branch information
renecannao committed Jun 8, 2017
1 parent 64eb4cd commit fc58e51
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/MySQL_Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions include/StatCounters.h
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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;
}
};
Expand Down
4 changes: 4 additions & 0 deletions lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fc58e51

Please sign in to comment.