Speed up start time with multiple listeners #3699

When multiple listeners are configured start up time is slow.
This commit batches together the configuration of all the listeners.
pull/3700/head
René Cannaò 4 years ago
parent f6facace11
commit 33fba7641a

@ -584,6 +584,9 @@ class MySQL_Threads_Handler
std::array<prometheus::Counter*, p_th_counter::__size> p_counter_array {};
std::array<prometheus::Gauge*, p_th_gauge::__size> p_gauge_array {};
} status_variables;
std::atomic<bool> bootstrapping_listeners;
/**
* @brief Update the client host cache with the supplied 'client_sockaddr',
* and the supplied 'error' parameter specifying if there was a connection

@ -1028,6 +1028,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() {
#endif // IDLE_THREADS
stacksize=0;
shutdown_=0;
bootstrapping_listeners = true;
pthread_rwlock_init(&rwlock,NULL);
pthread_attr_init(&attr);
// Zero initialize all variables
@ -2368,6 +2369,10 @@ void MySQL_Threads_Handler::shutdown_threads() {
}
void MySQL_Threads_Handler::start_listeners() {
// we set bootstrapping_listeners to true
// In this way MySQL_Thread will knows there are more listeners to add
// and it will continue looping until all listeners are added
bootstrapping_listeners = true;
char *_tmp=NULL;
_tmp=GloMTH->get_variable((char *)"interfaces");
if (strlen(_tmp)==0) {
@ -2382,6 +2387,8 @@ void MySQL_Threads_Handler::start_listeners() {
listener_add((char *)token);
}
free_tokenizer( &tok );
// no more listeners to add
bootstrapping_listeners = false;
}
void MySQL_Threads_Handler::stop_listeners() {
@ -3104,9 +3111,15 @@ __run_skip_1a:
#endif // IDLE_THREADS
pthread_mutex_unlock(&thread_mutex);
while ((n=__sync_add_and_fetch(&mypolls.pending_listener_add,0))) { // spin here
poll_listener_add(n);
assert(__sync_bool_compare_and_swap(&mypolls.pending_listener_add,n,0));
while ( // spin here if ...
(n=__sync_add_and_fetch(&mypolls.pending_listener_add,0)) // there is a new listener to add
||
(GloMTH->bootstrapping_listeners == true) // MySQL_Thread_Handlers has more listeners to configure
) {
if (n) {
poll_listener_add(n);
assert(__sync_bool_compare_and_swap(&mypolls.pending_listener_add,n,0));
}
}
proxy_debug(PROXY_DEBUG_NET, 7, "poll_timeout=%llu\n", mypolls.poll_timeout);

Loading…
Cancel
Save