Open AaronLin98 opened 2 weeks ago
version: gorocksdb@v1.6.36
function: write_batch.go
func (wb *WriteBatch) Put(key, value []byte) { cKey := byteToChar(key) cValue := byteToChar(value) C.rocksdb_writebatch_put(wb.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value))) }
use case:
func writeLargeObjects(db *grocksdb.DB) { for i := 0; i < 1000; i += 10 { writeLargeObjectsCore(db, i, i+10) } } func writeLargeObjectsCore(db *grocksdb.DB, l, r int) { largeValue := make([]byte, 1*1024*1024) // 1MB bytes for i := range largeValue { largeValue[i] = 'x' } batch := grocksdb.NewWriteBatch() for i := l; i < r; i++ { key := fmt.Sprintf("large_key_%d", i) batch.Put([]byte(key), largeValue) } writeOpts := grocksdb.NewDefaultWriteOptions() err := db.Write(writeOpts, batch) if err != nil { log.Fatalf("Write failed: %v", err) } writeOpts.Destroy() batch.Destroy() }
results: By this use case, memory leak will happen. The VmRSS is much larger than Go sys memory and rocksdb-memtable and rocksdb-block-cache.
@AaronLin98
v1.6.36 is outdated. I highly recommend upgrading both RocksDB & grocksdb to newer version and give it another try.
I have tried the new version, it seems like cgo has some problem for memory leak
version: gorocksdb@v1.6.36
function: write_batch.go
use case:
results: By this use case, memory leak will happen. The VmRSS is much larger than Go sys memory and rocksdb-memtable and rocksdb-block-cache.