Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(epictest) generate data before starting benchmark #449

Merged
merged 1 commit into from
Dec 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions epictest/addcat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
blockservice "github.com/jbenet/go-ipfs/blockservice"
bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
Expand All @@ -20,7 +21,6 @@ import (
util "github.com/jbenet/go-ipfs/util"
errors "github.com/jbenet/go-ipfs/util/debugerror"
delay "github.com/jbenet/go-ipfs/util/delay"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
)

const kSeed = 1
Expand All @@ -34,10 +34,9 @@ func Test100MBInstantaneous(t *testing.T) {
NetworkLatency: 0,
RoutingLatency: 0,
BlockstoreLatency: 0,
DataAmountBytes: 100 * 1024 * 1024,
}

AddCatBytes(conf)
AddCatBytes(RandomBytes(100*1024*1024), conf)
}

func TestDegenerateSlowBlockstore(t *testing.T) {
Expand Down Expand Up @@ -77,11 +76,9 @@ func Test100MBMacbookCoastToCoast(t *testing.T) {
SkipUnlessEpic(t)
t.Parallel()

conf := Config{
DataAmountBytes: 100 * 1024 * 1024,
}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow()
conf := Config{}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow()

if err := AddCatBytes(conf); err != nil {
if err := AddCatBytes(RandomBytes(100*1024*1024), conf); err != nil {
t.Fatal(err)
}
}
Expand All @@ -90,15 +87,20 @@ func AddCatPowers(conf Config, megabytesMax int64) error {
var i int64
for i = 1; i < megabytesMax; i = i * 2 {
fmt.Printf("%d MB\n", i)
conf.DataAmountBytes = i * 1024 * 1024
if err := AddCatBytes(conf); err != nil {
if err := AddCatBytes(RandomBytes(i*1024*1024), conf); err != nil {
return err
}
}
return nil
}

func AddCatBytes(conf Config) error {
func RandomBytes(n int64) []byte {
var data bytes.Buffer
random.WritePseudoRandomBytes(n, &data, kSeed)
return data.Bytes()
}

func AddCatBytes(data []byte, conf Config) error {

sessionGenerator := bitswap.NewSessionGenerator(
tn.VirtualNetwork(delay.Fixed(conf.NetworkLatency)), // TODO rename VirtualNetwork
Expand All @@ -111,9 +113,7 @@ func AddCatBytes(conf Config) error {
catter.SetBlockstoreLatency(conf.BlockstoreLatency)

adder.SetBlockstoreLatency(0) // disable blockstore latency during add operation
var data bytes.Buffer
random.WritePseudoRandomBytes(conf.DataAmountBytes, &data, kSeed) // FIXME get a lazy reader
keyAdded, err := add(adder, bytes.NewReader(data.Bytes()))
keyAdded, err := add(adder, bytes.NewReader(data))
if err != nil {
return err
}
Expand All @@ -127,7 +127,7 @@ func AddCatBytes(conf Config) error {
// verify
var bufout bytes.Buffer
io.Copy(&bufout, readerCatted)
if 0 != bytes.Compare(bufout.Bytes(), data.Bytes()) {
if 0 != bytes.Compare(bufout.Bytes(), data) {
return errors.New("catted data does not match added data")
}
return nil
Expand Down
77 changes: 41 additions & 36 deletions epictest/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,61 @@ package epictest

import "testing"

func benchmarkAddCat(conf Config, b *testing.B) {
b.SetBytes(conf.DataAmountBytes)
func benchmarkAddCat(numBytes int64, conf Config, b *testing.B) {

b.StopTimer()
b.SetBytes(numBytes)
data := RandomBytes(numBytes) // we don't want to measure the time it takes to generate this data
b.StartTimer()

for n := 0; n < b.N; n++ {
if err := AddCatBytes(conf); err != nil {
if err := AddCatBytes(data, conf); err != nil {
b.Fatal(err)
}
}
}

var instant = Config{}.All_Instantaneous()

func BenchmarkInstantaneousAddCat1MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(1), b) }
func BenchmarkInstantaneousAddCat2MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(2), b) }
func BenchmarkInstantaneousAddCat4MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(4), b) }
func BenchmarkInstantaneousAddCat8MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(8), b) }
func BenchmarkInstantaneousAddCat16MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(16), b) }
func BenchmarkInstantaneousAddCat32MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(32), b) }
func BenchmarkInstantaneousAddCat64MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(64), b) }
func BenchmarkInstantaneousAddCat128MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(128), b) }
func BenchmarkInstantaneousAddCat256MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(256), b) }
func BenchmarkInstantaneousAddCat1MB(b *testing.B) { benchmarkAddCat(1*MB, instant, b) }
func BenchmarkInstantaneousAddCat2MB(b *testing.B) { benchmarkAddCat(2*MB, instant, b) }
func BenchmarkInstantaneousAddCat4MB(b *testing.B) { benchmarkAddCat(4*MB, instant, b) }
func BenchmarkInstantaneousAddCat8MB(b *testing.B) { benchmarkAddCat(8*MB, instant, b) }
func BenchmarkInstantaneousAddCat16MB(b *testing.B) { benchmarkAddCat(16*MB, instant, b) }
func BenchmarkInstantaneousAddCat32MB(b *testing.B) { benchmarkAddCat(32*MB, instant, b) }
func BenchmarkInstantaneousAddCat64MB(b *testing.B) { benchmarkAddCat(64*MB, instant, b) }
func BenchmarkInstantaneousAddCat128MB(b *testing.B) { benchmarkAddCat(128*MB, instant, b) }
func BenchmarkInstantaneousAddCat256MB(b *testing.B) { benchmarkAddCat(256*MB, instant, b) }

