I need data passing between nodejs and erlang process over tcp. Erlang process is kind of api server which receives data from nodejs process and does some processing.
I thought of using json as the structure for data and am using ejson to encode/decode messages. However while benchmarking, i find decode is very slow. around 20k msg/sec.
Is there a better or faster way to send data over tcp to erlang. Is there a way so that i can skip this decoding process in erlang.
for now data is of this type:
{ "event": "someevent", "channel": "some channel", }
erlang will use the event and channel to do some processing based on it.
You can try others json libs for erlang, or try to use serialize using bert
Maybe Protocol Buffers?
Or how about just sending 2 line terminated strings and using plain old tcp sockets. You can use inets setopts to set packet type to line. Then if you put your socket in to active once, the process owning the socket would get sent messages one by one. Or you can use passive mode, where you explicitly call recv, that would still give you the data line by line (careful with lines longer than the buffer).
I would use thrift. Implementing thrift servers in erlang is very simple. From the example it looks like implementing a client in javascript is also trivial.
You should check out msgpack. Its small, fast, and has libraries built for multiple langagues including erlang and javascript.
I have used it across multiple projects and have been pleased with its speed and how easy it was to use.