diff --git a/core/rawdb/freezer_batch.go b/core/rawdb/freezer_batch.go index 99b63df4dc..e270ee08ec 100644 --- a/core/rawdb/freezer_batch.go +++ b/core/rawdb/freezer_batch.go @@ -201,6 +201,7 @@ func (batch *freezerTableBatch) commit() error { // Update headBytes of table. batch.t.headBytes += dataSize + items := batch.curItem - batch.t.items.Load() batch.t.items.Store(batch.curItem) // Update metrics. @@ -208,7 +209,9 @@ func (batch *freezerTableBatch) commit() error { batch.t.writeMeter.Mark(dataSize + indexSize) // Periodically sync the table, todo (rjl493456442) make it configurable? - if time.Since(batch.t.lastSync) > 30*time.Second { + batch.t.uncommit += items + if batch.t.uncommit > 256 && time.Since(batch.t.lastSync) > 30*time.Second { + batch.t.uncommit = 0 batch.t.lastSync = time.Now() return batch.t.Sync() } diff --git a/core/rawdb/freezer_table.go b/core/rawdb/freezer_table.go index 3900b5d558..431f65ee81 100644 --- a/core/rawdb/freezer_table.go +++ b/core/rawdb/freezer_table.go @@ -113,6 +113,7 @@ type freezerTable struct { tailId uint32 // number of the earliest file metadata *freezerTableMeta // metadata of the table + uncommit uint64 // Count of items written without flushing to file lastSync time.Time // Timestamp when the last sync was performed headBytes int64 // Number of bytes written to the head file