Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/events/event_poller.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -282,9 +282,15 @@ func (ep *eventPoller) shoulderTap() {
func (ep *eventPoller) waitForShoulderTapOrPollTimeout(lastEventCount int) bool {
l := log.L(ep.ctx)
longTimeoutDuration := ep.conf.eventPollTimeout

if lastEventCount >= ep.conf.eventBatchSize {
l.Tracef("Polling immediately due to full previous event batch")
return true
}

// For throughput optimized environments, we can set an eventBatchingTimeout to allow messages to arrive
// between polling cycles (at the cost of some dispatch latency)
if ep.conf.eventBatchTimeout > 0 && lastEventCount > 0 && lastEventCount < ep.conf.eventBatchSize {
if ep.conf.eventBatchTimeout > 0 && lastEventCount > 0 {
shortTimeout := time.NewTimer(ep.conf.eventBatchTimeout)
select {
case <-shortTimeout.C:
Expand Down
11 changes: 10 additions & 1 deletion internal/events/event_poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,21 @@ func TestWaitForShoulderTapOrExitCloseBatch(t *testing.T) {
assert.False(t, ep.waitForShoulderTapOrPollTimeout(1))
}

func TestWaitForShoulderTapOrExitClosePoll(t *testing.T) {
func TestWaitForShoulderTapImmediateRepollOnFullBatch(t *testing.T) {
mdi := &databasemocks.Plugin{}
ep, cancel := newTestEventPoller(t, mdi, nil, nil)
cancel()
ep.conf.eventBatchTimeout = 1 * time.Minute
ep.conf.eventBatchSize = 1
assert.True(t, ep.waitForShoulderTapOrPollTimeout(1))
}

func TestWaitForShoulderTapOrExitClosePoll(t *testing.T) {
mdi := &databasemocks.Plugin{}
ep, cancel := newTestEventPoller(t, mdi, nil, nil)
cancel()
ep.conf.eventBatchTimeout = 1 * time.Minute
ep.conf.eventBatchSize = 2
assert.False(t, ep.waitForShoulderTapOrPollTimeout(1))
}

Expand Down