From 498433e351b451dc5af7119464bd54dcf7f07120 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Sun, 5 May 2024 10:20:34 +0700 Subject: [PATCH 1/4] BenchmarkTxn_Get --- mdbx/cursor_test.go | 47 +++++++++++++++++++++++++++++++++++++++++++-- mdbx/txn_test.go | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/mdbx/cursor_test.go b/mdbx/cursor_test.go index 5f59f91..f85733a 100644 --- a/mdbx/cursor_test.go +++ b/mdbx/cursor_test.go @@ -3,6 +3,7 @@ package mdbx import ( "bytes" + "encoding/binary" "encoding/hex" "fmt" "os" @@ -1263,8 +1264,9 @@ func TestCursor_Del_DupSort(t *testing.T) { if err != nil { panic(err) } - fmt.Printf("kk: %s\n", kk) - fmt.Printf("vv: %s\n", vv) + _, _ = kk, vv //TODO: add assert + //fmt.Printf("kk: %s\n", kk) + //fmt.Printf("vv: %s\n", vv) return nil }) @@ -1563,3 +1565,44 @@ func BenchmarkCursor_Renew(b *testing.B) { return nil }) } + +func BenchmarkCursor_SetRange(b *testing.B) { + env, _ := setup(b) + + var db DBI + k := make([]byte, 8) + binary.BigEndian.PutUint64(k, uint64(1)) + + if err := env.Update(func(txn *Txn) (err error) { + db, err = txn.OpenRoot(0) + if err != nil { + return err + } + err = txn.Put(db, k, k, 0) + if err != nil { + return err + } + return nil + }); err != nil { + b.Errorf("dbi: %v", err) + return + } + + if err := env.View(func(txn *Txn) (err error) { + c, err := txn.OpenCursor(db) + if err != nil { + return err + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, _, err := c.Get(k, nil, SetRange) + if err != nil { + return err + } + } + return nil + }); err != nil { + b.Errorf("put: %v", err) + } +} diff --git a/mdbx/txn_test.go b/mdbx/txn_test.go index 515ac3a..60f0dce 100644 --- a/mdbx/txn_test.go +++ b/mdbx/txn_test.go @@ -1263,6 +1263,42 @@ func openDBI(env *Env, key string, flags uint) (DBI, error) { return db, nil } +func BenchmarkTxn_Get(b *testing.B) { + env, _ := setup(b) + + var db DBI + k := make([]byte, 8) + binary.BigEndian.PutUint64(k, uint64(1)) + + if err := env.Update(func(txn *Txn) (err error) { + db, err = txn.OpenRoot(0) + if err != nil { + return err + } + err = txn.Put(db, k, k, 0) + if err != nil { + return err + } + return nil + }); err != nil { + b.Errorf("dbi: %v", err) + return + } + + if err := env.View(func(txn *Txn) (err error) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, err := txn.Get(db, k) + if err != nil { + return err + } + } + return nil + }); err != nil { + b.Errorf("put: %v", err) + } +} + func TestTxnEnvWarmup(t *testing.T) { env, _ := setup(t) From 035d047ab725c4413b908b6c00187ac98fff1619 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Sun, 5 May 2024 10:29:36 +0700 Subject: [PATCH 2/4] symbolizer for --- dbg/keep.go | 1 + dbg/pprof_cgo.go | 8 ++++++++ go.mod | 5 +++++ mdbx/env.go | 2 ++ 4 files changed, 16 insertions(+) create mode 100644 dbg/keep.go create mode 100644 dbg/pprof_cgo.go diff --git a/dbg/keep.go b/dbg/keep.go new file mode 100644 index 0000000..4744c85 --- /dev/null +++ b/dbg/keep.go @@ -0,0 +1 @@ +package dbg diff --git a/dbg/pprof_cgo.go b/dbg/pprof_cgo.go new file mode 100644 index 0000000..28ddf5e --- /dev/null +++ b/dbg/pprof_cgo.go @@ -0,0 +1,8 @@ +//go:build debug +// +build debug + +package dbg + +import ( + _ "github.com/benesch/cgosymbolizer" +) diff --git a/go.mod b/go.mod index c57a9ef..3b68f44 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,8 @@ module github.com/erigontech/mdbx-go go 1.15 + +require ( + github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b + github.com/ianlancetaylor/cgosymbolizer v0.0.0-20240503222823-736c933a666d // indirect +) diff --git a/mdbx/env.go b/mdbx/env.go index 42860c1..00296d9 100644 --- a/mdbx/env.go +++ b/mdbx/env.go @@ -13,6 +13,8 @@ import ( "sync" "time" "unsafe" + + _ "github.com/erigontech/mdbx-go/dbg" ) // success is a value returned from the MDBX API to indicate a successful call. From 0e0d559f4b37f327cd5072a7ef4c3c1e3f4454bf Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 8 May 2024 11:35:19 +0700 Subject: [PATCH 3/4] save --- go.sum | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 go.sum diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..76fb53b --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b h1:5JgaFtHFRnOPReItxvhMDXbvuBkjSWE+9glJyF466yw= +github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b/go.mod h1:eMD2XUcPsHYbakFEocKrWZp47G0MRJYoC60qFblGjpA= +github.com/ianlancetaylor/cgosymbolizer v0.0.0-20240503222823-736c933a666d h1:Azx2B59D4+zpVVtuYb8Oe3uOLi/ift4xfwKdhBX0Cy0= +github.com/ianlancetaylor/cgosymbolizer v0.0.0-20240503222823-736c933a666d/go.mod h1:DvXTE/K/RtHehxU8/GtDs4vFtfw64jJ3PaCnFri8CRg= From 02cb1c2c8c6464c754a7cbcc81ae0e7e555d02d4 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 8 May 2024 11:35:51 +0700 Subject: [PATCH 4/4] save --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 905eda4..d23e47a 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,6 @@ _cgo_export.* _testmain.go *.exe +*.out go.work*