R
R
RoflanDaniil2017-10-18 13:21:27
C++ / C#
RoflanDaniil, 2017-10-18 13:21:27

How do I link a node.js application and c (its not a node addons)?

I want to write an application that performs quite complex calculations (processing very large strings) and, as you know, Node.js is not suitable for this at all. Therefore, I will write work with strings in pure C, and middleware, work with the database and more in js. The C program will receive text as input and return the processed text. The program will have one thread of execution because the algorithm is not parallel.
I don't know how to pass data to a C program and get the result in js, and so that the execution of the C program is asynchronous for js. Is it normal from a performance point of view that the C program will be called on every request to the node server? I think that calling a program is not the fastest operation and you need to make the process of its execution long-lived as a node process. (How?)
And plus it should work somehow if the node processes are, for example, 30% and si 70%.
I suppose that there is some kind of software for these purposes, but I'm more interested in how to do it myself.
OC-unix

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
asd111, 2017-10-18
@RoflanDaniil

In your case, the producer/consumer pattern will work well. This is when some applications (producers) create data for processing and add it to the queue, while other applications (consumers) take data from the queue and process it.
You can take RabbitMQ( https://www.rabbitmq.com/tutorials/tutorial-two-py... or another queue.
In general, in your case, the application will work like this:
1. Js sends the strings for processing to the "For Processing" queue ".
2. C applications take rows from the "For Processing" queue.
3. A C application has processed the string and sent it to the "Ready" queue.
4. We take data from the "Ready" queue and do what we need.
If you don't need to access prepared strings from somewhere other than C, then steps 3-4 can be omitted.
With this approach, many C applications can be used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question