var routing = Config{}.Routing_Slow()

func BenchmarkRoutingSlowAddCat1MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(1), b) }
func BenchmarkRoutingSlowAddCat2MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(2), b) }
func BenchmarkRoutingSlowAddCat4MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(4), b) }
func BenchmarkRoutingSlowAddCat8MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(8), b) }
func BenchmarkRoutingSlowAddCat16MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(16), b) }
func BenchmarkRoutingSlowAddCat32MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(32), b) }
func BenchmarkRoutingSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*MB, routing, b) }
func BenchmarkRoutingSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*MB, routing, b) }
func BenchmarkRoutingSlowAddCat4MB(b *testing.B) { benchmarkAddCat(4*MB, routing, b) }
func BenchmarkRoutingSlowAddCat8MB(b *testing.B) { benchmarkAddCat(8*MB, routing, b) }
func BenchmarkRoutingSlowAddCat16MB(b *testing.B) { benchmarkAddCat(16*MB, routing, b) }
func BenchmarkRoutingSlowAddCat32MB(b *testing.B) { benchmarkAddCat(32*MB, routing, b) }

var network = Config{}.Network_NYtoSF()

func BenchmarkNetworkSlowAddCat1MB(b *testing.B) { benchmarkAddCat(network.Megabytes(1), b) }
func BenchmarkNetworkSlowAddCat2MB(b *testing.B) { benchmarkAddCat(network.Megabytes(2), b) }
func BenchmarkNetworkSlowAddCat4MB(b *testing.B) { benchmarkAddCat(network.Megabytes(4), b) }
func BenchmarkNetworkSlowAddCat8MB(b *testing.B) { benchmarkAddCat(network.Megabytes(8), b) }
func BenchmarkNetworkSlowAddCat16MB(b *testing.B) { benchmarkAddCat(network.Megabytes(16), b) }
func BenchmarkNetworkSlowAddCat32MB(b *testing.B) { benchmarkAddCat(network.Megabytes(32), b) }
func BenchmarkNetworkSlowAddCat64MB(b *testing.B) { benchmarkAddCat(network.Megabytes(64), b) }
func BenchmarkNetworkSlowAddCat128MB(b *testing.B) { benchmarkAddCat(network.Megabytes(128), b) }
func BenchmarkNetworkSlowAddCat256MB(b *testing.B) { benchmarkAddCat(network.Megabytes(256), b) }
func BenchmarkNetworkSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*MB, network, b) }
func BenchmarkNetworkSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*MB, network, b) }
func BenchmarkNetworkSlowAddCat4MB(b *testing.B) { benchmarkAddCat(4*MB, network, b) }
func BenchmarkNetworkSlowAddCat8MB(b *testing.B) { benchmarkAddCat(8*MB, network, b) }
func BenchmarkNetworkSlowAddCat16MB(b *testing.B) { benchmarkAddCat(16*MB, network, b) }
func BenchmarkNetworkSlowAddCat32MB(b *testing.B) { benchmarkAddCat(32*MB, network, b) }
func BenchmarkNetworkSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*MB, network, b) }
func BenchmarkNetworkSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*MB, network, b) }
func BenchmarkNetworkSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*MB, network, b) }

