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