From 1abc738098b38df6417de470dca8f8bc8d535bfd Mon Sep 17 00:00:00 2001 From: Tuan Pham Anh Date: Fri, 28 Jan 2022 03:15:14 +0700 Subject: [PATCH 1/5] - fix runBenchmarks for rocksdb, cleveldb and badgerdb by creating folder first - run benchmark for all dbs in BenchmarkSmall, BenchmarkMedium and BenchmarkLarge. Note: boltdb is still disabled as its too slow - dont know why --- benchmarks/bench_test.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/benchmarks/bench_test.go b/benchmarks/bench_test.go index 0391c8524..d0380446f 100644 --- a/benchmarks/bench_test.go +++ b/benchmarks/bench_test.go @@ -175,8 +175,11 @@ func BenchmarkMedium(b *testing.B) { benchmarks := []benchmark{ {"memdb", 100000, 100, 16, 40}, {"goleveldb", 100000, 100, 16, 40}, - // FIXME: this crashes on init! Either remove support, or make it work. - // {"cleveldb", 100000, 100, 16, 40}, + {"cleveldb", 100000, 100, 16, 40}, + // FIXME: idk why boltdb is too slow !? + //{"boltdb", 100000, 100, 16, 40}, + {"rocksdb", 100000, 100, 16, 40}, + {"badgerdb", 100000, 100, 16, 40}, } runBenchmarks(b, benchmarks) } @@ -185,8 +188,10 @@ func BenchmarkSmall(b *testing.B) { benchmarks := []benchmark{ {"memdb", 1000, 100, 4, 10}, {"goleveldb", 1000, 100, 4, 10}, - // FIXME: this crashes on init! Either remove support, or make it work. - // {"cleveldb", 100000, 100, 16, 40}, + {"cleveldb", 1000, 100, 4, 10}, + {"boltdb", 1000, 100, 4, 10}, + {"rocksdb", 1000, 100, 4, 10}, + {"badgerdb", 1000, 100, 4, 10}, } runBenchmarks(b, benchmarks) } @@ -195,8 +200,10 @@ func BenchmarkLarge(b *testing.B) { benchmarks := []benchmark{ {"memdb", 1000000, 100, 16, 40}, {"goleveldb", 1000000, 100, 16, 40}, - // FIXME: this crashes on init! Either remove support, or make it work. - // {"cleveldb", 100000, 100, 16, 40}, + // FIXME: idk why boltdb is too slow !? + //{"boltdb", 1000000, 100, 16, 40}, + {"rocksdb", 1000000, 100, 16, 40}, + {"badgerdb", 1000000, 100, 16, 40}, } runBenchmarks(b, benchmarks) } @@ -233,6 +240,10 @@ func runBenchmarks(b *testing.B, benchmarks []benchmark) { // prepare a dir for the db and cleanup afterwards dirName := fmt.Sprintf("./%s-db", prefix) + if (bb.dbType == db.RocksDBBackend) || (bb.dbType == db.CLevelDBBackend) || (bb.dbType == db.BoltDBBackend) { + _ = os.Mkdir(dirName, 0755) + } + defer func() { err := os.RemoveAll(dirName) if err != nil { From 6316b0145c7c215ac9a92690fd1dc1c9736392a7 Mon Sep 17 00:00:00 2001 From: Tuan Pham Anh Date: Fri, 28 Jan 2022 16:11:23 +0700 Subject: [PATCH 2/5] update benchmark setup scripts (INSTALL_ROOT.sh and RUN_BENCHMARKS.sh) and Makefile to test all dbs --- Makefile | 10 +++++----- benchmarks/setup/INSTALL_ROOT.sh | 30 ++++++++++++++++++++++++++---- benchmarks/setup/RUN_BENCHMARKS.sh | 11 ++++++++--- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 18abfa010..a5382e1da 100644 --- a/Makefile +++ b/Makefile @@ -47,8 +47,8 @@ lint: bench: cd benchmarks && \ go test $(LDFLAGS) -bench=RandomBytes . && \ - go test $(LDFLAGS) -bench=Small . && \ - go test $(LDFLAGS) -bench=Medium . && \ + go test $(LDFLAGS) -tags cleveldb,rocksdb,boltdb,badgerdb -bench=Small . && \ + go test $(LDFLAGS) -tags cleveldb,rocksdb,boltdb,badgerdb -bench=Medium . && \ go test $(LDFLAGS) -bench=BenchmarkMemKeySizes . .PHONY: bench @@ -56,9 +56,9 @@ bench: fullbench: cd benchmarks && \ go test $(LDFLAGS) -bench=RandomBytes . && \ - go test $(LDFLAGS) -bench=Small . && \ - go test $(LDFLAGS) -bench=Medium . && \ - go test $(LDFLAGS) -timeout=30m -bench=Large . && \ + go test $(LDFLAGS) -tags cleveldb,rocksdb,boltdb,badgerdb -bench=Small . && \ + go test $(LDFLAGS) -tags cleveldb,rocksdb,boltdb,badgerdb -bench=Medium . && \ + go test $(LDFLAGS) -tags cleveldb,rocksdb,boltdb,badgerdb -timeout=30m -bench=Large . && \ go test $(LDFLAGS) -bench=Mem . && \ go test $(LDFLAGS) -timeout=60m -bench=LevelDB . .PHONY: fullbench diff --git a/benchmarks/setup/INSTALL_ROOT.sh b/benchmarks/setup/INSTALL_ROOT.sh index 119193190..bcd719c01 100755 --- a/benchmarks/setup/INSTALL_ROOT.sh +++ b/benchmarks/setup/INSTALL_ROOT.sh @@ -1,10 +1,32 @@ #!/bin/sh +export DEBIAN_FRONTEND=noninteractive + apt-get update apt-get -y upgrade -apt-get -y install make screen +apt-get -y install screen wget git build-essential libsnappy-dev libgflags-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev + +# Installing leveldb from source +cd ~/ +git clone https://github.com/google/leveldb +cd leveldb +git checkout v1.7 +make -j2 +cp --preserve=links libleveldb.* /usr/local/lib +cp -r include/leveldb /usr/local/include/ +ldconfig + +# installing rocksdb from source +cd ~/ +git clone https://github.com/facebook/rocksdb +cd rocksdb +git checkout v6.15.5 +make -j4 install-shared +ldconfig -GOFILE=go1.12.7.linux-amd64.tar.gz +# install go +cd ~/ +mkdir go +wget https://go.dev/dl/go1.17.6.linux-amd64.tar.gz +tar -C /usr/local -xzf go1.17.6.linux-amd64.tar.gz -wget https://storage.googleapis.com/golang/${GOFILE} -tar -C /usr/local -xzf ${GOFILE} diff --git a/benchmarks/setup/RUN_BENCHMARKS.sh b/benchmarks/setup/RUN_BENCHMARKS.sh index 632d67dd4..3c9dd4c8d 100755 --- a/benchmarks/setup/RUN_BENCHMARKS.sh +++ b/benchmarks/setup/RUN_BENCHMARKS.sh @@ -12,11 +12,16 @@ BRANCH=${1:-master} REPOUSER=${2:-tendermint} export PATH=$PATH:/usr/local/go/bin -export PATH=$PATH:$HOME/go/bin +export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin +export GOROOT=/usr/local/go export GOPATH=$HOME/go -go get -u github.com/${REPOUSER}/iavl -cd ~/go/src/github.com/${REPOUSER}/iavl +export CGO_CFLAGS="-I/usr/local/include" +export CGO_LDFLAGS="-L/usr/local/lib -lleveldb -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd" + +cd ~/ +git clone https://github.com/${REPOUSER}/iavl +cd iavl git checkout ${BRANCH} make bench > results.txt From 6f887eef7dfac9e0264d3d942a44fa8560924f5f Mon Sep 17 00:00:00 2001 From: Tuan Pham Anh Date: Sat, 29 Jan 2022 14:29:19 +0700 Subject: [PATCH 3/5] update doc with command to run the benchmarks quickly using docker --- benchmarks/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/benchmarks/README.md b/benchmarks/README.md index 7e0aaf331..ff574f4b6 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -37,3 +37,21 @@ Copy them back from your local machine: scp user@host:go/src/github.com/cosmos/iavl/results.txt results.txt git add results ``` + +## Running benchmarks with docker + +Run the command below to install leveldb and rocksdb from source then run the benchmarks all the dbs (memdb, goleveldb, rocksdb, badgerdb) except boltdb. + +replace: +- `baabeetaa` with your repo username and +- `fix-bencharks` with your branch. + +``` +docker run --rm -it ubuntu:16.04 /bin/bash -c \ +"apt-get update && apt-get install -y curl && \ +sh <(curl -s https://raw.githubusercontent.com/baabeetaa/iavl/fix-bencharks/benchmarks/setup/INSTALL_ROOT.sh) && \ +sh <(curl -s https://raw.githubusercontent.com/baabeetaa/iavl/fix-bencharks/benchmarks/setup/RUN_BENCHMARKS.sh) fix-bencharks baabeetaa && \ +cat ~/iavl/results.txt" +``` + +The script will install leveldb and rocksdb from source then run the benchmarks. From 3342d1e9c40f3cb2258f65a3192643b18a4b639d Mon Sep 17 00:00:00 2001 From: Tuan Pham Anh Date: Sat, 29 Jan 2022 14:33:17 +0700 Subject: [PATCH 4/5] update doc... --- benchmarks/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/benchmarks/README.md b/benchmarks/README.md index ff574f4b6..cfac7b998 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -53,5 +53,3 @@ sh <(curl -s https://raw.githubusercontent.com/baabeetaa/iavl/fix-bencharks/benc sh <(curl -s https://raw.githubusercontent.com/baabeetaa/iavl/fix-bencharks/benchmarks/setup/RUN_BENCHMARKS.sh) fix-bencharks baabeetaa && \ cat ~/iavl/results.txt" ``` - -The script will install leveldb and rocksdb from source then run the benchmarks. From 481fe0fffcceceb85ab630e6d954460dfd8246d1 Mon Sep 17 00:00:00 2001 From: Tuan Pham Anh Date: Fri, 4 Feb 2022 17:47:23 +0700 Subject: [PATCH 5/5] fix lint --- benchmarks/bench_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmarks/bench_test.go b/benchmarks/bench_test.go index d0380446f..8d361e18a 100644 --- a/benchmarks/bench_test.go +++ b/benchmarks/bench_test.go @@ -177,7 +177,7 @@ func BenchmarkMedium(b *testing.B) { {"goleveldb", 100000, 100, 16, 40}, {"cleveldb", 100000, 100, 16, 40}, // FIXME: idk why boltdb is too slow !? - //{"boltdb", 100000, 100, 16, 40}, + // {"boltdb", 100000, 100, 16, 40}, {"rocksdb", 100000, 100, 16, 40}, {"badgerdb", 100000, 100, 16, 40}, } @@ -201,7 +201,7 @@ func BenchmarkLarge(b *testing.B) { {"memdb", 1000000, 100, 16, 40}, {"goleveldb", 1000000, 100, 16, 40}, // FIXME: idk why boltdb is too slow !? - //{"boltdb", 1000000, 100, 16, 40}, + // {"boltdb", 1000000, 100, 16, 40}, {"rocksdb", 1000000, 100, 16, 40}, {"badgerdb", 1000000, 100, 16, 40}, }