Skip to content

Make Initiator`s inbound channel buffered - #22

Merged
AlexandrosKyriakakis merged 6 commits into
developfrom
initiator-inboound-channel-buffered
Jul 1, 2025
Merged

AlexandrosKyriakakis merged 6 commits into
developfrom
initiator-inboound-channel-buffered

Conversation

@AlexandrosKyriakakis

Copy link
Copy Markdown
Member

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 InitiatorInChanCapacity with an integer representing the capacity of the inbound channel to the session settings config.

@aarjaneiro aarjaneiro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - minor comments

Comment thread initiator.go

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)

@aarjaneiro aarjaneiro Jun 26, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed: ec6f791

Comment thread session.go
}

func (s *session) drainMessageIn() {
s.log.OnEventf("Draining %d messages from inbound channel...", len(s.messageIn))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, did not catch this one

Comment thread initiator.go Outdated
return
}

inChanCapacity := i.getInChanCapacity(sessionID, settings)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed: b25add1 fe34cc4

Comment thread session.go
}

// s.messageIn is buffered so we need to drain it before disconnection
s.drainMessageIn()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work for quickfix to process incoming messages while session is in disconnected state? Maybe it's ok, but not sure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@AlexandrosKyriakakis
AlexandrosKyriakakis merged commit 514304d into develop Jul 1, 2025
@AlexandrosKyriakakis
AlexandrosKyriakakis deleted the initiator-inboound-channel-buffered branch July 1, 2025 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants