Recent revisions

The built-in slow query log holds LOCK_log for an awfully long time, and
I thought I could do it better.

This plugin uses a lock-free algorithm to write to the log file: call write(2)
with the complete log entry and let the OS kernel take care of the rest.
While this MAY not work for NFS (at least certain versions), this will work
for the most common case of local disk.

I had to extend the plugin API slightly to get all the same information as
the MySQL slow query log.

The main challenge is log file rotation, as if you just close(2) a file
descriptor that others may be write(2)ing to then bad things may happen
(namely that the file descriptor gets reused for something else.. say an
innodb data file, and writing part of your slow query log as an innodb
page will not end in hugs and puppies).

My solution to log file rotation is to basically count how many people
may be using it and waiting until this drops to zero before closing the
file descriptor. This avoids taking any locks around calling write(),
which is the most time consuming part of writing the log.

I know of one more possible improvement to this: reduce the number of
malloc() calls (we should be able to cache this for each thd).

../client/mysqlslap -u root test -S var/tmp/mysqld.1.sock -q 'select 1;'
--number-of-queries=1000000 --concurrency=64 --create-schema=test
Benchmark
Average number of seconds to run all queries: 18.293 seconds
Minimum number of seconds to run all queries: 18.293 seconds
Maximum number of seconds to run all queries: 18.293 seconds
Number of clients running queries: 64
Average number of queries per client: 15625

../client/mysqlslap -u root test -S var/tmp/mysqld.1.sock -q 'select 1;'
--number-of-queries=1000000 --concurrency=64 --create-schema=test
Benchmark
Average number of seconds to run all queries: 15.812 seconds
Minimum number of seconds to run all queries: 15.812 seconds
Maximum number of seconds to run all queries: 15.812 seconds
Number of clients running queries: 64
Average number of queries per client: 15625

(these numbers have been pretty stable over sevaral runs)

and a third, without any slow query log enabled:

./client/mysqlslap -u root test -S var/tmp/mysqld.1.sock -q 'select 1;'
--number-of-queries=1000000 --concurrency=64 --create-schema=test
Benchmark
Average number of seconds to run all queries: 13.006 seconds
Minimum number of seconds to run all queries: 13.006 seconds
Maximum number of seconds to run all queries: 13.006 seconds
Number of clients running queries: 64
Average number of queries per client: 15625