Get benchmarks working

This commit is contained in:
Matt Joiner 2021-05-04 22:56:43 +10:00
parent afea28091f
commit 855144212c
2 changed files with 32 additions and 19 deletions

View File

@ -98,6 +98,10 @@ type piece struct {
} }
func (p2 piece) getBlob() *sqlite.Blob { func (p2 piece) getBlob() *sqlite.Blob {
rowid, err := rowidForBlob(p2.conn, p2.name, p2.length)
if err != nil {
panic(err)
}
if *p2.blob != nil { if *p2.blob != nil {
err := (*p2.blob).Close() err := (*p2.blob).Close()
if err != nil { if err != nil {
@ -105,10 +109,6 @@ func (p2 piece) getBlob() *sqlite.Blob {
} }
*p2.blob = nil *p2.blob = nil
} }
rowid, err := rowidForBlob(p2.conn, p2.name, p2.length)
if err != nil {
panic(err)
}
*p2.blob, err = p2.conn.OpenBlob("main", "blob", "data", rowid, true) *p2.blob, err = p2.conn.OpenBlob("main", "blob", "data", rowid, true)
if err != nil { if err != nil {
panic(err) panic(err)
@ -144,7 +144,7 @@ func (p2 piece) MarkComplete() error {
} }
func (p2 piece) MarkNotComplete() error { func (p2 piece) MarkNotComplete() error {
panic("implement me") return sqlitex.Exec(p2.conn, "update blob set verified=false where name=?", nil, p2.name)
} }
func (p2 piece) Completion() (ret storage.Completion) { func (p2 piece) Completion() (ret storage.Completion) {

View File

@ -76,21 +76,34 @@ func BenchmarkMarkComplete(b *testing.B) {
b.Run(fmt.Sprintf("BatchWrites=%v", batchWrites), func(b *testing.B) { b.Run(fmt.Sprintf("BatchWrites=%v", batchWrites), func(b *testing.B) {
dbPath := filepath.Join(b.TempDir(), "storage.db") dbPath := filepath.Join(b.TempDir(), "storage.db")
//b.Logf("storage db path: %q", dbPath) //b.Logf("storage db path: %q", dbPath)
ci, err := NewPiecesStorage(NewPiecesStorageOpts{ newPoolOpts := NewPoolOpts{
NewPoolOpts: NewPoolOpts{ Path: dbPath,
Path: dbPath, Capacity: 4*pieceSize - 1,
Capacity: 4*pieceSize - 1, NoConcurrentBlobReads: false,
NoConcurrentBlobReads: false, PageSize: 1 << 14,
PageSize: 1 << 14, Memory: memory,
Memory: memory, }
}, provOpts := func(opts *ProviderOpts) {
ProvOpts: func(opts *ProviderOpts) { opts.BatchWrites = batchWrites
opts.BatchWrites = batchWrites }
}, b.Run("SqlitePieceStorage", func(b *testing.B) {
ci, err := NewPiecesStorage(NewPiecesStorageOpts{
NewPoolOpts: newPoolOpts,
ProvOpts: provOpts,
})
c.Assert(err, qt.IsNil)
defer ci.Close()
test_storage.BenchmarkPieceMarkComplete(b, ci, pieceSize, test_storage.DefaultNumPieces, capacity)
})
b.Run("SqliteDirect", func(b *testing.B) {
ci, err := NewDirectStorage(NewDirectStorageOpts{
NewPoolOpts: newPoolOpts,
ProvOpts: provOpts,
})
c.Assert(err, qt.IsNil)
defer ci.Close()
test_storage.BenchmarkPieceMarkComplete(b, ci, pieceSize, test_storage.DefaultNumPieces, capacity)
}) })
c.Assert(err, qt.IsNil)
defer ci.Close()
test_storage.BenchmarkPieceMarkComplete(b, ci, pieceSize, test_storage.DefaultNumPieces, capacity)
}) })
} }
}) })