mariano / node-db-mysql

MySQL database bindings for Node.js
http://nodejsdb.org
150 stars 30 forks source link

mysql_real_query is blocking #59

Open erikdubbelboer opened 12 years ago

erikdubbelboer commented 12 years ago

Hi,

It seems you are using mysql_real_query() which is a blocking call. Nodejs only runs a maximum of 4 threads so running 4 slow queries using your library will block everything else.

You can try this by running 4 SELECT SLEEP(10) queries and then doing some fast query. The fast query will only run after the 4 slow queries are done. Example code here: https://gist.github.com/1957486

(The example code actually causes a Segmentation fault but if you want I can create another ticket for that)

An example on how to do async queries can be found here: http://jan.kneschke.de/2008/9/9/async-mysql-queries-with-c-api/