Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
test: add delay store to arc benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist committed Apr 6, 2021
1 parent 75d8d1a commit 3d591e3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
37 changes: 31 additions & 6 deletions arc_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/ipfs/go-block-format v0.0.2
github.com/ipfs/go-cid v0.0.5
github.com/ipfs/go-datastore v0.4.1
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.1
github.com/ipfs/go-log v0.0.1
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ github.com/ipfs/go-cid v0.0.5 h1:o0Ix8e/ql7Zb5UVUJEUfjsWCIY8t48++9lR8qi6oiJU=
github.com/ipfs/go-cid v0.0.5/go.mod h1:plgt+Y5MnOey4vO4UlUazGqdbEXuFYitED67FexhXog=
github.com/ipfs/go-datastore v0.4.1 h1:W4ZfzyhNi3xmuU5dQhjfuRn/wFuqEE1KnOmmQiOevEY=
github.com/ipfs/go-datastore v0.4.1/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=
Expand Down

0 comments on commit 3d591e3

Please sign in to comment.