2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-29 16:23:59 +00:00

Add more realistic index benchmarks

+ reduce test size of BenchmarkMasterIndexLookupParallel
This commit is contained in:
Alexander Weiss 2020-07-04 07:05:51 +02:00
parent 82c908871d
commit 3b7a3711e6
2 changed files with 25 additions and 38 deletions

View File

@ -336,7 +336,7 @@ var (
) )
func initBenchmarkIndexJSON() { func initBenchmarkIndexJSON() {
idx, _ := createRandomIndex(rand.New(rand.NewSource(0))) idx, _ := createRandomIndex(rand.New(rand.NewSource(0)), 200000)
var buf bytes.Buffer var buf bytes.Buffer
idx.Encode(&buf) idx.Encode(&buf)
benchmarkIndexJSON = buf.Bytes() benchmarkIndexJSON = buf.Bytes()
@ -418,11 +418,11 @@ func NewRandomTestID(rng *rand.Rand) restic.ID {
return id return id
} }
func createRandomIndex(rng *rand.Rand) (idx *repository.Index, lookupID restic.ID) { func createRandomIndex(rng *rand.Rand, packfiles int) (idx *repository.Index, lookupID restic.ID) {
idx = repository.NewIndex() idx = repository.NewIndex()
// create index with 200k pack files // create index with given number of pack files
for i := 0; i < 200000; i++ { for i := 0; i < packfiles; i++ {
packID := NewRandomTestID(rng) packID := NewRandomTestID(rng)
var blobs []restic.Blob var blobs []restic.Blob
offset := 0 offset := 0
@ -449,7 +449,7 @@ func createRandomIndex(rng *rand.Rand) (idx *repository.Index, lookupID restic.I
} }
func BenchmarkIndexHasUnknown(b *testing.B) { func BenchmarkIndexHasUnknown(b *testing.B) {
idx, _ := createRandomIndex(rand.New(rand.NewSource(0))) idx, _ := createRandomIndex(rand.New(rand.NewSource(0)), 200000)
lookupID := restic.NewRandomID() lookupID := restic.NewRandomID()
b.ResetTimer() b.ResetTimer()
@ -460,7 +460,7 @@ func BenchmarkIndexHasUnknown(b *testing.B) {
} }
func BenchmarkIndexHasKnown(b *testing.B) { func BenchmarkIndexHasKnown(b *testing.B) {
idx, lookupID := createRandomIndex(rand.New(rand.NewSource(0))) idx, lookupID := createRandomIndex(rand.New(rand.NewSource(0)), 200000)
b.ResetTimer() b.ResetTimer()
@ -474,7 +474,7 @@ func BenchmarkIndexAlloc(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
createRandomIndex(rng) createRandomIndex(rng, 200000)
} }
} }
@ -484,7 +484,7 @@ func BenchmarkIndexAllocParallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
rng := rand.New(rand.NewSource(0)) rng := rand.New(rand.NewSource(0))
for pb.Next() { for pb.Next() {
createRandomIndex(rng) createRandomIndex(rng, 200000)
} }
}) })
} }

View File

@ -57,11 +57,19 @@ func TestMasterIndexLookup(t *testing.T) {
rtest.Assert(t, blobs == nil, "Expected no blobs when fetching with a random id") rtest.Assert(t, blobs == nil, "Expected no blobs when fetching with a random id")
} }
func BenchmarkMasterIndexLookupSingleIndex(b *testing.B) { func createRandomMasterIndex(rng *rand.Rand, num, size int) (*repository.MasterIndex, restic.ID) {
idx1, lookupID := createRandomIndex(rand.New(rand.NewSource(0)))
mIdx := repository.NewMasterIndex() mIdx := repository.NewMasterIndex()
for i := 0; i < num-1; i++ {
idx, _ := createRandomIndex(rng, size)
mIdx.Insert(idx)
}
idx1, lookupID := createRandomIndex(rng, size)
mIdx.Insert(idx1) mIdx.Insert(idx1)
return mIdx, lookupID
}
func BenchmarkMasterIndexLookupSingleIndex(b *testing.B) {
mIdx, lookupID := createRandomMasterIndex(rand.New(rand.NewSource(0)), 1, 200000)
b.ResetTimer() b.ResetTimer()
@ -71,16 +79,7 @@ func BenchmarkMasterIndexLookupSingleIndex(b *testing.B) {
} }
func BenchmarkMasterIndexLookupMultipleIndex(b *testing.B) { func BenchmarkMasterIndexLookupMultipleIndex(b *testing.B) {
rng := rand.New(rand.NewSource(0)) mIdx, lookupID := createRandomMasterIndex(rand.New(rand.NewSource(0)), 100, 10000)
mIdx := repository.NewMasterIndex()
for i := 0; i < 5; i++ {
idx, _ := createRandomIndex(rng)
mIdx.Insert(idx)
}
idx1, lookupID := createRandomIndex(rng)
mIdx.Insert(idx1)
b.ResetTimer() b.ResetTimer()
@ -90,11 +89,9 @@ func BenchmarkMasterIndexLookupMultipleIndex(b *testing.B) {
} }
func BenchmarkMasterIndexLookupSingleIndexUnknown(b *testing.B) { func BenchmarkMasterIndexLookupSingleIndexUnknown(b *testing.B) {
lookupID := restic.NewRandomID()
idx1, _ := createRandomIndex(rand.New(rand.NewSource(0)))
mIdx := repository.NewMasterIndex() lookupID := restic.NewRandomID()
mIdx.Insert(idx1) mIdx, _ := createRandomMasterIndex(rand.New(rand.NewSource(0)), 1, 200000)
b.ResetTimer() b.ResetTimer()
@ -104,14 +101,8 @@ func BenchmarkMasterIndexLookupSingleIndexUnknown(b *testing.B) {
} }
func BenchmarkMasterIndexLookupMultipleIndexUnknown(b *testing.B) { func BenchmarkMasterIndexLookupMultipleIndexUnknown(b *testing.B) {
rng := rand.New(rand.NewSource(0))
lookupID := restic.NewRandomID() lookupID := restic.NewRandomID()
mIdx := repository.NewMasterIndex() mIdx, _ := createRandomMasterIndex(rand.New(rand.NewSource(0)), 100, 10000)
for i := 0; i < 6; i++ {
idx, _ := createRandomIndex(rng)
mIdx.Insert(idx)
}
b.ResetTimer() b.ResetTimer()
@ -123,16 +114,12 @@ func BenchmarkMasterIndexLookupMultipleIndexUnknown(b *testing.B) {
func BenchmarkMasterIndexLookupParallel(b *testing.B) { func BenchmarkMasterIndexLookupParallel(b *testing.B) {
mIdx := repository.NewMasterIndex() mIdx := repository.NewMasterIndex()
for _, numindices := range []int{5, 10, 20} { for _, numindices := range []int{25, 50, 100} {
var lookupID restic.ID var lookupID restic.ID
b.StopTimer() b.StopTimer()
rng := rand.New(rand.NewSource(0)) rng := rand.New(rand.NewSource(0))
for i := 0; i < numindices; i++ { mIdx, lookupID = createRandomMasterIndex(rng, numindices, 10000)
var idx *repository.Index
idx, lookupID = createRandomIndex(rng)
mIdx.Insert(idx)
}
b.StartTimer() b.StartTimer()
name := fmt.Sprintf("known,indices=%d", numindices) name := fmt.Sprintf("known,indices=%d", numindices)