Hi,
I am implementing a publisher/subscriber RPC interface with a large volume of messages.
The server receives the incoming published messages and dispatches them to the subscribers after filtering without modifying the original message content. The filtering is done on separate worker threads.
My question is whether this can be done with zero copy? The worst case is marshalling the received message struct into a native struct than building a struct parameter for each subscriber. That would be 1 + N copies.
I tried to keep the original MyStruct::Reader around (that is received as a parameter upon publishing) but my understanding and experience is that it only holds a weak reference to the underlying data which is released as soon as the original context goes out of scope. See the code below for clarity.
------------------------------------------------------------------------------------------------------------
kj::Promise<void> server::Server::publish(PublishContext context) {
Event::Reader event = context.getParams().getEvent();
// Is there a way to make Event::Reader-s data outlive this scope?
// Or a convenient way to make a deep copy?
eventRouter_.insertEvent(event);
return kj::READY_NOW;
};
------------------------------------------------------------------------------------------------------------
The other part of the question is if I manage to keep the reader and its data (or I just make a new Event::Builder) can I reuse those to craft multiple subscriber dispatch requests. After all, the +N copies is that I really want to avoid. If i do something like below, would that work and would that result in N copies?
------------------------------------------------------------------------------------------------------------
Event::Builder/Reader event;
for (auto client: subscribers) {
auto req = client.dispatchRequest();
req.setEvent(event);
req.send();
}
------------------------------------------------------------------------------------------------------------
Thank you for your time and help,
-Gym