Home > Software design >  CPP program background waiting for jobs
CPP program background waiting for jobs

Time:05-13

I want to split up the following workflow of a C program:

Read serialized data (1 sec, which is already very fast for that size)
Search data (0.01 ms)
Return found data(0.00.. ms) Edit: found data is just a small file

Obviously reading the data takes most of the time. Additionally, the data that is being read, never changes. To speed up the workflow, I want to read the data once, then wait for requests. Just like a MySQL db, that is waiting for statements. Or any other Process that is running and just waiting for something to do. Right now, I start the program using the shell, and it will only be run inside a linux docker container.

What would be your approach to do that?

Goal: The program is always running and waiting for search metadata from another process (bash script?, a nodejs exec call), then perform search, then return data (write to file)

Dependency: I want to build this without eg nodejs v8 integration

Is Boost Asio a good startingpoint? Do I need to build a socket server? Are there easier ways?

CodePudding user response:

This is very opinion-based.

I'd turn the program into a REST server. I hate boost, though, and recommend Poco::Net instead. If you want to see an example implementation:

[email protected]:jplflyer/ShowLib.git

And look at the RESTServer class.

I use JSON to pass messages around. It's become the industry standard.

CodePudding user response:

I've used Boost.ASIO for network communication and it is a very good library with good documentation and example code.

But Boost is a huge library. One good thing about Boost.ASIO is you can compile it as a standalone library without much of the boost headers. Have a look here on how to compile Boost.ASIO as standalone library.

  • Related