I'm busting my head but cannot find a solution for this. Please consider this scenario:
I have writers that want to write to non-blocking "queue" to another machine on the local network and have a reader that will read data (blocking mode if there are no writers) and do some job A and then return after a long hour and take next data.
So the scenario is like that:
- Writer writes
- Writer writes
- Writer writes
- Writer writes
- Writer writes
Reader reads and does job
In the same time while reader is busy:
- Writer writes
- Writer writes
- Writer writes
- Writer writes
- Writer writes
- etc ...
I thought I could do this with a tcp daemon as a reader, but that would mean that it would run simultaneously with fork(s) and I want the reader to process one at a time because it will do a cpu hungry job.
I thought about having a tcp server get the requests and then signal to a FIFO and have another daemon read from the FIFO but it has the same limitations.
I mean the FIFO must read when the writer writes, and I want the writer to write many times faster than the reader.
A db solution would be ok, but a) it is not very fast and b) there is no locking for the reader..I wouldn't want to implement it with sleep(x) it seems not a good programming technique.
Any solutions?