thanks to http://kx.com/q/c/c.js we have JavaScript (de)serialization to use with WebSockets.
With Node.js you can also open Sockets and talk directly to Q. To make this work you need to tweak things a bit so I released a package called node-q .
Hi,
great work! I once wrote a node c++ module using the c interface, but with all the node changes it doesnt compile anymore.
So I just checked your package. I think its really great, but I think I found some issues:
you assume that a whole message comes in one chunk in the data event “this.socket.on(“data”, function(buffer) {.”
unfortunately this is not always correct. Tcp can split the data and so the data callback might be triggered mutliple times for one k ipc message. You have to buffer the data and check the length.
i think you have a race condition in your message dispatcher: assume you are sending a sync message from node. But while you do so, kdb sends you an upd. in your code the activeRequestResponse is set to true.
you assume that a whole message comes in one chunk in the data event “this.socket.on(“data”, function(buffer) {.”
unfortunately this is not always correct. Tcp can split the data and so the data callback might be triggered mutliple times for one k ipc message. You have to buffer the data and check the length.
you can also receive multiple k-messages in one data chunk or even one and a half…
Hi Markus! If I remember you correctly we talked about using Node.js with Q / Kdb+ in Ireland in 2012? :)
You are right with the chunked packages. I will implement this as soon as possible. I copied your “issue” to https://github.com/cinovo/node-q/issues/1. Hope that’s okay.
Mixing sync and async requests is not a good idea. You are right. I will check if I can use the 2nd byte in the header to sort out the async messages.
But I am still not sure how you will keep track of replies if you send multiple requests. Because as far as I know there is no such thing as a correlation id in the headers? Modyfying http://code.kx.com/wiki/Reference/dotzdotpg is not allowed to solve the task :)
Hi,
great work! I once wrote a node c++ module using the c interface, but with all the node changes it doesnt compile anymore.
So I just checked your package. I think its really great, but I think I found some issues:
you assume that a whole message comes in one chunk in the data event “this.socket.on(“data”, function(buffer) {.”
unfortunately this is not always correct. Tcp can split the data and so the data callback might be triggered mutliple times for one k ipc message. You have to buffer the data and check the length.
i think you have a race condition in your message dispatcher: assume you are sending a sync message from node. But while you do so, kdb sends you an upd. in your code the activeRequestResponse is set to true.
Hi Markus! If I remember you correctly we talked about using Node.js with Q / Kdb+ in Ireland in 2012? :)
You are right with the chunked packages. I will implement this as soon as possible. I copied your “issue” to https://github.com/cinovo/node-q/issues/1. Hope that’s okay.
Mixing sync and async requests is not a good idea. You are right. I will check if I can use the 2nd byte in the header to sort out the async messages.
But I am still not sure how you will keep track of replies if you send multiple requests. Because as far as I know there is no such thing as a correlation id in the headers? Modyfying http://code.kx.com/wiki/Reference/dotzdotpg is not allowed to solve the task :)
Hi,
great work! I once wrote a node c++ module using the c interface, but with all the node changes it doesnt compile anymore.
So I just checked your package. I think its really great, but I think I found some issues:
you assume that a whole message comes in one chunk in the data event “this.socket.on(“data”, function(buffer) {.”
unfortunately this is not always correct. Tcp can split the data and so the data callback might be triggered mutliple times for one k ipc message. You have to buffer the data and check the length.
i think you have a race condition in your message dispatcher: assume you are sending a sync message from node. But while you do so, kdb sends you an upd. in your code the activeRequestResponse is set to true.
> But I am still not sure how you will keep track of replies if you send multiple requests
This is easy: sync requests are answered in the correct order (message type is 2 - response). That means the first message sent is the first one answered.
Another open problem ist that I have to convert the Buffer to ArrayBuffer and vice versa because c.js is implemented for browsers and Buffer is a Node.js specific thing. I already optimized this by using the memcpy NPM but it will still be better to read / write directly to Buffer.
But I am not sure if performance is really such a big problem here for real use cases where Node.js is used as a tier between WAN/Web and LAN/q. Users will mostly subscribe to aggregated feeds and make queries with far less than millions of results.
I already implemented qipc in erlang and that’s the reason why I get started with c.js:) c.js is tested and used by many people. Without a proper test suite it is very hard to know that the protocol is implemented correctly.
Charly send me a Node.js implementation. I will check if I can replace c.js with that code to remove the Buffer <> ArrayBuffer overhead in the future.
> But I am still not sure how you will keep track of replies if you send multiple requests
This is easy: sync requests are answered in the correct order (message type is 2 - response). That means the first message sent is the first one answered.