TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
|
A buffered producer that obtains data via ZeroMQ. More...
#include <zmqbufferedproducer.h>
Public Member Functions | |
ZeroMQBufferedProducer (uint8_t nthreads, size_t maxQueueSize, std::string endpoint=std::string()) | |
~ZeroMQBufferedProducer () | |
std::optional< T > | get () |
std::string | endpoint () const |
void | stop () |
Protected Member Functions | |
void | handleRequest (void const *buf, size_t len, ReqRepServer::ReplyFn reply) |
A buffered producer that obtains data via ZeroMQ.
The intended use-case is for this class to be used together with ZeroMQBufferedConsumer to implement distributed producer-consumer setups. Suppose you have an existing setup that looks like this, with sections of your code producing items of type T and other sections consuming them:
[Producer] -> [Consumer]
Then, assuming that items can be serialized with cereal, the ZeroMQBufferedConsumer/Producer classes enable the following design:
[Producer] -> [ZeroMQBufferedConsumer] | TCP | [ZeroMQBufferedProducer] -> [Consumer]
As in common::BufferedProducer you specify a number of threads in the constructor which will be used to deserialize data. Calling get() returns data. Destructing the object will stop all threads.
Make sure that you're calling get() fast enough; if you expect delays for consumption set maxQueueSize accordingly. If the queue runs full the server will not accept new data from the network.
cpid::ZeroMQBufferedProducer< T >::ZeroMQBufferedProducer | ( | uint8_t | nthreads, |
size_t | maxQueueSize, | ||
std::string | endpoint = std::string() |
||
) |
cpid::ZeroMQBufferedProducer< T >::~ZeroMQBufferedProducer | ( | ) |
|
inline |
std::optional< T > cpid::ZeroMQBufferedProducer< T >::get | ( | ) |
|
protected |
void cpid::ZeroMQBufferedProducer< T >::stop | ( | ) |