1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-21 06:21:35 +03:00

MWL#192: Non-blocking client API for libmysqlclient.

All client functions that can block on I/O have alternate _start() and
_cont() versions that do not block but return control back to the
application, which can then issue I/O wait in its own fashion and later
call back into the library to continue the operation.

Works behind the scenes by spawning a co-routine/fiber to run the
blocking operation and suspend it while waiting for I/O. This
co-routine/fiber use is invisible to applications.

For i368/x86_64 on GCC, uses very fast assembler co-routine support. On
Windows uses native Win32 Fibers. Falls back to POSIX ucontext on other
platforms. Assembler routines for more platforms are relatively easy to
add by extending mysys/my_context.c, eg. similar to the Lua lcoco
library.

For testing, mysqltest and mysql_client_test are extended with the
option --non-blocking-api. This causes the programs to use the
non-blocking API for database access. mysql-test-run.pl has a similar
option --non-blocking-api that uses this, as well as additional
testcases.

An example program tests/async_queries.c is included that uses the new
non-blocking API with libevent to show how, in a single-threaded
program, to issue many queries in parallel against a database.


client/async_example.c:
  Fix const warning
  ******
  Fix bug with wrong timeout value for poll().
include/Makefile.am:
  Fix missing include for `make dist`
include/mysql.h:
  Add prototypes for all non-blocking API calls.
include/mysql.h.pp:
  Add prototypes for all non-blocking API calls.
mysys/my_context.c:
  Fix type warning for makecontext() function pointer argument.
sql-common/mysql_async.c:
  Fix crashes in the non-blocking API for functions that can take MYSQL argument
  that is NULL.
tests/Makefile.am:
  Add header file to `make dist`
tests/mysql_client_test.c:
  Replace blocking calls with wrappers around the non-blocking calls, used in
  mysql_client_test to test the new non-blocking API.
tests/nonblock-wrappers.h:
  Replace blocking calls with wrappers around the non-blocking calls, used in
  mysql_client_test to test the new non-blocking API.
This commit is contained in:
unknown
2011-09-20 12:49:25 +02:00
parent 1a344b87e4
commit a5b881594d
41 changed files with 4389 additions and 38 deletions

View File

@@ -185,6 +185,7 @@ my $opt_ps_protocol;
my $opt_sp_protocol;
my $opt_cursor_protocol;
my $opt_view_protocol;
my $opt_non_blocking_api;
our $opt_debug;
our $opt_debug_server;
@@ -964,6 +965,7 @@ sub command_line_setup {
'sp-protocol' => \$opt_sp_protocol,
'view-protocol' => \$opt_view_protocol,
'cursor-protocol' => \$opt_cursor_protocol,
'non-blocking-api' => \$opt_non_blocking_api,
'ssl|with-openssl' => \$opt_ssl,
'skip-ssl' => \$opt_skip_ssl,
'compress' => \$opt_compress,
@@ -5468,6 +5470,11 @@ sub start_mysqltest ($) {
mtr_add_arg($args, "--cursor-protocol");
}
if ( $opt_non_blocking_api )
{
mtr_add_arg($args, "--non-blocking-api");
}
if ( $opt_strace_client )
{
$exe= $opt_strace_client || "strace";
@@ -5915,6 +5922,7 @@ Options to control what engine/variation to run
(implies --ps-protocol)
view-protocol Create a view to execute all non updating queries
sp-protocol Create a stored procedure to execute all queries
non-blocking-api Use the non-blocking client API
compress Use the compressed protocol between client and server
ssl Use ssl protocol between client and server
skip-ssl Dont start server with support for ssl connections

View File

@@ -0,0 +1,5 @@
SET @old_general_log= @@global.general_log;
SET @old_slow_query_log= @@global.slow_query_log;
ok
SET @@global.general_log= @old_general_log;
SET @@global.slow_query_log= @old_slow_query_log;

View File

@@ -0,0 +1,9 @@
CREATE TABLE t1 (a INT PRIMARY KEY);
INSERT INTO t1 VALUES (1);
SELECT * FROM t1;
a
1
SELECT * FROM t1;
a
1
DROP TABLE t1;

View File

@@ -0,0 +1 @@
--log=$MYSQLTEST_VARDIR/log/master.log --log-output=FILE,TABLE

View File

@@ -0,0 +1,23 @@
# This runs the mysql_client_test using the non-blocking API.
# This test should work in embedded server after we fix mysqltest
-- source include/not_embedded.inc
SET @old_general_log= @@global.general_log;
SET @old_slow_query_log= @@global.slow_query_log;
# We run with different binaries for normal and --embedded-server
#
# If this test fails with "command "$MYSQL_CLIENT_TEST" failed",
# you should either run mysql_client_test separartely against a running
# server or run mysql-test-run --debug mysql_client_test and check
# var/log/mysql_client_test.trace
--exec echo "$MYSQL_CLIENT_TEST --non-blocking-api" > $MYSQLTEST_VARDIR/log/mysql_client_test.out.log 2>&1
--exec $MYSQL_CLIENT_TEST --non-blocking-api --getopt-ll-test=25600M >> $MYSQLTEST_VARDIR/log/mysql_client_test.out.log 2>&1
# End of 4.1 tests
echo ok;
SET @@global.general_log= @old_general_log;
SET @@global.slow_query_log= @old_slow_query_log;

View File

@@ -2,6 +2,8 @@
# in order to optimize things we skip this test on all
# other platforms
--source include/windows.inc
# Named pipe does not support the non-blocking API.
--disable_non_blocking_api
# Only run this test if named pipe is avaliable
let $nmp= query_get_value("SHOW VARIABLES LIKE 'named_pipe'", Value, 1);

View File

@@ -0,0 +1,18 @@
# Test mixing the use of blocking and non-blocking API in a single connection.
--enable_non_blocking_api
connect (con_nonblock,localhost,root,,test);
--disable_non_blocking_api
connect (con_normal,localhost,root,,test);
connection con_nonblock;
CREATE TABLE t1 (a INT PRIMARY KEY);
--enable_non_blocking_api
INSERT INTO t1 VALUES (1);
--disable_non_blocking_api
SELECT * FROM t1;
--enable_non_blocking_api
SELECT * FROM t1;
connection con_normal;
DROP TABLE t1;