Linux Notes
162
If you have more than 16MB of memory, you should add something like the following to your init scripts
(for example,
/etc/init.d/boot.local
on SuSE Linux):
echo 65536 > /proc/sys/fs/file-max
echo 8192 > /proc/sys/fs/dquot-max
echo 1024 > /proc/sys/fs/super-max
You can also run the
echo
commands from the command line as
root
, but these settings are lost the
next time your computer restarts.
Alternatively, you can set these parameters on startup by using the
sysctl
tool, which is used by
many Linux distributions (including SuSE Linux 8.0 and later). Put the following values into a file named
/etc/sysctl.conf
:
# Increase some values for MySQL
fs.file-max = 65536
fs.dquot-max = 8192
fs.super-max = 1024
You should also add the following to
/etc/my.cnf
:
[mysqld_safe]
open-files-limit=8192
This should enable a server limit of 8,192 for the combined number of connections and open files.
The
STACK_SIZE
constant in LinuxThreads controls the spacing of thread stacks in the address
space. It needs to be large enough so that there is plenty of room for each individual thread
stack, but small enough to keep the stack of some threads from running into the global
mysqld
data. Unfortunately, as we have experimentally discovered, the Linux implementation of
mmap()
successfully unmaps a mapped region if you ask it to map out an address currently in use, zeroing
out the data on the entire page instead of returning an error. So, the safety of
mysqld
or any other
threaded application depends on the “gentlemanly” behavior of the code that creates threads. The
user must take measures to make sure that the number of running threads at any given time is
sufficiently low for thread stacks to stay away from the global heap. With
mysqld
, you should enforce
this behavior by setting a reasonable value for the
max_connections
[467]
variable.
If you build MySQL yourself, you can patch LinuxThreads for better stack use. See
Section 2.20.1.3,
“Linux Source Distribution Notes”
. If you do not want to patch LinuxThreads, you should set
max_connections
[467]
to a value no higher than 500. It should be even less if you have a large
key buffer, large heap tables, or some other things that make
mysqld
allocate a lot of memory, or if
you are running a 2.2 kernel with a 2GB patch. If you are using our binary or RPM version, you can
safely set
max_connections
[467]
at 1500, assuming no large key buffer or heap tables with lots
of data. The more you reduce
STACK_SIZE
in LinuxThreads the more threads you can safely create.
Values between 128KB and 256KB are recommended.
If you use a lot of concurrent connections, you may suffer from a “feature” in the 2.2 kernel that
attempts to prevent fork bomb attacks by penalizing a process for forking or cloning a child. This
causes MySQL not to scale well as you increase the number of concurrent clients. On single-CPU
systems, we have seen this manifest as very slow thread creation; it may take a long time to connect
to MySQL (as long as one minute), and it may take just as long to shut it down. On multiple-CPU
systems, we have observed a gradual drop in query speed as the number of clients increases. In
the process of trying to find a solution, we have received a kernel patch from one of our users who
claimed it helped for his site. This patch is available at
http://dev.mysql.com/Downloads/Patches/linux-
fork.patch
. We have done rather extensive testing of this patch on both development and production
systems. It has significantly improved MySQL performance without causing any problems and is
recommended for users who still run high-load servers on 2.2 kernels.
This issue has been fixed in the 2.4 kernel, so if you are not satisfied with the current performance
of your system, rather than patching your 2.2 kernel, it might be easier to upgrade to 2.4. On SMP
systems, upgrading also gives you a nice SMP boost in addition to fixing the fairness bug.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...