I may be getting ahead of myself here, but I'm looking into how I implement many simultaneous channel writes efficiently, as I didn't see anything obvious for apply the same value to many channels simultaneously.
I have two core issues:
I'm using a
MessageToByteEncoderto encode my models into
ByteBuffersto go over the network. However, there are scenarios where MQTT brokers are expected to write the same values to many (thousands, some brokers even support millions) simultaneous connections. The obvious solution is to encode the model into a
ByteBuffermanually and use that one buffer to feed all of the channels. However, there doesn't seem to be an obvious way to bypass the
OutboundOuttype I use and send a
ByteBufferdirectly, as there's (intentionally, AFAICT) no way to manually wrap it in a
NIOAny. I'd rather not have to drop my nice models entirely just for this one use case.
My main issue is the need to send such a message to many (again, thousands to millions) channels simultaneously. I've used the
ChatServerexample for my initial implementation (though I used the
DispatchQueuestrictly as a lock), which iterates through all of the known channels, writing to each in turn. Since channels are thread-safe, I could turn this into a
Dispatch.apply, but I was wondering if there was anything built in to achieve better parallelism here, or any approach I might be missing. AFAICT, there are no APIs on
EventLoop` to achieve what I want.
In general, what approaches are most common or effective in dealing with the work done within a channel without blocking it? The
ChatServerexample uses a
DispatchQueuefor both locking and async work, but I don't think that's a scalable solution, especially when there may need to be more threads than CPU cores in that case. Is putting work onto a channel's
EventLoopthe expected method here? It appears to be a simple,
Dispatchlike API for submitting work, so it seems like it would be effective. But is it recommended?
Thanks for any insight.