-------------------------------------------------------------
revno: 2877
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: 35164-6.0
timestamp: Wed 2008-10-15 19:53:18 -0300
message:
Bug#35164: Large number of invalid pthread_attr_setschedparam calls
Bug#37536: Thread scheduling causes performance degradation at low thread count
Bug#12702: Long queries take 100% of CPU and freeze other applications under Windows
The problem is that although having threads with different priorities
yields marginal improvements [1] in some platforms [2], relying on some
statically defined priorities (QUERY_PRIOR and WAIT_PRIOR) to play well
(or to work at all) with different scheduling practices and disciplines
is, at best, a shot in the dark as the meaning of priority values may
change depending on the scheduling policy set for the process.
Another problem is that increasing priorities can hurt other concurrent
(running on the same hardware) applications (such as AMP) by causing
starvation problems as MySQL threads will successively preempt lower
priority processes. This can be evidenced by Bug#12702.
The solution is to not change the threads priorities and rely on the
system scheduler to perform its job. This also enables a system admin
to increase or decrease the scheduling priority of the MySQL process,
if intended.
Furthermore, the internal wrappers and code for changing the priority
of threads is being removed as they are now unused and ancient.
1. Due to unintentional side effects. On Solaris this could artificially
help benchmarks as calling the priority changing syscall millions of
times is more beneficial than the actual setting of the priority.
2. Where it actually works. It has never worked on Linux as the default
scheduling policy SCHED_OTHER only accepts the static priority 0.
configure.in:
Remove checks for functions that are not used anymore.
include/config-netware.h:
Remove unused define.
include/my_pthread.h:
Remove thread priority changing wrappers.
mysys/my_pthread.c:
Remove thread priority changing wrappers. They do not work properly
and their implementations were incorrectly protected by a check for
HAVE_PTHREAD_SETSCHEDPARAM.
mysys/thr_alarm.c:
Remove meaningless (100) increase of a thread priority.
sql/mysql_priv.h:
Remove meaningless thread priority values.
sql/mysqld.cc:
Don't change thread priorities.
sql/slave.cc:
Don't change thread priorities.
sql/slave.h:
Update function prototype.
sql/sql_parse.cc:
Don't change thread priorities.
sql/sql_prepare.cc:
Don't change thread priorities.
sql/unireg.h:
Mark flag as obsolete.
storage/innobase/handler/ha_innodb.cc:
Remove use of obsolete flag and associated behavior.
storage/innobase/include/srv0srv.h:
Remove use of obsolete flag and associated variables.
storage/innobase/os/os0thread.c:
Remove use of obsolete flag and associated behavior.
storage/innobase/srv/srv0srv.c:
Remove use of obsolete flag and associated variables.
A build "--without-server" fails if using "--with-ssl" (YaSSL)
The problem was the lack of directory "extra" in a build
which did not include the server.
configure.in:
1) Ensure "extra" is in the list of client directories.
2) Always handle the client directories first, as they will
be contained in every build (we have client-only, but not
server-only).
"have_profiling"
1) Renamed have_community_features server system variable to
have_profiling.
2) Removed eable-community-features configure option and
ENABLE_COMMUNITY_FEATURES macro.
3) Removed COMMUNITY_SERVER macro and replaced its usage by
ENABLED_PROFILING.
Only --enable-profiling is now needed to enable profiling.
It was the only existing "community feature", so there was
no need for both configure options.
Using --enable-community-features will give a warning message
since it no longer exists.
Backport from 6.0 to 5.1.
Only those sync points are included, which are used in debug_sync.test.
The Debug Sync Facility allows to place synchronization points
in the code:
open_tables(...)
DEBUG_SYNC(thd, "after_open_tables");
lock_tables(...)
When activated, a sync point can
- Send a signal and/or
- Wait for a signal
Nomenclature:
- signal: A value of a global variable that persists
until overwritten by a new signal. The global
variable can also be seen as a "signal post"
or "flag mast". Then the signal is what is
attached to the "signal post" or "flag mast".
- send a signal: Assign the value (the signal) to the global
variable ("set a flag") and broadcast a
global condition to wake those waiting for
a signal.
- wait for a signal: Loop over waiting for the global condition until
the global value matches the wait-for signal.
Please find more information in the top comment in debug_sync.cc
or in the worklog entry.
.bzrignore:
WL#4259 - Debug Sync Facility
Added the symbolic link libmysqld/debug_sync.cc.
CMakeLists.txt:
WL#4259 - Debug Sync Facility
Added definition for ENABLED_DEBUG_SYNC.
configure.in:
WL#4259 - Debug Sync Facility
Added definition for ENABLED_DEBUG_SYNC.
include/my_sys.h:
WL#4259 - Debug Sync Facility
Added definition for the DEBUG_SYNC_C macro.
libmysqld/CMakeLists.txt:
WL#4259 - Debug Sync Facility
Added sql/debug_sync.cc.
libmysqld/Makefile.am:
WL#4259 - Debug Sync Facility
Added sql/debug_sync.cc.
mysql-test/include/have_debug_sync.inc:
WL#4259 - Debug Sync Facility
New include file.
mysql-test/mysql-test-run.pl:
WL#4259 - Debug Sync Facility
Added option --debug_sync_timeout.
mysql-test/r/debug_sync.result:
WL#4259 - Debug Sync Facility
New test result.
mysql-test/r/have_debug_sync.require:
WL#4259 - Debug Sync Facility
New require file.
mysql-test/t/debug_sync.test:
WL#4259 - Debug Sync Facility
New test file.
mysys/my_static.c:
WL#4259 - Debug Sync Facility
Added definition for debug_sync_C_callback_ptr.
mysys/thr_lock.c:
WL#4259 - Debug Sync Facility
Added sync point "wait_for_lock".
sql/CMakeLists.txt:
WL#4259 - Debug Sync Facility
Added debug_sync.cc and debug_sync.h.
sql/Makefile.am:
WL#4259 - Debug Sync Facility
Added debug_sync.cc and debug_sync.h.
sql/debug_sync.cc:
WL#4259 - Debug Sync Facility
New source file.
sql/debug_sync.h:
WL#4259 - Debug Sync Facility
New header file.
sql/mysqld.cc:
WL#4259 - Debug Sync Facility
Added opt_debug_sync_timeout.
Added calls to debug_sync_init() and debug_sync_end().
Fixed a purecov comment (unrelated).
sql/set_var.cc:
WL#4259 - Debug Sync Facility
Added server variable "debug_sync".
sql/set_var.h:
WL#4259 - Debug Sync Facility
Added declaration for server variable "debug_sync".
sql/share/errmsg.txt:
WL#4259 - Debug Sync Facility
Added error messages ER_DEBUG_SYNC_TIMEOUT and ER_DEBUG_SYNC_HIT_LIMIT.
sql/sql_base.cc:
WL#4259 - Debug Sync Facility
Added sync points "after_flush_unlock" and "before_lock_tables_takes_lock".
sql/sql_class.cc:
WL#4259 - Debug Sync Facility
Added initialization for debug_sync_control to THD::THD.
Added calls to debug_sync_init_thread() and debug_sync_end_thread().
sql/sql_class.h:
WL#4259 - Debug Sync Facility
Added element debug_sync_control to THD.
storage/myisam/myisamchk.c:
Fixed a typo in an error message string (unrelated).
Solaris binary packages should be compiled with '-g0', not '-g'
The main fix for this is done in the build tools,
but in the sources it affects "configure.in"
which sets "DEBUG_CXXFLAGS" to be used in all debug builds.
Option "--without-server" still not working in 5.1
The general approach is to make sure that source files
which require thread support are only compiled if the build
really needs thread support,
which means when the server is built or a thread-safe client
library.
This required several changes:
- Make sure the subdirectories "storage/" and "plugin/" are
only processed if the server is built, not ifclient-only.
- Make the compilation of some modules which inherently
require threading depend on thread supportin the build.
- Separate the handling of threading in "configure.in" from
that of server issues, threading is also needed in a
non-server build of a thread-safe client library.
Also, "libdbug" must get built even in a client-only build,
so "dbug/" must be in the list of client directories.
In addition, calls to thread functions in source files which
can be built without thread support must use the wrapper
functions which handle the non-threaded build.
So the modules "client/mysqlimport.c" and "client/mysqlslap.c"
must call "my_thread_end()" only via "mysql_thread_end()".
Makefile.am:
The directories "storage/" and "plugin/" contain files
which are needed for the server only, so their contents
is to be built only if a server is built.
They must not be named unconditionally, because building
their contents will fail unless threads are enabled.
These directories are now listed in the "configure"
variable "sql_server_dirs" which becomes part of
"sql_union_dirs" if the server is to be built.
client/mysqlimport.c:
Use the wrapper function "mysql_thread_end()" which
correctly handles the case of a non-threaded build.
client/mysqlslap.c:
Use the wrapper function "mysql_thread_end()" which
correctly handles the case of a non-threaded build.
configure.in:
Various changes to support builds "--without-server":
1) For the unit tests, we need "libdbug".
2) Separate the treatment of the server from that of the
thread-safe client library.
3) Introduce an "automake conditional" "NEED_THREAD"
which can be checked in some "Makefile.am".
4) Include "storage/" and "plugin/" in the list of
"sql_server_dirs" so that they are handled in the
top "Makefile.am" only if the server is to be built
(see the change in that file).
mysys/Makefile.am:
The code of "mf_keycache.c" in 5.1 is no longer safe
to be built without thread support.
(In 5.0, this was possible.)
Rather than fix these issues, which is tedious and risky,
avoid the need to ever build it without thread support:
It is needed in the server only, which needs thread support.
The only case where we build a "libmysys" without thread
support is for a non-threaded client, where "mf_keycache"
is not neded.
So its inclusion in the list of source files can depend
on the new conditional "NEED_THREAD".
unittest/mysys/Makefile.am:
Test program "my_atomic-t" is to verify the correct handling
of threads only, it cannot be built without thread support
and is not needed in such cases either.
Let its build depend on the new conditional "NEED_THREAD".
bzr branch mysql-5.1-performance-version mysql-trunk # Summit
cd mysql-trunk
bzr merge mysql-5.1-innodb_plugin # which is 5.1 + Innodb plugin
bzr rm innobase # remove the builtin
Next step: build, test fixes.
The problem was that a pthread.h header used by gcc did not
declare the pthread_setscheprio, yet the function is implemented
by the function is implemented, causing a autoconf check to pass
and compilation with C++ to fail. The solution is to add a
autoconf check to ensure that the function is properly declared.
configure.in:
Check that the pthread_setschedprio is declared.
Change the default optimization level for Sun Studio to "-O1".
This is a workaround for a Sun Studio bug (see bug #41710
comments for details):
1. Use $GCC instead of $ac_cv_prog_gcc to check for gcc, since
the first one is the only documented way to do it.
2. Use $GXX instead of $ac_cv_prog_cxx_g to check for g++,
since the latter is set to "yes" when the C++ compiler accepts
"-g" which is the case for both g++ and CC.
3. When building with Sun Studio, set the default values for
CFLAGS/CXXFLAGS to "-O1", since unlike GCC, Sun Studio
interprets "-O" as "-xO3" (see the manual pages for cc and CC).
configure.in:
1. Use $GCC instead of $ac_cv_prog_gcc to check for gcc, since
the first one is the only documented way to do it.
2. Use $GXX instead of $ac_cv_prog_cxx_g to check for g++,
since the latter is set to "yes" when the C++ compiler accepts
"-g" which is the case for both g++ and CC.
3. When building with Sun Studio, set the default values for
CFLAGS/CXXFLAGS to "-O1", since unlike GCC, Sun Studio
interprets "-O" as "-xO3" (see the manual pages for cc and CC).