Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full node streaming batch size reset to 2000, properly zero out cache on flush #2068

Merged
merged 3 commits into from
Aug 9, 2024
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
4 changes: 2 additions & 2 deletions protocol/app/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ const (

DefaultGrpcStreamingEnabled = false
DefaultGrpcStreamingFlushIntervalMs = 50
DefaultGrpcStreamingMaxBatchSize = 1000000
DefaultGrpcStreamingMaxChannelBufferSize = 1000000
DefaultGrpcStreamingMaxBatchSize = 2000
DefaultGrpcStreamingMaxChannelBufferSize = 2000

DefaultVEOracleEnabled = true
DefaultOptimisticExecutionEnabled = false
Expand Down
12 changes: 6 additions & 6 deletions protocol/app/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func TestValidate(t *testing.T) {
GrpcEnable: true,
GrpcStreamingEnabled: true,
GrpcStreamingFlushIntervalMs: 100,
GrpcStreamingMaxBatchSize: 1000000,
GrpcStreamingMaxChannelBufferSize: 1000000,
GrpcStreamingMaxBatchSize: 2000,
GrpcStreamingMaxChannelBufferSize: 2000,
},
},
"success - optimistic execution": {
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestValidate(t *testing.T) {
GrpcEnable: true,
GrpcStreamingEnabled: true,
GrpcStreamingFlushIntervalMs: 0,
GrpcStreamingMaxBatchSize: 1000000,
GrpcStreamingMaxBatchSize: 2000,
},
expectedErr: fmt.Errorf("grpc streaming flush interval must be positive number"),
},
Expand All @@ -140,7 +140,7 @@ func TestValidate(t *testing.T) {
GrpcEnable: true,
GrpcStreamingEnabled: true,
GrpcStreamingFlushIntervalMs: 100,
GrpcStreamingMaxBatchSize: 1000000,
GrpcStreamingMaxBatchSize: 2000,
GrpcStreamingMaxChannelBufferSize: 0,
},
expectedErr: fmt.Errorf("grpc streaming channel size must be positive number"),
Expand Down Expand Up @@ -183,8 +183,8 @@ func TestGetFlagValuesFromOptions(t *testing.T) {
expectedGrpcEnable: true,
expectedGrpcStreamingEnable: false,
expectedGrpcStreamingFlushMs: 50,
expectedGrpcStreamingBatchSize: 1000000,
expectedGrpcStreamingMaxChannelBufferSize: 1000000,
expectedGrpcStreamingBatchSize: 2000,
expectedGrpcStreamingMaxChannelBufferSize: 2000,
expectedOptimisticExecutionEnabled: false,
},
"Sets values from options": {
Expand Down
30 changes: 16 additions & 14 deletions protocol/streaming/full_node_streaming_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (sm *FullNodeStreamingManagerImpl) SendOrderbookUpdates(
clobPairIds = append(clobPairIds, clobPairId)
}

sm.AddUpdatesToCache(streamUpdates, clobPairIds, uint32(len(updates)))
sm.AddUpdatesToCache(streamUpdates, clobPairIds)
}

// SendOrderbookFillUpdates groups fills by their clob pair ids and
Expand Down Expand Up @@ -393,7 +393,7 @@ func (sm *FullNodeStreamingManagerImpl) SendOrderbookFillUpdates(
clobPairIds = append(clobPairIds, clobPairId)
}

sm.AddUpdatesToCache(streamUpdates, clobPairIds, uint32(len(orderbookFills)))
sm.AddUpdatesToCache(streamUpdates, clobPairIds)
}

// SendTakerOrderStatus sends out a taker order and its status to the full node streaming service.
Expand All @@ -411,30 +411,31 @@ func (sm *FullNodeStreamingManagerImpl) SendTakerOrderStatus(
}

sm.AddUpdatesToCache(
map[uint32][]clobtypes.StreamUpdate{
clobPairId: {
{
UpdateMessage: &clobtypes.StreamUpdate_TakerOrder{
TakerOrder: &streamTakerOrder,
},
[]clobtypes.StreamUpdate{
{
UpdateMessage: &clobtypes.StreamUpdate_TakerOrder{
TakerOrder: &streamTakerOrder,
},
BlockHeight: blockHeight,
ExecMode: uint32(execMode),
},
},
1,
[]uint32{clobPairId},
)
}

// AddUpdatesToCache adds a series of updates to the full node streaming cache.
// Clob pair ids are the clob pair id each update is relevant to.
func (sm *FullNodeStreamingManagerImpl) AddUpdatesToCache(
updates []clobtypes.StreamUpdate,
clobPairIds []uint32,
numUpdatesToAdd uint32,
) {
sm.Lock()
defer sm.Unlock()

metrics.IncrCounter(
metrics.GrpcAddUpdateToBufferCount,
float32(numUpdatesToAdd),
float32(len(updates)),
)

sm.streamUpdateCache = append(sm.streamUpdateCache, updates...)
Expand All @@ -452,7 +453,8 @@ func (sm *FullNodeStreamingManagerImpl) AddUpdatesToCache(
for id := range sm.orderbookSubscriptions {
sm.removeSubscription(id)
}
clear(sm.streamUpdateCache)
sm.streamUpdateCache = nil
sm.streamUpdateSubscriptionCache = nil
}
sm.EmitMetrics()
}
Expand Down Expand Up @@ -501,8 +503,8 @@ func (sm *FullNodeStreamingManagerImpl) FlushStreamUpdatesWithLock() {
}
}

clear(sm.streamUpdateCache)
clear(sm.streamUpdateSubscriptionCache)
sm.streamUpdateCache = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

will this work? vs. setting to empty array

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, tested

sm.streamUpdateSubscriptionCache = nil

for _, id := range idsToRemove {
sm.logger.Error(
Expand Down
Loading