views:

1518

answers:

6

Does there exist any asynchronous connectors to Mysql that can be used in C or C++? I'm looking for something that can be plugged into a reactor pattern written in Boost.Asio.

[Edit:] Running a synchronous connector in threads is not an option.

A: 

I think the only solution will be to create an asynchronous service that wraps a standard connector. You'll need to understand the ODBC APIs though.

Skizz

Skizz
A: 

I had a similar problem with a very different technologies: Twisted python (reactor-based IO) and sqlAlchemy (??). While searching for a solution, I found about an sAsync project that simply created a separate thread for sqlAlchemy and then responded to requests.

Given that ASIO is based on low level OS features (such as aio_read() or ReadFileEx() etc) and an OS-level reactor (or proactor, in Windows' case) I don't think you have another chance than emulating the 'asynchronousness' by similar means.

Running a synchronous connector in threads is not an option

Think about it: the libmysqlclient / mysqlclient.dll you're using makes synchronous socket calls. The OS scheduler will correctly switch to another thread until the I/O is finished, so what's the difference? (apart from the fact that you shouldn't make 2k threads for this..)

Edit: mysql_real_connect() supports an UNIX socket parameter. You can supposedly read yourself from the mysql server port and write to that UNIX socket only using ASIO. Like a proxyfication.

Vlagged
A: 

There is a project called DBSlayer that puts another layer in front of MySQL that you talk to through JSON. http://code.nytimes.com/projects/dbslayer

dj2
+1  A: 

[ Running a synchronous connector in threads is not an option Think about it: the libmysqlclient / mysqlclient.dll you're using makes synchronous socket calls. The OS scheduler will correctly switch to another thread until the I/O is finished]

This is bugging me! - the 'another thread' could as easily be a second sync. connection to mysql, and should be handled by mysql just as it would another client altogether? My gutfeel is that it should work using multiple threads.

slashmais
It will work in threads. But lets say that you want to have 100 connections vs one or more servers. Not that I imagine that anyone would do that, but accept it for the sake of the argument. Should I then spin up 100 thread (or even only 10 in a thread pool..)? Thats a fairly large overhead.
Thomas Watnedal
+2  A: 

http://jan.kneschke.de/2008/9/9/async-mysql-queries-with-c-api http://forums.mysql.com/read.php?45,183339,183339 enjoy

The blocking connect is a serious issue in this implementation, but nonetheless is seem to do what I originally requested. The drizzle project (https://launchpad.net/drizzle) is working on an async client that will be backwards compatible with Mysql (mentioned here: http://www.oddments.org/?p=20)
Thomas Watnedal
A: 

MySQL Connector/C++ is a C++ implementation of JDBC 4.0

The reference customers who use MySQL Connector/C++ are: - OpenOffice - MySQL Workbench

Learn more: http://forums.mysql.com/read.php?167,221298