Asynchronous Mysql connector

2019-03-09 20:16发布

Do any asynchronous connectors exist for Mysql that can be used within a C or C++ application? 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.

7条回答
老娘就宠你
2楼-- · 2019-03-09 20:46

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.

查看更多
聊天终结者
3楼-- · 2019-03-09 20:53

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.

查看更多
Lonely孤独者°
4楼-- · 2019-03-09 21:00

have you considered using libdrizzle? i have used only an old version, from when it was a separate project from drizzle, and i tested the asynchronous query features, but i never did any actual benchmarks worth mentioning.

查看更多
孤傲高冷的网名
5楼-- · 2019-03-09 21:02

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

查看更多
放荡不羁爱自由
6楼-- · 2019-03-09 21:03

[ 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.

查看更多
Anthone
7楼-- · 2019-03-09 21:06

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

查看更多
登录 后发表回答