]> Sergey Matveev's repositories - btrtrc.git/blob - storage/sqlite/sqlite-storage_test.go
Add const noCacheBlobs in sqlite storage benchmarks
[btrtrc.git] / storage / sqlite / sqlite-storage_test.go
1 package sqliteStorage
2
3 import (
4         "errors"
5         "fmt"
6         "path/filepath"
7         "testing"
8         "time"
9
10         _ "github.com/anacrolix/envpprof"
11         "github.com/anacrolix/squirrel"
12         "github.com/anacrolix/torrent/storage"
13         test_storage "github.com/anacrolix/torrent/storage/test"
14         "github.com/dustin/go-humanize"
15         qt "github.com/frankban/quicktest"
16 )
17
18 func BenchmarkMarkComplete(b *testing.B) {
19         const pieceSize = test_storage.DefaultPieceSize
20         const noTriggers = false
21         const noCacheBlobs = false
22         var capacity int64 = test_storage.DefaultNumPieces * pieceSize / 2
23         if noTriggers {
24                 // Since we won't push out old pieces, we have to mark them incomplete manually.
25                 capacity = 0
26         }
27         runBench := func(b *testing.B, ci storage.ClientImpl) {
28                 test_storage.BenchmarkPieceMarkComplete(b, ci, pieceSize, test_storage.DefaultNumPieces, capacity)
29         }
30         c := qt.New(b)
31         b.Run("CustomDirect", func(b *testing.B) {
32                 var opts squirrel.NewCacheOpts
33                 opts.Capacity = capacity
34                 opts.NoTriggers = noTriggers
35                 opts.NoCacheBlobs = noCacheBlobs
36                 benchOpts := func(b *testing.B) {
37                         opts.Path = filepath.Join(b.TempDir(), "storage.db")
38                         ci, err := NewDirectStorage(opts)
39                         c.Assert(err, qt.IsNil)
40                         defer ci.Close()
41                         runBench(b, ci)
42                 }
43                 b.Run("Default", benchOpts)
44         })
45         for _, memory := range []bool{false, true} {
46                 b.Run(fmt.Sprintf("Memory=%v", memory), func(b *testing.B) {
47                         b.Run("Direct", func(b *testing.B) {
48                                 var opts NewDirectStorageOpts
49                                 opts.Memory = memory
50                                 opts.Capacity = capacity
51                                 // opts.GcBlobs = true
52                                 opts.BlobFlushInterval = time.Second
53                                 opts.NoTriggers = noTriggers
54                                 opts.NoCacheBlobs = noCacheBlobs
55                                 directBench := func(b *testing.B) {
56                                         opts.Path = filepath.Join(b.TempDir(), "storage.db")
57                                         ci, err := NewDirectStorage(opts)
58                                         var ujm squirrel.ErrUnexpectedJournalMode
59                                         if errors.As(err, &ujm) {
60                                                 b.Skipf("setting journal mode %q: %v", opts.SetJournalMode, err)
61                                         }
62                                         c.Assert(err, qt.IsNil)
63                                         defer ci.Close()
64                                         runBench(b, ci)
65                                 }
66                                 for _, journalMode := range []string{"", "wal", "off", "truncate", "delete", "persist", "memory"} {
67                                         opts.SetJournalMode = journalMode
68                                         b.Run("JournalMode="+journalMode, func(b *testing.B) {
69                                                 for _, mmapSize := range []int64{-1} {
70                                                         if memory && mmapSize >= 0 {
71                                                                 continue
72                                                         }
73                                                         b.Run(fmt.Sprintf("MmapSize=%s", func() string {
74                                                                 if mmapSize < 0 {
75                                                                         return "default"
76                                                                 } else {
77                                                                         return humanize.IBytes(uint64(mmapSize))
78                                                                 }
79                                                         }()), func(b *testing.B) {
80                                                                 opts.MmapSize = mmapSize
81                                                                 opts.MmapSizeOk = true
82                                                                 directBench(b)
83                                                         })
84                                                 }
85                                         })
86                                 }
87                         })
88                 })
89         }
90 }