diff --git a/arc_cache_test.go b/arc_cache_test.go index f330e83..d9ffcfa 100644 --- a/arc_cache_test.go +++ b/arc_cache_test.go @@ -10,7 +10,9 @@ import ( blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" + delaystore "github.com/ipfs/go-datastore/delayed" syncds "github.com/ipfs/go-datastore/sync" + delay "github.com/ipfs/go-ipfs-delay" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -41,6 +43,17 @@ func createStores(t testing.TB) (*arccache, Blockstore, *callbackDatastore) { return arc, bs, cd } +func createStoresWithDelay(t testing.TB, delayed delay.D) (*arccache, Blockstore, *callbackDatastore) { + cd := &callbackDatastore{f: func() {}, ds: ds.NewMapDatastore()} + slowStore := delaystore.New(cd, delayed) + bs := NewBlockstore(syncds.MutexWrap(slowStore)) + arc, err := testArcCached(context.TODO(), bs) + if err != nil { + t.Fatal(err) + } + return arc, bs, cd +} + func trap(message string, cd *callbackDatastore, t *testing.T) { cd.SetFunc(func() { t.Fatal(message) @@ -318,32 +331,36 @@ func Benchmark_SimplePutDelete(b *testing.B) { } func Benchmark_ThrashPut(b *testing.B) { - arc, _, _ := createStores(b) - table := []struct { numBlocks int threads int + delay time.Duration }{ { numBlocks: 1_000_000, threads: 1, + delay: time.Millisecond * 1, }, { numBlocks: 1_000_000, threads: 32, + delay: time.Millisecond * 1, }, { numBlocks: 1_000_000, threads: 64, + delay: time.Millisecond * 1, }, { numBlocks: 1_000_000, threads: 500, + delay: time.Millisecond * 1, }, } for _, test := range table { b.Run(fmt.Sprintf("%d_threads-%d_blocks", test.threads, test.numBlocks), func(b *testing.B) { + arc, _, _ := createStoresWithDelay(b, delay.Fixed(test.delay)) trace := make([]blocks.Block, test.numBlocks) for i := 0; i < test.numBlocks; i++ { token := make([]byte, 4) @@ -386,32 +403,36 @@ func Benchmark_ThrashPut(b *testing.B) { } func Benchmark_ThrashGet(b *testing.B) { - arc, _, _ := createStores(b) - table := []struct { numBlocks int threads int + delay time.Duration }{ { numBlocks: 1_000_000, threads: 1, + delay: time.Millisecond * 1, }, { numBlocks: 1_000_000, threads: 32, + delay: time.Millisecond * 1, }, { numBlocks: 1_000_000, threads: 64, + delay: time.Millisecond * 1, }, { numBlocks: 1_000_000, threads: 500, + delay: time.Millisecond * 1, }, } for _, test := range table { b.Run(fmt.Sprintf("%d_threads-%d_blocks", test.threads, test.numBlocks), func(b *testing.B) { + arc, _, _ := createStoresWithDelay(b, delay.Fixed(test.delay)) trace := make([]blocks.Block, test.numBlocks) for i := 0; i < test.numBlocks; i++ { token := make([]byte, 4) @@ -454,32 +475,36 @@ func Benchmark_ThrashGet(b *testing.B) { } func Benchmark_ThrashDelete(b *testing.B) { - arc, _, _ := createStores(b) - table := []struct { numBlocks int threads int + delay time.Duration }{ { numBlocks: 1_000_000, threads: 1, + delay: time.Millisecond * 1, }, { numBlocks: 1_000_000, threads: 32, + delay: time.Millisecond * 1, }, { numBlocks: 1_000_000, threads: 64, + delay: time.Millisecond * 1, }, { numBlocks: 1_000_000, threads: 500, + delay: time.Millisecond * 1, }, } for _, test := range table { b.Run(fmt.Sprintf("%d_threads-%d_blocks", test.threads, test.numBlocks), func(b *testing.B) { + arc, _, _ := createStoresWithDelay(b, delay.Fixed(test.delay)) trace := make([]blocks.Block, test.numBlocks) for i := 0; i < test.numBlocks; i++ { token := make([]byte, 4) diff --git a/go.mod b/go.mod index 64675b4..cb44afe 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/ipfs/go-block-format v0.0.3 github.com/ipfs/go-cid v0.0.7 github.com/ipfs/go-datastore v0.4.2 + github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8 github.com/ipfs/go-ipfs-ds-help v1.0.0 github.com/ipfs/go-ipfs-util v0.0.2 github.com/ipfs/go-log v0.0.1 diff --git a/go.sum b/go.sum index cc30010..a9befeb 100644 --- a/go.sum +++ b/go.sum @@ -20,6 +20,7 @@ github.com/ipfs/go-datastore v0.4.1 h1:W4ZfzyhNi3xmuU5dQhjfuRn/wFuqEE1KnOmmQiOev github.com/ipfs/go-datastore v0.4.1/go.mod h1:SX/xMIKoCszPqp+z9JhPYCmoOoXTvaa13XEbGtsFUhA= github.com/ipfs/go-datastore v0.4.2 h1:h8/n7WPzhp239kkLws+epN3Ic7YtcBPgcaXfEfdVDWM= github.com/ipfs/go-datastore v0.4.2/go.mod h1:SX/xMIKoCszPqp+z9JhPYCmoOoXTvaa13XEbGtsFUhA= +github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8 h1:NAviDvJ0WXgD+yiL2Rj35AmnfgI11+pHXbdciD917U0= github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= github.com/ipfs/go-ipfs-ds-help v1.0.0 h1:bEQ8hMGs80h0sR8O4tfDgV6B01aaF9qeTrujrTLYV3g= github.com/ipfs/go-ipfs-ds-help v1.0.0/go.mod h1:ujAbkeIgkKAWtxxNkoZHWLCyk5JpPoKnGyCcsoF6ueE=