-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code to create graphs for issue #40.
Use "make benchmark" to run.
- Loading branch information
Showing
20 changed files
with
376 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import db "github.com/ipfs/go-datastore/flatfs" | ||
|
||
func main() { | ||
db.TimeQuery() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
sort -nk2 res | awk '$1 == "direct" {$2 = "direct"}; 1' > res2 | ||
|
||
gnuplot <<EOF | ||
set terminal png size 800,500 | ||
set grid lw 0.25 | ||
set output "plot.png" | ||
set style fill solid 0.25 border -1 | ||
set style boxplot outliers pointtype 7 | ||
set style data boxplot | ||
set title "flatfs query key-only 10,000 entries" | ||
set ylabel "time (ms)" | ||
set xlabel "buffer size" | ||
plot "res2" using (1):3:(0.5):2 notitle | ||
EOF | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../leveldb/run-benchmark.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package flatfs | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"math/rand" | ||
"time" | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
ds "github.com/ipfs/go-datastore" | ||
dsq "github.com/ipfs/go-datastore/query" | ||
) | ||
|
||
var N = 10000 | ||
|
||
func TimeQuery() { | ||
rand.Seed(time.Now().UTC().UnixNano()) | ||
path, err := ioutil.TempDir("/tmp", "flatdb_") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
d, err := New(path, 5, false) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer func() { | ||
os.RemoveAll(path) | ||
d.Close() | ||
}() | ||
for n := 0; n < N; n++ { | ||
err := d.Put(ds.NewKey(RandomString(52)), []byte(RandomString(1000))) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
//TestQuery(d) | ||
//TestQuery(d) | ||
//TestQuery(d) | ||
// TestDirect(d) | ||
// TestIterator(d) | ||
// TestQuery(d) | ||
//TestDirect(d) | ||
//TestDirect(d) | ||
//TestDirect(d) | ||
// TestQuery(d) | ||
// TestDirect(d) | ||
// TestQuery(d) | ||
// TestDirect(d) | ||
// TestQuery(d) | ||
// TestDirect(d) | ||
// TestDirect(d) | ||
// TestDirect(d) | ||
// TestIterator(d) | ||
// TestIterator(d) | ||
// TestIterator(d) | ||
// TestIterator(d) | ||
// TestQuery(d) | ||
// TestQuery(d) | ||
// TestQuery(d) | ||
for i := 0; i <= 100; i++ { | ||
dsq.KeysOnlyBufSize = 1 << uint(rand.Intn(15)) | ||
if dsq.KeysOnlyBufSize <= 8192 { | ||
TestQuery(d) | ||
} else { | ||
TestDirect(d) | ||
} | ||
} | ||
} | ||
|
||
func TestQuery(d *Datastore) { | ||
start := time.Now() | ||
rs, err := d.Query(dsq.Query{KeysOnly: true}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
i := 0 | ||
for r := range rs.Next() { | ||
i += int(r.Key[0]) | ||
} | ||
elapsed := time.Since(start) | ||
//fmt.Printf("i = %d\n", i) | ||
fmt.Printf("query %d %f\n", dsq.KeysOnlyBufSize, elapsed.Seconds()*1000) | ||
} | ||
|
||
func TestDirect(fs *Datastore) { | ||
start := time.Now() | ||
i := 0 | ||
err := filepath.Walk(fs.path, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
log.Errorf("Walk func in Query got error: %v", err) | ||
return err | ||
} | ||
|
||
if !info.Mode().IsRegular() || strings.HasPrefix(info.Name(), ".") { | ||
return nil | ||
} | ||
|
||
key, ok := fs.decode(info.Name()) | ||
if !ok { | ||
log.Warning("failed to decode entry in flatfs") | ||
return nil | ||
} | ||
|
||
i += int(key.String()[0]) | ||
|
||
return nil | ||
}) | ||
if err != nil { | ||
log.Warning("walk failed: ", err) | ||
} | ||
elapsed := time.Since(start) | ||
//fmt.Printf("i = %d\n", i) | ||
fmt.Printf("direct %d %f\n", dsq.KeysOnlyBufSize, elapsed.Seconds()*1000) | ||
|
||
} | ||
|
||
|
||
|
||
func RandomString(strlen int) string { | ||
const chars = "abcdefghijklmnopqrstuvwxyz0123456789" | ||
result := make([]byte, strlen) | ||
for i := 0; i < strlen; i++ { | ||
result[i] = chars[rand.Intn(len(chars))] | ||
} | ||
return string(result) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import leveldb "github.com/ipfs/go-datastore/leveldb" | ||
|
||
func main() { | ||
leveldb.TimeQuery() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
sort -nk2 res | awk '$1 == "direct" {$2 = "direct"}; 1' > res2 | ||
|
||
gnuplot <<EOF | ||
set terminal png size 800,500 | ||
set grid lw 0.25 | ||
set output "plot.png" | ||
set style fill solid 0.25 border -1 | ||
set style boxplot outliers pointtype 7 | ||
set style data boxplot | ||
set title "leveldb query key-only 100,000 entries" | ||
set ylabel "time (ms)" | ||
set xlabel "buffer size" | ||
plot "res2" using (1):3:(0.5):2 notitle | ||
EOF | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
set -x | ||
|
||
go run main/main.go > res | ||
./plot.sh |
Oops, something went wrong.