var blockstore = Config{}.Blockstore_7200RPM()

func BenchmarkBlockstoreSlowAddCat1MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(1), b) }
func BenchmarkBlockstoreSlowAddCat2MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(2), b) }
func BenchmarkBlockstoreSlowAddCat4MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(4), b) }
func BenchmarkBlockstoreSlowAddCat8MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(8), b) }
func BenchmarkBlockstoreSlowAddCat16MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(16), b) }
func BenchmarkBlockstoreSlowAddCat32MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(32), b) }
func BenchmarkBlockstoreSlowAddCat64MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(64), b) }
func BenchmarkBlockstoreSlowAddCat128MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(128), b) }
func BenchmarkBlockstoreSlowAddCat256MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(256), b) }
func BenchmarkBlockstoreSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*MB, blockstore, b) }
func BenchmarkBlockstoreSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*MB, blockstore, b) }
func BenchmarkBlockstoreSlowAddCat4MB(b *testing.B) { benchmarkAddCat(4*MB, blockstore, b) }
func BenchmarkBlockstoreSlowAddCat8MB(b *testing.B) { benchmarkAddCat(8*MB, blockstore, b) }
func BenchmarkBlockstoreSlowAddCat16MB(b *testing.B) { benchmarkAddCat(16*MB, blockstore, b) }
func BenchmarkBlockstoreSlowAddCat32MB(b *testing.B) { benchmarkAddCat(32*MB, blockstore, b) }
func BenchmarkBlockstoreSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*MB, blockstore, b) }
func BenchmarkBlockstoreSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*MB, blockstore, b) }
func BenchmarkBlockstoreSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*MB, blockstore, b) }
7 changes: 0 additions & 7 deletions epictest/test_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type Config struct {
BlockstoreLatency time.Duration
NetworkLatency time.Duration
RoutingLatency time.Duration
DataAmountBytes int64
}

func (c Config) All_Instantaneous() Config {
Expand Down Expand Up @@ -47,9 +46,3 @@ func (c Config) Routing_Slow() Config {
c.BlockstoreLatency = 200 * time.Millisecond
return c
}

// Megabytes is a convenience method to set DataAmountBytes
func (c Config) Megabytes(mb int64) Config {
c.DataAmountBytes = mb * 1024 * 1024
return c
}
11 changes: 11 additions & 0 deletions epictest/unit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package epictest

const (
_ = iota // ignore first value by assigning to blank identifier
KB = 1 << (10 * iota)
MB
GB
TB
PB
EB
)
26 changes: 26 additions & 0 deletions epictest/unit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package epictest

import "testing"

// and the award for most meta goes to...

func TestByteSizeUnit(t *testing.T) {
if 1*KB != 1*1024 {
t.Fatal(1 * KB)
}
if 1*MB != 1*1024*1024 {
t.Fail()
}
if 1*GB != 1*1024*1024*1024 {
t.Fail()
}
if 1*TB != 1*1024*1024*1024*1024 {
t.Fail()
}
if 1*PB != 1*1024*1024*1024*1024*1024 {
t.Fail()
}
if 1*EB != 1*1024*1024*1024*1024*1024*1024 {
t.Fail()
}
}