diff options
author | Michael Widenius <monty@askmonty.org> | 2013-03-25 11:13:42 +0200 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2013-03-25 11:13:42 +0200 |
commit | d8986fd6c3b69d2970e66684e1d00dd603fc9ab7 (patch) | |
tree | c9beb686d03c141643d1afb95f0aa2bdb8cbbc8d /mysys | |
parent | 8b047ac5c4b7d326742fd8b7a165a17089a9d83b (diff) | |
download | mariadb-git-d8986fd6c3b69d2970e66684e1d00dd603fc9ab7.tar.gz |
Speed up connection time:
-Change my_rnd() slightly to make it safer if two threads use it at the same time.
-Avoid some sprintf and strmov in vio.
-Changed thread_count to be automaticly incremented (instead of under LOCK_thread_count).
-Thread cache now uses LOCK_thread_cache instead of LOCK_thread_count.
-Moved delete thd out from LOCK_thread_count.
-Save some mysql_cond_broadcast(&COND_thread_count) calls.
-Removed call to getsockname() during connect.
-Initialize random generator without locks.
Other things:
-Fixed test cases that depends on changes for LOCK_grant
-Added thread_safe_decrement32() and thread_safe_increment32()
-Removed sql_rnd_with_mutex() and get_thread_running()
-In check_table_access() don't lock LOCK_grant if we can resolve the grant with user or db level grants (the normal case).
-Don't use a lock for setting THD->query_id.
-Fixed bug where thd->set_query_id() could be set to same value by multiple threads.
Thanks to Yoshinori Matsunobu for the benchmark of connection speed and to
Domas Mituzas for the inspiration for many of the fixes.
include/violite.h:
Change desc to a string pointer
mysql-test/suite/perfschema/r/all_instances.result:
Added new mutex
mysql-test/suite/perfschema/t/func_mutex.test:
Test for LOCK_system_variables_hash instead of LOCK_grant, as LOCK_grant is not anymore always taken for SELECT's.
mysys/my_gethwaddr.c:
More DBUG
mysys/my_rnd.c:
Change my_rnd() slightly to make it safer if two threads use it at the same time.
sql/event_scheduler.cc:
Changed thread_count to be automically incremented
Moved some safe things out from LOCK_thread_count.
Simplify deleting of THD for running thread.
sql/mysqld.cc:
Changed thread_count to be automically incremented
Thread cache now uses LOCK_thread_cache instead of LOCK_thread_count
Added delete_running_thd()
Moved delete thd out from LOCK_thread_count
More DBUG
Only call mysql_cond_broadcast(&COND_thread_count) if thread_count is 0
Removed call to getsockname() (old not anymore needed check)
sql/mysqld.h:
Removed sql_rnd_with_mutex() (not needed anymore)
Removed not used function get_thread_running()
Added thread_safe_decrement32() and thread_safe_increment32()
Simplified dec_thread_running() and inc_thread_running()
next_query_id() should return the original value for global_query_id, not the next one.
(Bug introduced with MySQL 5.5 merge).
sql/sql_acl.cc:
In check_table_access() don't lock LOCK_grant if we can resolve the grant with user or db level grants (the normal case).
sql/sql_class.cc:
Removed thd_lock_thread_count() and thd_unlock_thread_count()
Initialize random generator without locks
Don't use a lock for setting THD->query_id.
(This is only accessed by thread owning the THD)
sql/sql_class.h:
Don't use a lock for setting THD->query_id.
sql/sql_insert.cc:
Changed thread_count to be automically incremented
sql/sql_parse.cc:
Changed thread_count to be automically incremented
Fixed bug where thd->set_query_id() could be set to same value by multiple threads.
vio/vio.c:
Don't generate 'desc' with sprintf/strmov. Assign a pointer instead.
(Good enough as this is just for debugging)
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/my_gethwaddr.c | 10 | ||||
-rw-r--r-- | mysys/my_rnd.c | 15 |
2 files changed, 19 insertions, 6 deletions
diff --git a/mysys/my_gethwaddr.c b/mysys/my_gethwaddr.c index 74dae29f235..aa63138b48c 100644 --- a/mysys/my_gethwaddr.c +++ b/mysys/my_gethwaddr.c @@ -87,13 +87,17 @@ my_bool my_gethwaddr(uchar *to) int fd, res= 1; struct ifreq ifr[32]; struct ifconf ifc; + DBUG_ENTER("my_gethwaddr"); ifc.ifc_req= ifr; ifc.ifc_len= sizeof(ifr); fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) + { + DBUG_PRINT("error", ("socket() call failed with %d", errno)); goto err; + } if (ioctl(fd, SIOCGIFCONF, (char*)&ifc) >= 0) { @@ -106,8 +110,8 @@ my_bool my_gethwaddr(uchar *to) ETHER_ADDR_LEN); #else /* - A bug in OpenSolaris used to prevent non-root from getting a mac address: - {no url. Oracle killed the old OpenSolaris bug database} + A bug in OpenSolaris used to prevent non-root from getting a mac + address: {no url. Oracle killed the old OpenSolaris bug database} Thus, we'll use an alternative method and extract the address from the arp table. @@ -124,7 +128,7 @@ my_bool my_gethwaddr(uchar *to) close(fd); err: - return res; + DBUG_RETURN(res); } #elif defined(_WIN32) diff --git a/mysys/my_rnd.c b/mysys/my_rnd.c index 178bcd9c539..d043c8529ad 100644 --- a/mysys/my_rnd.c +++ b/mysys/my_rnd.c @@ -45,11 +45,20 @@ void my_rnd_init(struct my_rnd_struct *rand_st, ulong seed1, ulong seed2) RETURN VALUE generated pseudo random number + + NOTE: + This is codes so that it can be called by two threads at the same time + with minimum impact. + (As the number is supposed to be random, it doesn't matter much if + rand->seed1 or rand->seed2 are updated with slightly wrong numbers or + if two threads gets the same number. */ double my_rnd(struct my_rnd_struct *rand_st) { - rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) % rand_st->max_value; - rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) % rand_st->max_value; - return (((double) rand_st->seed1)/rand_st->max_value_dbl); + unsigned long seed1; + seed1= (rand_st->seed1*3+rand_st->seed2) % rand_st->max_value; + rand_st->seed2=(seed1+rand_st->seed2+33) % rand_st->max_value; + rand_st->seed1= seed1; + return (((double) seed1)/rand_st->max_value_dbl); } |