Async mySQL (MariaDB)

Proper database handling proved to be quite a lot more complicated than the usual one line SQL query.

I try to be able to service the maximum amount of requests without losing precious milliseconds waiting for database fetches to finish

Therefore I now coded the Mori server to

  • initiate a number of concurrent connections to the same database server. This is needed, because the underlying protocol itself (the communication protocol between a client and a MySQL/MariaDB server) does not allow multiple requests to be ongoing at the same time. The previous request must finish before a new one can be initiated.
  • queue all SQL requests (using the Linux queue macros) and process them as some of the database connections becomes available
  • use the asynchronous client API. This was evidently available as an undocumented feature in MySQL, but it was properly documented in the MariaDB fork, and this prompted me to start using the MariaDB database. The asynchronous interface allows one to start a query and process the result later.
  • use libevent to trigger processing of database request results at the moment they become available