diff options
Diffstat (limited to 'tx_test.go')
-rw-r--r-- | tx_test.go | 208 |
1 files changed, 0 insertions, 208 deletions
@@ -3,13 +3,9 @@ package bolt import ( "errors" "fmt" - "math/rand" "os" - "strconv" - "strings" "testing" - "github.com/boltdb/bolt/bench" "github.com/stretchr/testify/assert" ) @@ -267,210 +263,6 @@ func TestTx_OnCommit_Rollback(t *testing.T) { assert.Equal(t, 0, x) } -// func BenchmarkReadSequential_1Concurrency_1Buckets_1Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 1, 1) -// } -// func BenchmarkReadSequential_1Concurrency_1Buckets_10Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 10, 1) -// } -// func BenchmarkReadSequential_1Concurrency_1Buckets_100Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 100, 1) -// } -// func BenchmarkReadSequential_1Concurrency_1Buckets_1000Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 1000, 1) -// } -// func BenchmarkReadSequential_1Concurrency_1Buckets_10000Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 10000, 1) -// } - -// func BenchmarkReadSequential_10Concurrency_1Buckets_1Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 1, 10) -// } -// func BenchmarkReadSequential_10Concurrency_1Buckets_10Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 10, 10) -// } -// func BenchmarkReadSequential_10Concurrency_1Buckets_100Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 100, 10) -// } -// func BenchmarkReadSequential_10Concurrency_1Buckets_1000Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 1000, 10) -// } -// func BenchmarkReadSequential_10Concurrency_1Buckets_10000Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 10000, 10) -// } - -// func BenchmarkReadSequential_100Concurrency_1Buckets_1Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 1, 100) -// } -// func BenchmarkReadSequential_100Concurrency_1Buckets_10Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 10, 100) -// } -// func BenchmarkReadSequential_100Concurrency_1Buckets_100Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 100, 100) -// } -// func BenchmarkReadSequential_100Concurrency_1Buckets_1000Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 1000, 100) -// } -// func BenchmarkReadSequential_100Concurrency_1Buckets_10000Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 10000, 100) -// } - -// func BenchmarkReadSequential_1000Concurrency_1Buckets_1Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 1, 1000) -// } -// func BenchmarkReadSequential_1000Concurrency_1Buckets_10Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 10, 1000) -// } -// func BenchmarkReadSequential_1000Concurrency_1Buckets_100Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 100, 1000) -// } -// func BenchmarkReadSequential_1000Concurrency_1Buckets_1000Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 1000, 1000) -// } -// func BenchmarkReadSequential_1000Concurrency_1Buckets_10000Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 10000, 1000) -// } - -// func BenchmarkReadSequential_10000Concurrency_1Buckets_1Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 1, 10000) -// } -// func BenchmarkReadSequential_10000Concurrency_1Buckets_10Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 10, 10000) -// } -// func BenchmarkReadSequential_10000Concurrency_1Buckets_100Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 100, 10000) -// } -// func BenchmarkReadSequential_10000Concurrency_1Buckets_1000Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 1000, 10000) -// } -// func BenchmarkReadSequential_10000Concurrency_1Buckets_10000Items(b *testing.B) { -// benchmarkReadSequential(b, 1, 10000, 10000) -// } - -// func benchmark(b *testing.B, readWriteMode, traversalPattern string, numBuckets, numItemsPerBucket, parallelism int) { -// withOpenDB(func(db *DB, path string) { -// if err := bench.GenerateDB(db, numBuckets, numItemsPerBucket); err != nil { -// b.Fatal(err) -// } -// bench.New(db, &bench.Config{ -// ReadWriteMode: readWriteMode, -// TraversalPattern: traversalPattern, -// Parallelism: parallelism, -// }).Run(b) -// }) -// } - -// func benchmarkRead(b *testing.B, traversalPattern string, numBuckets, numItemsPerBucket, parallelism int) { -// benchmark(b, bench.BenchReadMode, traversalPattern, numBuckets, numItemsPerBucket, parallelism) -// } - -// func benchmarkReadSequential(b *testing.B, numBuckets, numItemsPerBucket, parallelism int) { -// benchmark(b, bench.BenchReadMode, bench.BenchSequentialTraversal, numBuckets, numItemsPerBucket, parallelism) -// } - -// func benchmarkReadRandom(b *testing.B, numBuckets, numItemsPerBucket, parallelism int) { -// benchmark(b, bench.BenchReadMode, bench.BenchRandomTraversal, numBuckets, numItemsPerBucket, parallelism) -// } - -// Benchmark the performance iterating over a cursor. -func BenchmarkTxCursor1(b *testing.B) { benchmarkTxCursor(b, 1) } -func BenchmarkTxCursor10(b *testing.B) { benchmarkTxCursor(b, 10) } -func BenchmarkTxCursor100(b *testing.B) { benchmarkTxCursor(b, 100) } -func BenchmarkTxCursor1000(b *testing.B) { benchmarkTxCursor(b, 1000) } -func BenchmarkTxCursor10000(b *testing.B) { benchmarkTxCursor(b, 10000) } - -func benchmarkTxCursor(b *testing.B, total int) { - indexes := rand.Perm(total) - value := []byte(strings.Repeat("0", 100)) - - withOpenDB(func(db *DB, path string) { - // Write data to bucket. - db.Update(func(tx *Tx) error { - tx.CreateBucket([]byte("widgets")) - bucket := tx.Bucket([]byte("widgets")) - for i := 0; i < total; i++ { - bucket.Put([]byte(fmt.Sprintf("%016d", indexes[i])), value) - } - return nil - }) - b.ResetTimer() - - // Iterate over bucket using cursor. - for i := 0; i < b.N; i++ { - db.View(func(tx *Tx) error { - count := 0 - c := tx.Bucket([]byte("widgets")).Cursor() - for k, _ := c.First(); k != nil; k, _ = c.Next() { - count++ - } - if count != total { - b.Fatalf("wrong count: %d; expected: %d", count, total) - } - return nil - }) - } - }) -} - -// Benchmark the performance of bulk put transactions in random order. -func BenchmarkTxPutRandom1(b *testing.B) { benchmarkTxPutRandom(b, 1) } -func BenchmarkTxPutRandom10(b *testing.B) { benchmarkTxPutRandom(b, 10) } -func BenchmarkTxPutRandom100(b *testing.B) { benchmarkTxPutRandom(b, 100) } -func BenchmarkTxPutRandom1000(b *testing.B) { benchmarkTxPutRandom(b, 1000) } -func BenchmarkTxPutRandom10000(b *testing.B) { benchmarkTxPutRandom(b, 10000) } - -func benchmarkTxPutRandom(b *testing.B, total int) { - indexes := rand.Perm(total) - value := []byte(strings.Repeat("0", 64)) - withOpenDB(func(db *DB, path string) { - db.Update(func(tx *Tx) error { - _, err := tx.CreateBucket([]byte("widgets")) - return err - }) - var tx *Tx - var bucket *Bucket - for j := 0; j < b.N; j++ { - for i := 0; i < total; i++ { - if i%1000 == 0 { - if tx != nil { - tx.Commit() - } - tx, _ = db.Begin(true) - bucket = tx.Bucket([]byte("widgets")) - } - bucket.Put([]byte(strconv.Itoa(indexes[i])), value) - } - } - tx.Commit() - }) -} - -// Benchmark the performance of bulk put transactions in sequential order. -func BenchmarkTxPutSequential1(b *testing.B) { benchmarkTxPutSequential(b, 1) } -func BenchmarkTxPutSequential10(b *testing.B) { benchmarkTxPutSequential(b, 10) } -func BenchmarkTxPutSequential100(b *testing.B) { benchmarkTxPutSequential(b, 100) } -func BenchmarkTxPutSequential1000(b *testing.B) { benchmarkTxPutSequential(b, 1000) } -func BenchmarkTxPutSequential10000(b *testing.B) { benchmarkTxPutSequential(b, 10000) } - -func benchmarkTxPutSequential(b *testing.B, total int) { - value := []byte(strings.Repeat("0", 64)) - withOpenDB(func(db *DB, path string) { - db.Update(func(tx *Tx) error { - _, err := tx.CreateBucket([]byte("widgets")) - return err - }) - db.Update(func(tx *Tx) error { - bucket := tx.Bucket([]byte("widgets")) - for j := 0; j < b.N; j++ { - for i := 0; i < total; i++ { - bucket.Put([]byte(strconv.Itoa(i)), value) - } - } - return nil - }) - }) -} - func ExampleTx_Rollback() { // Open the database. db, _ := Open(tempfile(), 0666) |