Thursday Jun 11, 2009

Changing process.max-file-descriptor using 'ulimit -n' can cause MySQL to change table_open_cache value

Before I get into details here is the bottom line. If you start MySQL on Solaris as a non-root (ie, mysql) user and for some reason you need to adjust the file descriptor resource limit for the parent shell, never use 'ulimit -n'. This will set both the soft and hard limit and may cause MySQL to adjust the max_connections and table_open_cache configuration variables upon next startup.

Use either:

 ulimit -S -n 1024

or something like:

  prctl -n process.max-file-descriptor -t basic -v  1024 -r -i process $$

The Details

The default 'basic' privilege value for the resource control process.max-file-descriptor is 256. This control represents the soft ulimit for file descriptors per process. The default 'privileged' privilege is set to 65535, which represents the hard ulimit. A non-root user can adjust the soft limit down or up to the hard limit. Unless it has PRIV_SYS_RESOURCE a non-root user can only decrease the hard limit.

Not being aware of the default values I started a sysbench run with 256 threads. It failed with the following message:

FATAL: unable to connect to MySQL server, aborting...
FATAL: error 2001: Can't create UNIX socket (24)
FATAL: failed to connect to database server!
FATAL: thread#252: failed to connect to database server, aborting...

Sysbench fails because the action for the basic privilege process.max-file-descriptors is deny. I was running sysbench logged in as mysql. I made the mistake of increasing the ulimit to what I thought was a reasonable 1024 via 'ulimit -n 1024'. When restarting mysqld it inherited a soft and hard limit of 1024. This had the effect of causing mysqld to recalculate the values for max_connections and table_open_cache as displayed in the error log:

090610  9:44:11 [Warning] Changed limits: max_open_files: 1024  max_connections: 886  table_cache: 64

This value is much too small for table_open_cache and is guaranteed to cause heavy contention on LOCK_open as concurrent threads increase.

Why did MySQL change table_open_cache and max_connections?

Upon startup mysqld will calculate the number of open files it wants selecting the greatest of:

  • myisam's requirement for 2 file handles per connection
    • 10+max_connections+table_cache_size\*2
  • max_connnections\*5
  • open_files_limit

For the purpose of this discussion let's call this max_open_files.

It then compares max_open_files with the soft resource limit for file descriptors per process. If the soft limit is less than max_open_files both the soft and hard limit will be set to max_open_files via setrlimit. If setrlimit fails the requested max_open_files is modified to the old soft limit. If the returned max_open_files is less than myisam's requirement for 2 file handles per connection and open_files_limit has not been specified, max_connections and table_open_cache will be recalculated to fit within the new boundaries.

Now take the case where I inadvertently set both the soft and hard limit via 'ulimit -n 1024'. I had set  open_table_cache=4096 and max_connections=2049, arbitrary large values so I could set them once and forget about them. In this case max_open_files=max_connections\*5=10245. When trying to increase the limits to 10245, the setrlimit call fails because I started mysqld as the mysql user and it does not have the privilege to increase the hard limit from 1024 to 10245. In this case max_open_files is set to 1024, which causes mysqld to recalculate max_connections and table_open_cache:

090610  9:44:11 [Warning] Changed limits: max_open_files: 1024  max_connections: 886  table_cache: 64

How to observe process.max-file-descriptor

You can use either prctl or ulimit to observe the current values of process.max-file-descriptor:

$ prctl -n process.max-file-descriptor  -i process $$
process: 20773: -ksh
NAME    PRIVILEGE       VALUE    FLAG   ACTION                       RECIPIENT
        basic             256       -   deny                             20773
        privileged      65.5K       -   deny                                 -
        system          2.15G     max   deny                                 -
$ ulimit -S -n ### soft limit
$ ulimit -H -n ### hard limit

Wednesday Apr 22, 2009

MySQL DTrace presentation slides

For some reason my presentation slides have not been posted to on MySQL Users Conference site. Here it is, a pdf format of "Introduction to Using DTrace with MySQL".

Tuesday Apr 21, 2009

mysql dtrace provider now enabled in MySQL 5.4

Over the last year there has been alot of work done to instrument MySQL with static dtrace probes. The mysql provider first became available in MySQL 6.0.8 but required a build with the --enable-dtrace flag to enable it. Starting with MySQL 5.4 the mysql provider and it's static probes are now enabled by default and ready to be used on Solaris 10, OpenSolaris and Mac OS X.

The static probes in MySQL 5.4 have been designed to follow the execution path of a query

with the level getting deeper as the query execution proceeds. However the probes are implemented so that you don't have to traverse the entire hierarchy to get the information you want.

They are also implemented in sets. The -start probe exposes pertinent information such as the query text. The -done probe returns the status of the probe operation. With probe sets time spent within an operation can be captured.

