Something went wrong. Try again.
An ATProto Powered Reputation Network
Something went wrong. Try again.
2.8 kB · 88 lines
Go
at master
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889package storage
import ( "context" "fmt" "path/filepath" "testing"
"provenance/internal/domain" "provenance/internal/storage/db" "provenance/internal/trust")
// Include live replay versions and indexes so that bytes per record reflect ingestion storage.func BenchmarkSoftScale(b *testing.B) { for _, count := range []int{10000, 100000} { b.Run(fmt.Sprint(count), func(b *testing.B) { ctx := context.Background() s, err := OpenWithSoft(filepath.Join(b.TempDir(), "scale.db"), domain.SoftAllAuthors) if err != nil { b.Fatal(err) } defer s.Close() tx, err := s.conn.BeginTx(ctx, nil) if err != nil { b.Fatal(err) } q := s.queries.WithTx(tx) const authorCount = 1000 for index := 0; index < authorCount; index++ { if err := joinSoft(ctx, q, fmt.Sprintf("did:plc:%024d", index)); err != nil { b.Fatal(err) } } for index := 0; index < count; index++ { author := fmt.Sprintf("did:plc:%024d", index%authorCount) subject := fmt.Sprintf("did:plc:%024d", authorCount+index) key := fmt.Sprintf("3%012d", index) if err := putSoft(ctx, q, domain.Vouch{Author: author, Subject: subject, Source: domain.FollowCollection, RecordKey: key, Score: domain.FollowScore, CreatedAt: "2026-10-09T00:00:00Z"}); err != nil { b.Fatal(err) } if err := q.SetSoftVersion(ctx, db.SetSoftVersionParams{Author: author, Source: domain.FollowCollection, RecordKey: key, TimeUs: int64(index + 1)}); err != nil { b.Fatal(err) } } if err := tx.Commit(); err != nil { b.Fatal(err) } var pages, pageSize int64 if err := s.conn.QueryRow("PRAGMA page_count").Scan(&pages); err != nil { b.Fatal(err) } if err := s.conn.QueryRow("PRAGMA page_size").Scan(&pageSize); err != nil { b.Fatal(err) } bytesPerRecord := float64(pages*pageSize) / float64(count) for name, read := range map[string]func() ([]domain.Vouch, error){ "graph": func() ([]domain.Vouch, error) { rows, _, err := s.TrustGraph(ctx, "", domain.Default, count+1) return rows, err }, "outgoing": func() ([]domain.Vouch, error) { rows, _, err := s.Outgoing(ctx, fmt.Sprintf("did:plc:%024d", 0), "", domain.Default, count/authorCount+1) return rows, err }, } { b.Run(name, func(b *testing.B) { b.ReportAllocs() for index := 0; index < b.N; index++ { rows, err := read() if err != nil { b.Fatal(err) } selected := trust.Select(rows, "", domain.Default) expected := count if name == "outgoing" { expected /= authorCount } if len(selected) != expected { b.Fatal("selection lost edges") } } b.ReportMetric(bytesPerRecord, "disk-bytes/record") }) } }) }}