mercredi 14 novembre 2018

Advise on pattern: Broadcasting numpy arrays to different processes. Queues, ZMQ?

I am building a desktop application for acquiring from a fast camera (around kHz frame rates). In order to extend the length of the movies, I was placing the frames into a queue which was consumed by a separated process that was writing to disk.

Now I need to add a bit more of flexibility (I am not the user of the program) so others can develop on top of what I am doing. The general pattern is that the data generated by the camera could be used by different processes (not only to save to disk). I wouldn't want that each new person has to alter the base code, for instance by creating a new queue for their process.

Therefore my question: is there a way of broadcasting numpy arrays from one process to a variable number of other processes? Something like how signals and slots work in Qt, but that is multiprocess-safe in Python.

I came across ZMQ, which seems ideal, but couldn't find examples of people working on edge cases. For instance, what happens if the server is broadcasting but the clients are busy, are those frames going to be dropped? How efficient is to serialize a 2D numpy array (around 1000x50 uint16) and reconstruct at the other side of the socket compared to queues?

The pattern I though about is:

  • 1 process acquires data and broadcasts each frame
  • N independent processes define two child processes each:
    • 1 process to receive the broadcast, recreate the array and place it into a queue object
    • 1 process to consume the queue

In this way, even if the child processes are falling behind, no frames would be lost.

I am looking for advice on the pattern, but also on libraries to use. ZMQ popped up several times in my searches, but there might be other options. The main deployment environment are Windows PCs.

Aucun commentaire:

Enregistrer un commentaire