Merge pull request #3700 from sysown/v2.x-multiple_port_delay

Speed up start time with multiple listeners #3699
pull/3707/head
René Cannaò 4 years ago committed by GitHub
commit 6485d1549d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -583,6 +583,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

@ -1027,6 +1027,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
@ -2365,6 +2366,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) {
@ -2379,6 +2384,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() {
@ -3096,9 +3103,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