Repository navigation
Make Initiator`s inbound channel buffered - #22
Conversation
|
|
||
| inChanCapacityStr, err := settings.Setting(initiatorInChanCapacityConfig) | ||
| if err != nil { | ||
| i.sessions[sessionID].log.OnEventf("Failed to get setting %s, will default to 0: %v", initiatorInChanCapacityConfig, err) |
There was a problem hiding this comment.
For clarity, I would mention somewhere either in the message or in a // comment that a buffer of size 0 is the same as unbuffered
| } | ||
|
|
||
| func (s *session) drainMessageIn() { | ||
| s.log.OnEventf("Draining %d messages from inbound channel...", len(s.messageIn)) |
There was a problem hiding this comment.
if there are no more producers, we can assume len(s.messageIn) will be unchanged. In that case, the for loop below can be simplified
There was a problem hiding this comment.
Sorry, did not catch this one
| return | ||
| } | ||
|
|
||
| inChanCapacity := i.getInChanCapacity(sessionID, settings) |
There was a problem hiding this comment.
settings here corresponds to FIX session, in other quickfix library buffer/queue capacity was not part of the settings, instead delegated to Initiator or Acceptor initialization, NewInitiator
| } | ||
|
|
||
| // s.messageIn is buffered so we need to drain it before disconnection | ||
| s.drainMessageIn() |
There was a problem hiding this comment.
Does it work for quickfix to process incoming messages while session is in disconnected state? Maybe it's ok, but not sure.
There was a problem hiding this comment.
At that moment it is not disconnected yet, the next session state will be disconnected, so the connection should still be on. The other side should also wait for our disconnect response when the disconnection is finalized
We have observed slow consumption of FIX messages in the Initiator.
Since the outbound channel is buffered, the event loop is sending too many messages at once but reads incoming messages one by one. This creates an inconsistency between incoming consumption messages and outgoing production messages.
In this PR we resolve this issue by making the inbound channel buffered. So the Initiator can now read and write in a truly asynchronous way.
This change is feature flagged. Can be used by setting
InitiatorInChanCapacitywith an integer representing the capacity of the inbound channel to the session settings config.