From: Mayank Prasad Date: August 23 2012 3:27pm Subject: bzr push into mysql-5.6 branch (mayank.prasad:4142 to 4143) WL#6372 List-Archive: http://lists.mysql.com/commits/144606 Message-Id: <201208231527.q7NFRgnm017098@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 4143 Mayank Prasad 2012-08-23 wl#6372 : Post-Iris changes to Server defaults Details: - Modified code to make sure thread/host_cache_size is being set to default value only when they are not explicitly set by user. modified: mysys_ssl/my_getopt.cc sql/mysqld.cc 4142 Mayank Prasad 2012-08-22 wl#6372 : Post-Iris changes to Server defaults Details: - Implemented . thread_cache_size . host_cache_size modified: sql/mysqld.cc === modified file 'mysys_ssl/my_getopt.cc' --- a/mysys_ssl/my_getopt.cc 2012-06-09 14:11:09 +0000 +++ b/mysys_ssl/my_getopt.cc 2012-08-23 15:26:30 +0000 @@ -150,6 +150,16 @@ void my_getopt_register_get_addr(my_geto @return error in case of ambiguous or unknown options, 0 on success. */ +#define SET_OPTIONS_DEFAULT_VALUE(_str, _length, _optend) \ + optp_temp= longopts; \ + opt_found= findopt(_str, _length, &optp_temp, NULL); \ + if(opt_found) \ + { \ + void *value; \ + value= (void*)optp_temp->value; \ + if ((error= setval(optp_temp, value, _optend, false))) \ + return error; \ + } int handle_options(int *argc, char ***argv, const struct my_option *longopts, my_get_one_option get_one_option) @@ -163,6 +173,7 @@ int handle_options(int *argc, char ***ar void *value; int error, i; my_bool is_cmdline_arg= 1; + my_bool is_thread_cache_size_set= false, is_host_cache_size_set= false; /* handle_options() assumes arg0 (program name) always exists */ DBUG_ASSERT(argc && *argc >= 1); @@ -549,6 +560,15 @@ int handle_options(int *argc, char ***ar return error; if (get_one_option && get_one_option(optp->id, optp, argument)) return EXIT_UNSPECIFIED_ERROR; + + if(strcmp(optp->name,"thread_cache_size") == 0) + { + is_thread_cache_size_set= true; + } + else if(strcmp(optp->name,"host_cache_size") == 0) + { + is_host_cache_size_set= true; + } (*argc)--; /* option handled (long), decrease argument count */ } @@ -562,6 +582,84 @@ int handle_options(int *argc, char ***ar to the program, yet to be (possibly) handled. */ (*argv)[argvpos]= 0; + + /* + If values for thread_cache_size and host_cache_size are not set explicitly + set them to default values which are dependent on max_connections. + Note: max_connections is being updated depending on max_open_files in + init_common_variables(), so its not necessary max_connections would be what + is being set by command-line or in config file. + */ + if(!is_thread_cache_size_set || !is_host_cache_size_set) + { + char *optend; + const struct my_option *optp_temp; + unsigned long default_value, max_connections; + static void* max_connections_ptr; + + /* + There is no way to access max_connections global variable here. So keep + pointer to address where max_connections is stored. Using this we can + get value of max_connections. + */ + optp_temp= longopts; + char *opt_str= (char*)"max_connections="; + if((opt_found= findopt(opt_str, 15, &optp_temp, NULL))) + { + max_connections_ptr= optp_temp->value; + } + + /* + Get value of max_connections global variable. + */ + if(max_connections_ptr) + { + max_connections= *(unsigned long*)max_connections_ptr; + } + + if(!is_thread_cache_size_set) + { + char buff[80], *opt_str=(char*)"thread_cache_size="; + + /* + Calculate default value to be set. + */ + default_value= 8 + max_connections/100; + default_value= default_value > 100 ? 100 : default_value; + + /* + Generate option string based on max_connections. + */ + optend= &buff[0]; + optend= ullstr(default_value, (char*)optend); + SET_OPTIONS_DEFAULT_VALUE(opt_str, 17, optend); + } + + if(!is_host_cache_size_set) + { + char buff[80], *opt_str=(char*)"host_cache_size="; + + /* + Calculate default value to be set. + */ + if (max_connections <= 500) + { + default_value= 128 + max_connections; + } + else + { + default_value= (628 + ((max_connections - 500) / 20 )); + default_value= default_value > 2000 ? 2000 : default_value; + } + + /* + Generate option string based on max_connections. + */ + optend= &buff[0]; + optend= ullstr(default_value, (char*)optend); + SET_OPTIONS_DEFAULT_VALUE(opt_str, 15, optend); + } + } return 0; } === modified file 'sql/mysqld.cc' --- a/sql/mysqld.cc 2012-08-22 12:28:26 +0000 +++ b/sql/mysqld.cc 2012-08-23 15:26:30 +0000 @@ -5154,32 +5154,6 @@ int mysqld_main(int argc, char **argv) if (init_common_variables()) unireg_abort(1); // Will do exit - /* - Set values for thread_cache_size and host_cache_size which are - dependent on max_connections. - Note: max_connections is being updated depending on max_open_files in - init_common_variables(), so its not necessary max_connections would be what - is being set by command-line or in config file. - */ - max_blocked_pthreads= (8 + max_connections / 100) > 100 ? - 100 : (8 + max_connections / 100); - - if (max_connections <= 500) - { - host_cache_size = 128 + max_connections; - } - else - { - host_cache_size = (628 + ((max_connections - 500) / 20 )); - /* - Cap host_cache_size at 2000. - */ - if(host_cache_size > 2000) - { - host_cache_size= 2000; - } - } - my_init_signals(); #if defined(__ia64__) || defined(__ia64) /* No bundle (reason: useless for push emails).