Sannis / node-mysql-libmysqlclient

Asynchronous MySQL binding for Node.js
http://sannis.github.com/node-mysql-libmysqlclient
Other
229 stars 47 forks source link

High-level API for v1.4.x branch #126

Closed Sannis closed 12 years ago

Sannis commented 12 years ago

This issue includes API proposal for the high-level API.

Define: mysql = require('mysql-libmysqlclient').

  1. First of all, I plan to maintain backward-compatibility, so mysql.createConnectionSync() should return MysqlConnection-compatible object. Guarantied by tests.
  2. mysql.binding property should return exactly bindings without any changes. Done in 83f69052bea2619e78017874fe847ce55a766649.
  3. mysql.MysqlConnectionQueued should be inherited from mysql.binding.MysqlConnection and use queue for connect, query and querySend methods. Done in #117.
  4. mysql.MysqlConnectionHighlevel should be a high-level API, includes only async functions from mysql.MysqlConnectionQueued. It should have a switch, what method is used for querying: query or querySend. Started in 28527d612cff08c8e616ddd0ef7d9ace6fe18a33.
  5. ... to be continued. If you have any suggestions for module API, please write them in comments. Thanks!
Sannis commented 12 years ago

@aleafs, @iseeyou1987, @avz - are this changes good for you?

aleafs commented 12 years ago

Hi @Sannis , really sorry for coming late, and thanks for your issue. Only one thing is that I have not figured out how these apis are helpful for slow queries. We use connections pool and querySend to communicate with mysql. When connections are run out, we push a new query into a queque before trigger "review_quequed_query" in nextTick.

Sannis commented 12 years ago

Currently my library use libeio threads for queries to MySQL server. Default thread pool size is 4, as @iseeyou1987 right mentioned. So if you start 8 queries, they block all threads and you can't run any libeio operations, such as other queries or file I/O. With mysql_send_query you solves this problem, but you can't run them in parallel. So need to use connection pool plus custom queue for sequalize queries in each copnnection. I think you are know this, so I've describe this for anyone who need this explanation.

It is quite good, that node community wrote modules for common resource polls and queues, but I think that such queue need to be in node-mysql-libmysqlclient itself, besause in other case some users may be confused with issues like #123. So MysqlConnectionQueued should implement such queues for query and querySend to avoid thread pool cluttering. I think it will be also helpful for you. Also, it should support things like this:

var conn = mysql.createConnection();
conn.connect(...); // async call without callback
conn.query("INSERT ..."); // async query, will be executed after connection