Skip to content

Commit 582bbe3

Browse files
NONEVM-3305: logpoller BatchInsertSize default config (#468)
* fix: log BatchInsertSize default config * fix: test * chore: typo Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent da6cf0f commit 582bbe3

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

pkg/logpoller/config.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,13 @@ var DefaultConfigSet = Config{
2929
LogPollerStartingLookback: config.MustNewDuration(24 * time.Hour), // Look back 24 hours on startup
3030
BlockTime: config.MustNewDuration(2500 * time.Millisecond), // TON block time is approximately 2.5 seconds
3131

32-
// fixed-sized fields in models.Log: ~342 bytes + Data field(BOC cell)
33-
// ccip message conservative e.g. 1500 bytes -> ~1842 bytes per log
34-
// SaveThreshold: 8000, // ~14.7MB
35-
36-
// fixed-sized fields in postgres models.Log: ~474 bytes + Data field(BOC cell)
37-
// ccip message conservative e.g. 1500 bytes -> ~1974 bytes per log
38-
// BatchInsertSize: 4000, // ~7.9MB
39-
40-
// database configuration,
41-
BatchInsertSize: 4000, // PostgreSQL batch insert size
32+
// memory estimation per log:
33+
// - in-memory models.Log: ~342 bytes + Data field (BOC cell) ≈ 1842 bytes
34+
// - postgres models.Log: ~474 bytes + Data field (BOC cell) ≈ 1974 bytes
35+
// SaveThreshold 7000 ≈ 12.9MB, BatchInsertSize 3500 ≈ 6.9MB
36+
BatchInsertSize: 3500, // postgresql batch insert size
4237
MinBatchSize: 500, // Minimum batch size for timeout retry
43-
SaveThreshold: 8000, // Memory buffer size before batch saving
38+
SaveThreshold: 7000, // Memory buffer size before batch saving
4439
}
4540

4641
func (c *Config) ApplyDefaults() {
@@ -74,6 +69,10 @@ func (c *Config) ValidateConfig() (err error) {
7469
if c.BatchInsertSize == 0 {
7570
return errors.New("batch_insert_size must be greater than 0")
7671
}
72+
// postgresql wire protocol limit: 65,535 params / 17 params per row ≈ 3,855 max rows
73+
if c.BatchInsertSize > 3800 {
74+
return fmt.Errorf("batch_insert_size (%d) exceeds postgresql parameter limit (max 3800 rows)", c.BatchInsertSize)
75+
}
7776
if c.MinBatchSize == 0 {
7877
return errors.New("min_batch_size must be greater than 0")
7978
}

pkg/logpoller/config_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func TestConfig_ValidateConfig(t *testing.T) {
7575
t.Run("valid config passes validation", func(t *testing.T) {
7676
cfg := &Config{
7777
PageSize: 100,
78-
BatchInsertSize: 4000,
78+
BatchInsertSize: 3500,
7979
MinBatchSize: 500,
80-
SaveThreshold: 8000,
80+
SaveThreshold: 7000,
8181
}
8282
err := cfg.ValidateConfig()
8383
require.NoError(t, err)
@@ -92,9 +92,9 @@ func TestConfig_ValidateConfig(t *testing.T) {
9292
t.Run("fails when PageSize is zero", func(t *testing.T) {
9393
cfg := &Config{
9494
PageSize: 0,
95-
BatchInsertSize: 4000,
95+
BatchInsertSize: 3500,
9696
MinBatchSize: 500,
97-
SaveThreshold: 8000,
97+
SaveThreshold: 7000,
9898
}
9999
err := cfg.ValidateConfig()
100100
require.Error(t, err)
@@ -106,19 +106,30 @@ func TestConfig_ValidateConfig(t *testing.T) {
106106
PageSize: 100,
107107
BatchInsertSize: 0,
108108
MinBatchSize: 500,
109-
SaveThreshold: 8000,
109+
SaveThreshold: 7000,
110110
}
111111
err := cfg.ValidateConfig()
112112
require.Error(t, err)
113113
require.Contains(t, err.Error(), "batch_insert_size")
114114
})
115115

116-
t.Run("fails when MinBatchSize is zero", func(t *testing.T) {
116+
t.Run("fails when BatchInsertSize exceeds PostgreSQL parameter limit", func(t *testing.T) {
117117
cfg := &Config{
118118
PageSize: 100,
119119
BatchInsertSize: 4000,
120+
MinBatchSize: 500,
121+
SaveThreshold: 7000,
122+
}
123+
err := cfg.ValidateConfig()
124+
require.Error(t, err)
125+
})
126+
127+
t.Run("fails when MinBatchSize is zero", func(t *testing.T) {
128+
cfg := &Config{
129+
PageSize: 100,
130+
BatchInsertSize: 3500,
120131
MinBatchSize: 0,
121-
SaveThreshold: 8000,
132+
SaveThreshold: 7000,
122133
}
123134
err := cfg.ValidateConfig()
124135
require.Error(t, err)
@@ -128,7 +139,7 @@ func TestConfig_ValidateConfig(t *testing.T) {
128139
t.Run("fails when SaveThreshold is zero", func(t *testing.T) {
129140
cfg := &Config{
130141
PageSize: 100,
131-
BatchInsertSize: 4000,
142+
BatchInsertSize: 3500,
132143
MinBatchSize: 500,
133144
SaveThreshold: 0,
134145
}
@@ -142,7 +153,7 @@ func TestConfig_ValidateConfig(t *testing.T) {
142153
PageSize: 100,
143154
BatchInsertSize: 500,
144155
MinBatchSize: 1000,
145-
SaveThreshold: 8000,
156+
SaveThreshold: 7000,
146157
}
147158
err := cfg.ValidateConfig()
148159
require.Error(t, err)

0 commit comments

Comments
 (0)