aboutsummaryrefslogtreecommitdiff
path: root/cmd/bolt
diff options
context:
space:
mode:
authorSteven Normore <snormore@gmail.com>2014-04-11 13:55:14 +0000
committerBen Johnson <benbjohnson@yahoo.com>2014-04-18 21:44:27 -0500
commitfdde1bcb0624ce5232bf0f3226a2f47fd5a24cb3 (patch)
treeb2c9af8e1ed0076c8e0536dcc2f9a53aa811a5e0 /cmd/bolt
parentinitial bench and generate command structure (diff)
downloaddedo-fdde1bcb0624ce5232bf0f3226a2f47fd5a24cb3.tar.gz
dedo-fdde1bcb0624ce5232bf0f3226a2f47fd5a24cb3.tar.xz
moar bench package
Diffstat (limited to 'cmd/bolt')
-rw-r--r--cmd/bolt/bench.go70
-rw-r--r--cmd/bolt/import.go5
-rw-r--r--cmd/bolt/keys.go32
-rw-r--r--cmd/bolt/main.go3
-rw-r--r--cmd/bolt/set.go6
5 files changed, 70 insertions, 46 deletions
diff --git a/cmd/bolt/bench.go b/cmd/bolt/bench.go
index c35e747..28cbbc3 100644
--- a/cmd/bolt/bench.go
+++ b/cmd/bolt/bench.go
@@ -1,43 +1,43 @@
package main
import (
- "os"
+ "testing"
"github.com/boltdb/bolt"
)
-// Run benchmarks on a given dataset.
-func Bench() {
- path := "bench"
- if _, err := os.Stat(path); os.IsNotExist(err) {
- fatal(err)
- return
- }
-
- db, err := bolt.Open(path, 0600)
- if err != nil {
- fatal(err)
- return
- }
- defer db.Close()
-
- bucketName := "widgets"
- key := "key1"
- value := "value1"
-
- err = db.Update(func(tx *bolt.Tx) error {
- // Find bucket.
- b := tx.Bucket(bucketName)
- if b == nil {
- fatalf("bucket not found: %s", bucketName)
- return nil
- }
-
- // Set value for a given key.
- return b.Put([]byte(key), []byte(value))
- })
- if err != nil {
- fatal(err)
- return
- }
+// Import converts an exported database dump into a new database.
+// parallelism: integer representing number of concurrent reads/writes
+// readWriteMode: 'read' or 'write'
+// traversalPattern: 'sequentrial' or 'random'
+func Bench(inputPath string, readWriteMode string, traversalPattern string, parallelism int) {
+
+ // cursor/sequential reads
+ // random reads
+
+ // sequential writes
+ // random writes
+
+ // reading from many buckets
+ // writing to many buckets
+
+ // read from many paths
+ // writing to many paths
+
+ // bucket size/messages
+ // bucket depth
+
+ // concurrency
+
+ // chart/graph
+
+ // profile
+
+ // benchmarks for getting all keys
+
+ b := bolt.NewBenchmark(inputPath, readWriteMode, traversalPattern, parallelism)
+
+ result := testing.Benchmark(b.Run)
+
+ println(result)
}
diff --git a/cmd/bolt/import.go b/cmd/bolt/import.go
index bcb7d2e..0988f32 100644
--- a/cmd/bolt/import.go
+++ b/cmd/bolt/import.go
@@ -23,6 +23,11 @@ func Import(path string, input string) {
fatal(err)
}
+ // Import all of the buckets.
+ importBuckets(path, root)
+}
+
+func importBuckets(path string, root []*rawMessage) {
// Open the database.
db, err := bolt.Open(path, 0600)
if err != nil {
diff --git a/cmd/bolt/keys.go b/cmd/bolt/keys.go
index 6affefe..65b717f 100644
--- a/cmd/bolt/keys.go
+++ b/cmd/bolt/keys.go
@@ -1,6 +1,8 @@
package main
import (
+ "errors"
+ "fmt"
"os"
"github.com/boltdb/bolt"
@@ -8,34 +10,44 @@ import (
// Keys retrieves a list of keys for a given bucket.
func Keys(path, name string) {
- if _, err := os.Stat(path); os.IsNotExist(err) {
+ keys, err := keys(path, name)
+
+ if err != nil {
fatal(err)
return
}
+ for _, key := range keys {
+ println(key)
+ }
+}
+
+func keys(path, name string) ([]string, error) {
+ if _, err := os.Stat(path); os.IsNotExist(err) {
+ return nil, err
+ }
+
db, err := bolt.Open(path, 0600)
if err != nil {
- fatal(err)
- return
+ return nil, err
}
defer db.Close()
+ keys := []string{}
+
err = db.View(func(tx *bolt.Tx) error {
// Find bucket.
b := tx.Bucket([]byte(name))
if b == nil {
- fatalf("bucket not found: %s", name)
- return nil
+ return errors.New(fmt.Sprintf("bucket %+v not found", b))
}
// Iterate over each key.
return b.ForEach(func(key, _ []byte) error {
- println(string(key))
+ keys = append(keys, string(key))
return nil
})
})
- if err != nil {
- fatal(err)
- return
- }
+
+ return keys, err
}
diff --git a/cmd/bolt/main.go b/cmd/bolt/main.go
index 009bdc5..19df59f 100644
--- a/cmd/bolt/main.go
+++ b/cmd/bolt/main.go
@@ -107,7 +107,8 @@ func NewApp() *cli.App {
Name: "bench",
Usage: "Run benchmarks on a given dataset",
Action: func(c *cli.Context) {
- Bench()
+ srcPath := c.Args().Get(0)
+ Bench(srcPath, "read", "sequential", 1)
},
},
}
diff --git a/cmd/bolt/set.go b/cmd/bolt/set.go
index 9761f44..c757d27 100644
--- a/cmd/bolt/set.go
+++ b/cmd/bolt/set.go
@@ -21,6 +21,12 @@ func Set(path, name, key, value string) {
defer db.Close()
err = db.Update(func(tx *bolt.Tx) error {
+ // Create the bucket if it doesn't exist.
+ if err := tx.CreateBucketIfNotExists([]byte(name)); err != nil {
+ fatalf("create bucket: %s", err)
+ return nil
+ }
+
// Find bucket.
b := tx.Bucket([]byte(name))
if b == nil {