I understand that the power of Node.js is that it processes all user requests on a single thread working on a queue of request. The idea being there is no context switch of this thread, no system calls.
input thread ---> | request queue| ---> output thread --(processes tasks if not causing system call, else delegates to thread pool).
The thread pool will:-
- execute tasks involving system calls (usually somewhat long running
ones.. e.g. IO tasks)
- put the results as another request task in the queue..
- which will be processed by the single thread working on queue
My question is, inevitable, Node.js code will need to put data in an RDBMS or JMS system. This is most definitely synchronous (even putting in JMS is synchronous.. although producer - consumer are not synchronous). So the thread pool processing these IO tasks will not only make system calls, but also be blocked during this period. JDBC in any case does not support synch calls (I guess due to need to be transactional, and maybe security issues, since txn and security context are attached to threads).
So how do we actually put data in RDBMS efficiently from a Node.js server?
Asked
Active
Viewed 158 times
0

Apurva Singh
- 4,534
- 4
- 33
- 42
-
Yes it is possible, look at [Node.js and MySQL](http://stackoverflow.com/questions/5818312/mysql-with-node-js) for example – Wand Maker Jan 11 '16 at 20:18
-
Let me expand a bit.. I would assume that connecting to Oracle, DB2, JMS servers like MQ, making web services calls.. all these IO stuff.. should be async to effectively use Node.. not just MySQL – Apurva Singh Jan 11 '16 at 20:27
-
Yes, most methods take a callback function as parameter which is invoked when result is available – Wand Maker Jan 11 '16 at 21:26