Badger writes slower on v2 than v1

I ran the badger benchmark tool on multiple versions

cd badger && go run main.go benchmark write --dir ./data4

and here’s what I see

==> 1.6.0.log <==
Time elapsed: 24s, bytes written: 1.4 GB, speed: 58 MB/sec, entries written: 8631194, speed: 359633/sec
Time elapsed: 25s, bytes written: 1.4 GB, speed: 57 MB/sec, entries written: 8897684, speed: 355907/sec
Time elapsed: 26s, bytes written: 1.5 GB, speed: 57 MB/sec, entries written: 9332095, speed: 358926/sec
Time elapsed: 27s, bytes written: 1.5 GB, speed: 55 MB/sec, entries written: 9332095, speed: 345633/sec
Time elapsed: 28s, bytes written: 1.5 GB, speed: 53 MB/sec, entries written: 9332095, speed: 333289/sec
Time elapsed: 29s, bytes written: 1.6 GB, speed: 54 MB/sec, entries written: 9869682, speed: 340333/sec
Time elapsed: 30s, bytes written: 1.6 GB, speed: 53 MB/sec, entries written: 10000000, speed: 333333/sec
Time elapsed: 31s, bytes written: 1.6 GB, speed: 52 MB/sec, entries written: 10000000, speed: 322580/sec
Time elapsed: 32s, bytes written: 1.6 GB, speed: 50 MB/sec, entries written: 10000000, speed: 312500/sec
2020/09/28 13:43:59 DB.Close. Error: <nil>. Time taken to close: 6.366059347s

==> 1.6.2.log <==
Time elapsed: 23s, bytes written: 1.4 GB, speed: 61 MB/sec, entries written: 8807820, speed: 382948/sec
Time elapsed: 24s, bytes written: 1.4 GB, speed: 60 MB/sec, entries written: 9017530, speed: 375730/sec
Time elapsed: 25s, bytes written: 1.5 GB, speed: 60 MB/sec, entries written: 9436950, speed: 377478/sec
Time elapsed: 26s, bytes written: 1.5 GB, speed: 58 MB/sec, entries written: 9436950, speed: 362959/sec
Time elapsed: 27s, bytes written: 1.5 GB, speed: 57 MB/sec, entries written: 9569273, speed: 354417/sec
Time elapsed: 28s, bytes written: 1.6 GB, speed: 57 MB/sec, entries written: 10000000, speed: 357142/sec
Time elapsed: 29s, bytes written: 1.6 GB, speed: 55 MB/sec, entries written: 10000000, speed: 344827/sec
Time elapsed: 30s, bytes written: 1.6 GB, speed: 53 MB/sec, entries written: 10000000, speed: 333333/sec
Time elapsed: 31s, bytes written: 1.6 GB, speed: 52 MB/sec, entries written: 10000000, speed: 322580/sec
2020/09/28 13:57:14 DB.Close. Error: <nil>. Time taken to close: 5.444190012s

==> 2.0.0.log <==
Time elapsed: 21s, bytes written: 1.4 GB, speed: 66 MB/sec, entries written: 8702965, speed: 414426/sec
Time elapsed: 22s, bytes written: 1.4 GB, speed: 65 MB/sec, entries written: 8917908, speed: 405359/sec
Time elapsed: 23s, bytes written: 1.5 GB, speed: 65 MB/sec, entries written: 9332095, speed: 405743/sec
Time elapsed: 24s, bytes written: 1.5 GB, speed: 62 MB/sec, entries written: 9332095, speed: 388837/sec
Time elapsed: 25s, bytes written: 1.5 GB, speed: 60 MB/sec, entries written: 9332095, speed: 373283/sec
Time elapsed: 26s, bytes written: 1.6 GB, speed: 62 MB/sec, entries written: 10000000, speed: 384615/sec
Time elapsed: 27s, bytes written: 1.6 GB, speed: 59 MB/sec, entries written: 10000000, speed: 370370/sec
Time elapsed: 28s, bytes written: 1.6 GB, speed: 57 MB/sec, entries written: 10000000, speed: 357142/sec
2020/09/28 13:46:15 DB.Close. Error: <nil>. Time taken to close: 35.949363929s


==> 2.2007.2.log <==
Time elapsed: 32s, bytes written: 1.3 GB, speed: 41 MB/sec, entries written: 8134975, speed: 254217/sec
Time elapsed: 33s, bytes written: 1.3 GB, speed: 41 MB/sec, entries written: 8369075, speed: 253608/sec
Time elapsed: 34s, bytes written: 1.4 GB, speed: 40 MB/sec, entries written: 8544650, speed: 251313/sec
Time elapsed: 35s, bytes written: 1.4 GB, speed: 40 MB/sec, entries written: 8837275, speed: 252493/sec
Time elapsed: 36s, bytes written: 1.5 GB, speed: 40 MB/sec, entries written: 9071375, speed: 251982/sec
Time elapsed: 37s, bytes written: 1.5 GB, speed: 40 MB/sec, entries written: 9305475, speed: 251499/sec
Time elapsed: 38s, bytes written: 1.5 GB, speed: 40 MB/sec, entries written: 9481050, speed: 249501/sec
Time elapsed: 39s, bytes written: 1.6 GB, speed: 40 MB/sec, entries written: 9715150, speed: 249106/sec
Time elapsed: 40s, bytes written: 1.6 GB, speed: 40 MB/sec, entries written: 9949250, speed: 248731/sec
2020/09/28 13:47:42 DB.Close. Error: <nil>. Time taken to close: 1.923953977s

==> master.log <==
Time elapsed: 34s, bytes written: 1.3 GB, speed: 39 MB/sec, entries written: 8341138, speed: 245327/sec, gcSuccess: 0
Time elapsed: 35s, bytes written: 1.4 GB, speed: 39 MB/sec, entries written: 8564041, speed: 244686/sec, gcSuccess: 0
Time elapsed: 36s, bytes written: 1.4 GB, speed: 39 MB/sec, entries written: 8837275, speed: 245479/sec, gcSuccess: 0
Time elapsed: 37s, bytes written: 1.4 GB, speed: 39 MB/sec, entries written: 9038987, speed: 244296/sec, gcSuccess: 0
Time elapsed: 38s, bytes written: 1.5 GB, speed: 39 MB/sec, entries written: 9246950, speed: 243340/sec, gcSuccess: 0
Time elapsed: 39s, bytes written: 1.5 GB, speed: 39 MB/sec, entries written: 9422525, speed: 241603/sec, gcSuccess: 0
Time elapsed: 40s, bytes written: 1.5 GB, speed: 38 MB/sec, entries written: 9598100, speed: 239952/sec, gcSuccess: 0
Time elapsed: 41s, bytes written: 1.6 GB, speed: 38 MB/sec, entries written: 9832200, speed: 239809/sec, gcSuccess: 0
Time elapsed: 42s, bytes written: 1.6 GB, speed: 38 MB/sec, entries written: 10000000, speed: 238095/sec, gcSuccess: 0
2020/09/28 13:43:17 DB.Close. Error: <nil>. Time taken to close: 1.902832818s

It looks like badger v1.6.2 was the fastest (total time is time elapsed+time to close).

There seems to be a performance degradation in v2 and we should investigate it.

@Naman we should investigate this.