Scalability improvements #644

Some minor yet important tweak to spinloop
Replaced rand() with fastrand()
pull/739/head
René Cannaò 10 years ago
parent 21fdb12e0b
commit 7d3814e5b9

@ -22,6 +22,15 @@ struct _PtrSize_t {
};
*/
#ifndef def_fastrand
inline int fastrand() {
g_seed = (214013*g_seed+2531011);
//return (g_seed>>16)&0x7FFF;
return (g_seed>>16);
}
#define def_fastrand
#endif
class PtrArray {
private:
void expand(unsigned int);

@ -16,9 +16,9 @@ struct _rwlock_t {
/* Pause instruction to prevent excess processor bus usage */
#define cpu_relax_pa() asm volatile("pause\n": : :"memory")
#define cpu_relax_us() usleep(10)
#define cpu_relax_us() usleep(1)
#define RELAX_TRIES 1
#define RELAX_TRIES 100
static inline unsigned xchg_32(void *ptr, unsigned x) {
__asm__ __volatile__("xchgl %0,%1"

@ -773,6 +773,9 @@ __thread char * mysql_thread___monitor_password;
#ifdef DEBUG
__thread bool mysql_thread___session_debug;
#endif /* DEBUG */
__thread unsigned int g_seed;
#endif /* GLOBAL_DEFINED_HOSTGROUP */
#else
extern ProxySQL_GlobalVariables GloVars;
@ -853,6 +856,7 @@ extern __thread char * mysql_thread___monitor_password;
#ifdef DEBUG
extern __thread bool mysql_thread___session_debug;
#endif /* DEBUG */
extern __thread unsigned int g_seed;
#endif /* PROXYSQL_EXTERN */

@ -773,7 +773,8 @@ MySrvC *MyHGC::get_random_MySrvC() {
return NULL; // if we reach here, we couldn't find any target
}
unsigned int k=rand()%New_sum;
//unsigned int k=rand()%New_sum;
unsigned int k=fastrand()%New_sum;
k++;
New_sum=0;
@ -816,7 +817,8 @@ MySQL_Connection * MySrvConnList::get_random_MyConn() {
unsigned int i;
unsigned int l=conns->len;
if (l) {
i=rand()%l;
//i=rand()%l;
i=fastrand()%l;
conn=(MySQL_Connection *)conns->remove_index_fast(i);
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Returning MySQL Connection %p, server %s:%d\n", conn, conn->parent->address, conn->parent->port);
return conn;

Loading…
Cancel
Save