Check out MC Brown's MySQL University presentation "Using DTrace with MySQL" for details. MC and I will also be presenting a simlar presentation at the MySQL User's Conference on Tuesday 4/21 at 4:25pm (shameless plug). If you can't make that session there is another session on DTrace and MySQL on Wed 4/22 at 4:25pm.

For examples and ideas check out Jenny Chen's Blueprint on DTrace and MySQL . There is also a detailed section in the MySQL 6.0 documentation on using the MySQL static probes.

Tuesday Nov 04, 2008

Why isn't MySQL using the my.cnf settings I've specified?

You are just getting started with MySQL on OpenSolaris. You've installed the OpenSolaris Community Edition and CoolStack MySQL. To explore this new environment you decide to run some tests using the sysbench benchmark. After running a number of tests you realize that for some reason the options you are setting in /etc/my.cnf are not getting used.

What is going on? Not to worry, you've just hit a problem common to new users of MySQL on OpenSolaris.

Run this command:

 # /opt/coolstack/mysql/bin/mysqladmin | more

page down until you see:

 Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /opt/coolstack/mysql/etc/my.cnf ~/.my.cnf

This shows the order that my.cnf option files are read. Now do a copy and paste and 'ls -l' of these files:

$ ls -l /etc/my.cnf /etc/mysql/my.cnf /opt/coolstack/mysql/etc/my.cnf ~/.my.cnf
/opt/coolstack/mysql/etc/my.cnf: No such file or directory
/opt/coolstack/mysql/.my.cnf: No such file or directory
-rw-r--r--   1 mysql    mysql        676 Oct 23 15:21 /etc/my.cnf
lrwxrwxrwx   1 root     root          10 Nov  3 09:08 /etc/mysql/my.cnf -> 5.0/my.cnf

You expect to see /etc/my.cnf, after all you put it there. But how did /etc/mysql/my.cnf get there? It's there because by default MySQL is installed in /etc/mysql when you install OpenSolaris. Due to the order that my.cnf files are read any parameter specified in /etc/mysql/my.cnf will override the same setting in /etc/my.cnf.

So what to do? Well you could just delete the /etc/mysql/my.cnf symbolic link, but the best practice we've established in the MySQL Performance and Scalability project is to explicitly specify the my.cnf file as part of MySQL startup using the --defaults-file parameter:

# mysqld_safe --defaults-file=/etc/my.cnf &

This guarantees that only the configuration parameters you expect are used by the MySQL instance you started. When using the --defaults-file there is no restriction on the name and location of the configruation file. This allows better sharing of a system environment where multiple instances of MySQL are being run with different configuration parameters.

Thursday Dec 20, 2007

Webcam mandolin lessons

I've been hacking around on guitar since I was a teenager. But in my late '40s I decided to learn flatpicking guitar in the style of Doc Watson, Norman Blake, Tony Rice, etc. This style of guitar is associated with bluegrass and old-time Appalachian fiddle tunes. One thing I noticed while listening to to these tunes in a group setting was that I always seemed to latch on to the mandolin solos. The vocal quality of the instrument seem to mesh really well with my musical brainwaves.  So this past summer I picked up a used mandolin (Collings MT) and started working through some tunes.

Living in Klamath Falls, OR the nearest mandolin teachers are 60 miles "over the hill" in Ashland. Luckily I have some local friends who are good mandolin players that showed me a few things to get me started. I took a few lessons in Ashland but as winter sets in the thought of driving back and forth over the pass is not my idea of a good time. So I started searching the Web for online mandolin lessons. I came across a teacher in SoCal that was doing webcam lessons. That seemed pretty interesting to me so I started searching along those lines and discovered that Mike Compton was also offering webcam lessons. Now Mike is a fantastic player who is considered one of the greatest mandolinists that plays in the style of Bill Monroe.

I jumped at the chance to take lessons from him and sent him an email right away. He had some openings and we agreed to give it a try. My setup consists of a Macbook using iChat/AIM and a Snowball USB microphone. I have a 3Mb Qwest DSL connection. We've had one session so far. For the most part the video chat worked well, though there were times when it broke up pretty badly. I had already started working on "Evening Prayer Blues" and Mike had me play it for him.  After messing around with the iSight camera a bit Mike was able to see me play and totally changed the way I am holding the pick and using my right hand.

Also I told him that I really liked the intro and solo to "New Muleskinner Blues". Well he had notation/tab and a slowed-down quicktime movie to send me and I've been working through it. And with that I think I've figured out how this is going to work and how it is different from DVD lessons and other online music lessons. It's 2-way, Duh! Using the video with sparing use of the sheet music I can learn the tunes and technique "front porch" style. Once a week or so, I get together with Mike and get to go over stuff and learn new stuff. The DVD and online lessons are fine in themselves but there is no feedback. The main drawback of webcam lessons is that we can't play along together due to the delay in communications.

Here is a sample of Mike's videos on YouTube, this ones called "The Mountaineer"


Vince Carbone


« July 2016