zhttpsocket: for server mode, add ability to respond via router socket #48073
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The IPC protocol used between Pushpin components (ZHTTP) is based on ZeroMQ, where response data is sent via a PUB socket. The use of PUB here makes backpressure difficult and likely leads to message loss under high load. It would make more sense to use a socket type with backpressure, such as PUSH or ROUTER. This PR is the first in a series to enable response data via ROUTER. It uses the ROUTER socket that already exists for request data which is bidirectional, so we don't need to introduce a new socket.
Background: PUB was intended to enable one-to-many communication, but we don't use our IPC in that manner and it wouldn't be practical to do so since messages are always addressed to specific components. The decision to use PUB here is mainly an artifact of connmgr originally being modeled after mongrel2 which also uses PUB for response data. I suppose the idea was that you could set up multiple connmgrs and reach all of them with a single ethernet packet via UDP multicast. In theory that sounds interesting but I don't really see us ever doing that.
To start out, this PR enables sending response messages via ROUTER, by adding an optional address argument to the server mode handle's
send
method. If set toSome
, the message is sent via ROUTER to the supplied address, otherwise the message is sent via PUB (where the address is expected to be embedded in the message content). All existingsend
calls are updated to passNone
, so there is no change in behavior. In a future PR we can change the calls to passSome
to send via ROUTER.