Posted on 12 Comments

Disabling NPTL for MySQL on RHEL4 systems

Ok, so this doesn’t work on all Linux systems. This because many don’t ship with LinuxThreads libraries any more. While that’s nice in theory, reality is that NPTL threading does not always work well, in particular MySQL server on 64-bit machines can experience trouble. Other apps don’t see the problems because they don’t use that many threads.

If a threading hacker with spare time were to care about looking over the NPTL code to make it work well with hundreds (up to a few thousand) threads, that would be grand.

In the meantime, you may find the below patch useful: it modifies mysqld_safe so you don’t need to keep tweaking it when you upgrade your MySQL version. See the inline comments for further details.

--- mysql-5.1/scripts/mysqld_safe.sh 2007-01-29 10:26:34.000000000 +1000
+++ mysqld_safe.sh 2007-01-30 10:39:12.000000000 +1000
@@ -33,6 +33,7 @@
--ledir=DIRECTORY Look for mysqld in the specified directory
--open-files-limit=LIMIT Limit the number of open files
--core-file-size=LIMIT Limit core files to the specified size
+ --ld-assume-kernel=VERSION Make Linux ld use libraries for specified kernel
--timezone=TZ Set the system timezone
--mysqld=FILE Use the specified file as mysqld
--mysqld-version=VERSION Use "mysqld-VERSION" as mysqld
@@ -82,6 +83,7 @@
# mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])!
--ledir=*) ledir=`echo "$arg" | sed -e "s;--ledir=;;"` ;;
--open-files-limit=*) open_files=`echo "$arg" | sed -e "s;--open-files-limit=;;"` ;;
+ --ld-assume-kernel=*) ld_assume_kernel=`echo "$arg" | sed -e "s;--ld-assume-kernel=;;"` ;;
--core-file-size=*) core_file_size=`echo "$arg" | sed -e "s;--core-file-size=;;"` ;;
--timezone=*) TZ=`echo "$arg" | sed -e "s;--timezone=;;"` ; export TZ; ;;
--mysqld=*) MYSQLD=`echo "$arg" | sed -e "s;--mysqld=;;"` ;;
@@ -356,6 +358,20 @@
ulimit -c $core_file_size
fi

+# (by arjen 2007-01-30)
+# Allow user to specify LD_ASSUME_KERNEL param in my.cnf, saves patching this file across upgrades.
+# Should work on Red Hat and Fedora Linux. Appears to not work on Ubuntu (error reported).
+# Note: this only works with dynamically linked mysqld anyway, since it's a dynamic linker option.
+# See http://people.redhat.com/drepper/assumekernel.html for more details
+#
+# To disable NPTL and use LinuxThreads, put ld-assume-kernel=2.4.1 in [mysqld_safe] block of my.cnf
+# You can tell which threading library is used by doing "ps xa | grep mysqld".
+# This show many visible "processes" when using LinuxThreads, or only one when using NPTL.
+if test -n "$ld_assume_kernel"
+then
+ export LD_ASSUME_KERNEL=$ld_assume_kernel
+fi
+
#
# If there exists an old pid file, check if the daemon is already running
# Note: The switches to 'ps' may depend on your operating system

Posted on 12 Comments

12 thoughts on “Disabling NPTL for MySQL on RHEL4 systems

  1. Woah! This is the first time I’ve ever heard that NPTL slowing down threading. Do you have any other apps in which this same thing happens?

  2. Howdy. I didn’t say slow down. I said cause trouble. That’s exactly what it is.
    MySQL server is single-process (no forking at all), all multi-threaded. It uses one thread per connection, and then some extra for various background tasks.
    Most other daemons/apps don’t need threading to the extent where they require hundreds or even a few thousand threads.
    I suppose Apache 2 could get there, but most people use the prefork configuration.

  3. lotsa text, needs a tag

  4. Can you point me to the bugzilla report which you’ve filed with Redhat about this ?

  5. Well, the idea that NPTL does not work with MySQL 4.0 is very well documented. Apparently they are considering a backport to deal with this.

    Whether that is the issue, is uncertain since there are no versions talked about here. If there are issues with later versions and NPTL I would be very interested in details!

  6. Have you considered separating threads from connections in MySQL? Right now they are one and the same (class THD), plus some thread local variables are used. The thread local variables are easy to spot. I assume you want to support thousands of connections, but you don’t really want thousands of threads. This could be called MTTS (multi threaded threaded server) because MTS is taken and MySQL is already threaded.

  7. MySQL 4.0 is a different issue.

  8. Yes, I understand that that has been discussed. However, it’s a major architectural decision in the sense that such a change would be fairly fundamental to how MySQL works, and would require serious testing. It’s similar to this nice LL(k) parser we have “on the shelf”, putting it in place would be a very serious release on its own.
    So, I’m all for it, but fixing the threading libraries would nevertheless be good.

  9. Such hacks like disabling NPTL stops working as soon as you start using RECENT linux distribution which uses glibc 2.4 or 2.5 where there linuxthreads is no longer supported.

    Anyway hacks suck badly.

  10. Not disagreeing. Just being pragmatic about dealing with an existing situation.
    Are you offering to help fix the problem?

  11. I’d be happy to follow it up for you, but using the lazyweb in the vague hope arjen or ingo or someone decides to do your homework for you is perhaps not an effective way of getting things fixed.

    If someone was reporting some similar class of bug in MySQL, would you not ask for a testcase and a bug report at least?

  12. That was not the intent of the post.
    Other people (developers) are dealing with the internals of it, that wasn’t the focus of what I wrote.

Comments are closed.