diff --git a/cmd/benchmark/Dockerfile.khatru-badger b/cmd/benchmark/Dockerfile.khatru-badger index af67992..cce030b 100644 --- a/cmd/benchmark/Dockerfile.khatru-badger +++ b/cmd/benchmark/Dockerfile.khatru-badger @@ -6,7 +6,7 @@ WORKDIR /build COPY . . # Build the basic-badger example -RUN cd examples/basic-badger && \ +RUN echo ${pwd};cd examples/basic-badger && \ go mod tidy && \ CGO_ENABLED=0 go build -o khatru-badger . diff --git a/cmd/benchmark/Dockerfile.next-orly b/cmd/benchmark/Dockerfile.next-orly index 85c9a06..ded2018 100644 --- a/cmd/benchmark/Dockerfile.next-orly +++ b/cmd/benchmark/Dockerfile.next-orly @@ -78,7 +78,7 @@ EXPOSE 8080 ENV ORLY_DATA_DIR=/data ENV ORLY_LISTEN=0.0.0.0 ENV ORLY_PORT=8080 -ENV ORLY_LOG_LEVEL=info +ENV ORLY_LOG_LEVEL=off # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ diff --git a/cmd/benchmark/docker-compose.yml b/cmd/benchmark/docker-compose.yml index d424dd6..5acf60c 100644 --- a/cmd/benchmark/docker-compose.yml +++ b/cmd/benchmark/docker-compose.yml @@ -11,7 +11,7 @@ services: - ORLY_DATA_DIR=/data - ORLY_LISTEN=0.0.0.0 - ORLY_PORT=8080 - - ORLY_LOG_LEVEL=info + - ORLY_LOG_LEVEL=off volumes: - ./data/next-orly:/data ports: diff --git a/cmd/benchmark/main.go b/cmd/benchmark/main.go index 15e9fff..c8b4497 100644 --- a/cmd/benchmark/main.go +++ b/cmd/benchmark/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "crypto/rand" "flag" "fmt" "log" @@ -14,7 +13,6 @@ import ( "sync" "time" - lol "lol.mleku.dev" "next.orly.dev/pkg/crypto/p256k" "next.orly.dev/pkg/database" "next.orly.dev/pkg/encoders/envelopes/eventenvelope" @@ -64,7 +62,7 @@ type Benchmark struct { } func main() { - lol.SetLogLevel("trace") + // lol.SetLogLevel("trace") config := parseFlags() if config.RelayURL != "" { @@ -136,13 +134,15 @@ func runNetworkLoad(cfg *BenchmarkConfig) { cfg.RelayURL, cfg.NetWorkers, cfg.NetRate, cfg.TestDuration, ) // Create a timeout context for benchmark control only, not for connections - timeoutCtx, cancel := context.WithTimeout(context.Background(), cfg.TestDuration) + timeoutCtx, cancel := context.WithTimeout( + context.Background(), cfg.TestDuration, + ) defer cancel() - - // Use a separate background context for relay connections to avoid + + // Use a separate background context for relay connections to avoid // cancelling the server when the benchmark timeout expires connCtx := context.Background() - + var wg sync.WaitGroup if cfg.NetWorkers <= 0 { cfg.NetWorkers = 1 @@ -959,17 +959,15 @@ func (b *Benchmark) generateEvents(count int) []*event.E { events := make([]*event.E, count) now := timestamp.Now() + // Generate a keypair for signing all events + var keys p256k.Signer + if err := keys.Generate(); err != nil { + log.Fatalf("Failed to generate keys for benchmark events: %v", err) + } + for i := 0; i < count; i++ { ev := event.New() - // Generate random 32-byte ID - ev.ID = make([]byte, 32) - rand.Read(ev.ID) - - // Generate random 32-byte pubkey - ev.Pubkey = make([]byte, 32) - rand.Read(ev.Pubkey) - ev.CreatedAt = now.I64() ev.Kind = kind.TextNote.K ev.Content = []byte(fmt.Sprintf( @@ -984,6 +982,11 @@ func (b *Benchmark) generateEvents(count int) []*event.E { ), ) + // Properly sign the event instead of generating fake signatures + if err := ev.Sign(&keys); err != nil { + log.Fatalf("Failed to sign event %d: %v", i, err) + } + events[i] = ev } diff --git a/cmd/benchmark/reports/run_20250920_101521/aggregate_report.txt b/cmd/benchmark/reports/run_20250920_101521/aggregate_report.txt new file mode 100644 index 0000000..1177d92 --- /dev/null +++ b/cmd/benchmark/reports/run_20250920_101521/aggregate_report.txt @@ -0,0 +1,140 @@ +================================================================ +NOSTR RELAY BENCHMARK AGGREGATE REPORT +================================================================ +Generated: 2025-09-20T11:04:39+00:00 +Benchmark Configuration: + Events per test: 10000 + Concurrent workers: 8 + Test duration: 60s + +Relays tested: 6 + +================================================================ +SUMMARY BY RELAY +================================================================ + +Relay: next-orly +---------------------------------------- +Status: COMPLETED +Events/sec: 1035.42 +Events/sec: 659.20 +Events/sec: 1094.56 +Success Rate: 100.0% +Success Rate: 100.0% +Success Rate: 100.0% +Avg Latency: 470.069µs +Bottom 10% Avg Latency: 750.491µs +Avg Latency: 190.573µs +P95 Latency: 693.101µs +P95 Latency: 289.761µs +P95 Latency: 22.450848ms + +Relay: khatru-sqlite +---------------------------------------- +Status: COMPLETED +Events/sec: 1105.61 +Events/sec: 624.87 +Events/sec: 1070.10 +Success Rate: 100.0% +Success Rate: 100.0% +Success Rate: 100.0% +Avg Latency: 458.035µs +Bottom 10% Avg Latency: 702.193µs +Avg Latency: 193.997µs +P95 Latency: 660.608µs +P95 Latency: 302.666µs +P95 Latency: 23.653412ms + +Relay: khatru-badger +---------------------------------------- +Status: COMPLETED +Events/sec: 1040.11 +Events/sec: 663.14 +Events/sec: 1065.58 +Success Rate: 100.0% +Success Rate: 100.0% +Success Rate: 100.0% +Avg Latency: 454.784µs +Bottom 10% Avg Latency: 706.219µs +Avg Latency: 193.914µs +P95 Latency: 654.637µs +P95 Latency: 296.525µs +P95 Latency: 21.642655ms + +Relay: relayer-basic +---------------------------------------- +Status: COMPLETED +Events/sec: 1104.88 +Events/sec: 642.17 +Events/sec: 1079.27 +Success Rate: 100.0% +Success Rate: 100.0% +Success Rate: 100.0% +Avg Latency: 433.89µs +Bottom 10% Avg Latency: 653.813µs +Avg Latency: 186.306µs +P95 Latency: 617.868µs +P95 Latency: 279.192µs +P95 Latency: 21.247322ms + +Relay: strfry +---------------------------------------- +Status: COMPLETED +Events/sec: 1090.49 +Events/sec: 652.03 +Events/sec: 1098.57 +Success Rate: 100.0% +Success Rate: 100.0% +Success Rate: 100.0% +Avg Latency: 448.058µs +Bottom 10% Avg Latency: 729.464µs +Avg Latency: 189.06µs +P95 Latency: 667.141µs +P95 Latency: 290.433µs +P95 Latency: 20.822884ms + +Relay: nostr-rs-relay +---------------------------------------- +Status: COMPLETED +Events/sec: 1123.91 +Events/sec: 647.62 +Events/sec: 1033.64 +Success Rate: 100.0% +Success Rate: 100.0% +Success Rate: 100.0% +Avg Latency: 416.753µs +Bottom 10% Avg Latency: 638.318µs +Avg Latency: 185.217µs +P95 Latency: 597.338µs +P95 Latency: 273.191µs +P95 Latency: 22.416221ms + + +================================================================ +DETAILED RESULTS +================================================================ + +Individual relay reports are available in: + - /reports/run_20250920_101521/khatru-badger_results.txt + - /reports/run_20250920_101521/khatru-sqlite_results.txt + - /reports/run_20250920_101521/next-orly_results.txt + - /reports/run_20250920_101521/nostr-rs-relay_results.txt + - /reports/run_20250920_101521/relayer-basic_results.txt + - /reports/run_20250920_101521/strfry_results.txt + +================================================================ +BENCHMARK COMPARISON TABLE +================================================================ + +Relay Status Peak Tput/s Avg Latency Success Rate +---- ------ ----------- ----------- ------------ +next-orly OK 1035.42 470.069µs 100.0% +khatru-sqlite OK 1105.61 458.035µs 100.0% +khatru-badger OK 1040.11 454.784µs 100.0% +relayer-basic OK 1104.88 433.89µs 100.0% +strfry OK 1090.49 448.058µs 100.0% +nostr-rs-relay OK 1123.91 416.753µs 100.0% + +================================================================ +End of Report +================================================================ diff --git a/cmd/benchmark/reports/run_20250920_101521/khatru-badger_results.txt b/cmd/benchmark/reports/run_20250920_101521/khatru-badger_results.txt new file mode 100644 index 0000000..848b2d6 --- /dev/null +++ b/cmd/benchmark/reports/run_20250920_101521/khatru-badger_results.txt @@ -0,0 +1,298 @@ +Starting Nostr Relay Benchmark +Data Directory: /tmp/benchmark_khatru-badger_8 +Events: 10000, Workers: 8, Duration: 1m0s +1758364309339505ℹ️/tmp/benchmark_khatru-badger_8: All 0 tables opened in 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/levels.go:161 /build/pkg/database/logger.go:57 +1758364309340007ℹ️/tmp/benchmark_khatru-badger_8: Discard stats nextEmptySlot: 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/discard.go:55 /build/pkg/database/logger.go:57 +1758364309340039ℹ️/tmp/benchmark_khatru-badger_8: Set nextTxnTs to 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:358 /build/pkg/database/logger.go:57 +1758364309340327ℹ️(*types.Uint32)(0xc000147840)({ + value: (uint32) 1 +}) + /build/pkg/database/migrations.go:65 +1758364309340465ℹ️migrating to version 1... /build/pkg/database/migrations.go:79 + +=== Starting test round 1/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 9.614321551s +Events/sec: 1040.11 +Avg latency: 454.784µs +P90 latency: 596.266µs +P95 latency: 654.637µs +P99 latency: 844.569µs +Bottom 10% Avg latency: 706.219µs +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 136.444875ms +Burst completed: 1000 events in 141.806497ms +Burst completed: 1000 events in 168.991278ms +Burst completed: 1000 events in 167.713425ms +Burst completed: 1000 events in 162.89698ms +Burst completed: 1000 events in 157.775164ms +Burst completed: 1000 events in 166.476709ms +Burst completed: 1000 events in 161.742632ms +Burst completed: 1000 events in 162.138977ms +Burst completed: 1000 events in 156.657194ms +Burst test completed: 10000 events in 15.07982611s +Events/sec: 663.14 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 5000 reads in 44.903267299s +Combined ops/sec: 222.70 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 3166 queries in 1m0.104195004s +Queries/sec: 52.68 +Avg query latency: 125.847553ms +P95 query latency: 148.109766ms +P99 query latency: 212.054697ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 11366 operations (1366 queries, 10000 writes) in 1m0.127232573s +Operations/sec: 189.03 +Avg latency: 16.671438ms +Avg query latency: 134.993072ms +Avg write latency: 508.703µs +P95 latency: 133.755996ms +P99 latency: 152.790563ms + +Pausing 10s before next round... + +=== Test round completed === + + +=== Starting test round 2/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 9.384548186s +Events/sec: 1065.58 +Avg latency: 566.375µs +P90 latency: 738.377µs +P95 latency: 839.679µs +P99 latency: 1.131084ms +Bottom 10% Avg latency: 1.312791ms +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 166.832259ms +Burst completed: 1000 events in 175.061575ms +Burst completed: 1000 events in 168.897493ms +Burst completed: 1000 events in 167.584171ms +Burst completed: 1000 events in 178.212526ms +Burst completed: 1000 events in 202.208945ms +Burst completed: 1000 events in 154.130024ms +Burst completed: 1000 events in 168.817721ms +Burst completed: 1000 events in 153.032223ms +Burst completed: 1000 events in 154.799008ms +Burst test completed: 10000 events in 15.449161726s +Events/sec: 647.28 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 4582 reads in 1m0.037041762s +Combined ops/sec: 159.60 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 959 queries in 1m0.42440735s +Queries/sec: 15.87 +Avg query latency: 418.846875ms +P95 query latency: 473.089327ms +P99 query latency: 650.467474ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 10484 operations (484 queries, 10000 writes) in 1m0.283590079s +Operations/sec: 173.91 +Avg latency: 17.921964ms +Avg query latency: 381.041592ms +Avg write latency: 346.974µs +P95 latency: 1.269749ms +P99 latency: 399.015222ms + +=== Test round completed === + + +================================================================================ +BENCHMARK REPORT +================================================================================ + +Test: Peak Throughput +Duration: 9.614321551s +Total Events: 10000 +Events/sec: 1040.11 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 118 MB +Avg Latency: 454.784µs +P90 Latency: 596.266µs +P95 Latency: 654.637µs +P99 Latency: 844.569µs +Bottom 10% Avg Latency: 706.219µs +---------------------------------------- + +Test: Burst Pattern +Duration: 15.07982611s +Total Events: 10000 +Events/sec: 663.14 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 162 MB +Avg Latency: 193.914µs +P90 Latency: 255.617µs +P95 Latency: 296.525µs +P99 Latency: 451.81µs +Bottom 10% Avg Latency: 343.222µs +---------------------------------------- + +Test: Mixed Read/Write +Duration: 44.903267299s +Total Events: 10000 +Events/sec: 222.70 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 121 MB +Avg Latency: 9.145633ms +P90 Latency: 19.946513ms +P95 Latency: 21.642655ms +P99 Latency: 23.951572ms +Bottom 10% Avg Latency: 21.861602ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.104195004s +Total Events: 3166 +Events/sec: 52.68 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 188 MB +Avg Latency: 125.847553ms +P90 Latency: 140.664966ms +P95 Latency: 148.109766ms +P99 Latency: 212.054697ms +Bottom 10% Avg Latency: 164.089129ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.127232573s +Total Events: 11366 +Events/sec: 189.03 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 112 MB +Avg Latency: 16.671438ms +P90 Latency: 122.627849ms +P95 Latency: 133.755996ms +P99 Latency: 152.790563ms +Bottom 10% Avg Latency: 138.087104ms +---------------------------------------- + +Test: Peak Throughput +Duration: 9.384548186s +Total Events: 10000 +Events/sec: 1065.58 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 1441 MB +Avg Latency: 566.375µs +P90 Latency: 738.377µs +P95 Latency: 839.679µs +P99 Latency: 1.131084ms +Bottom 10% Avg Latency: 1.312791ms +---------------------------------------- + +Test: Burst Pattern +Duration: 15.449161726s +Total Events: 10000 +Events/sec: 647.28 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 165 MB +Avg Latency: 186.353µs +P90 Latency: 243.413µs +P95 Latency: 283.06µs +P99 Latency: 440.76µs +Bottom 10% Avg Latency: 324.151µs +---------------------------------------- + +Test: Mixed Read/Write +Duration: 1m0.037041762s +Total Events: 9582 +Events/sec: 159.60 +Success Rate: 95.8% +Concurrent Workers: 8 +Memory Used: 138 MB +Avg Latency: 16.358228ms +P90 Latency: 37.654373ms +P95 Latency: 40.578604ms +P99 Latency: 46.331181ms +Bottom 10% Avg Latency: 41.76124ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.42440735s +Total Events: 959 +Events/sec: 15.87 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 110 MB +Avg Latency: 418.846875ms +P90 Latency: 448.809017ms +P95 Latency: 473.089327ms +P99 Latency: 650.467474ms +Bottom 10% Avg Latency: 518.112626ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.283590079s +Total Events: 10484 +Events/sec: 173.91 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 205 MB +Avg Latency: 17.921964ms +P90 Latency: 582.319µs +P95 Latency: 1.269749ms +P99 Latency: 399.015222ms +Bottom 10% Avg Latency: 176.257001ms +---------------------------------------- + +Report saved to: /tmp/benchmark_khatru-badger_8/benchmark_report.txt +AsciiDoc report saved to: /tmp/benchmark_khatru-badger_8/benchmark_report.adoc +1758364794792663ℹ️/tmp/benchmark_khatru-badger_8: Lifetime L0 stalled for: 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:536 /build/pkg/database/logger.go:57 +1758364796617126ℹ️/tmp/benchmark_khatru-badger_8: +Level 0 [ ]: NumTables: 00. Size: 0 B of 0 B. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 64 MiB +Level 1 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 2 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 3 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 4 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 5 [B]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 6 [ ]: NumTables: 04. Size: 87 MiB of 87 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 4.0 MiB +Level Done +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:615 /build/pkg/database/logger.go:57 +1758364796621659ℹ️/tmp/benchmark_khatru-badger_8: database closed /build/pkg/database/database.go:134 + +RELAY_NAME: khatru-badger +RELAY_URL: ws://khatru-badger:3334 +TEST_TIMESTAMP: 2025-09-20T10:39:56+00:00 +BENCHMARK_CONFIG: + Events: 10000 + Workers: 8 + Duration: 60s diff --git a/cmd/benchmark/reports/run_20250920_101521/khatru-sqlite_results.txt b/cmd/benchmark/reports/run_20250920_101521/khatru-sqlite_results.txt new file mode 100644 index 0000000..7e896fa --- /dev/null +++ b/cmd/benchmark/reports/run_20250920_101521/khatru-sqlite_results.txt @@ -0,0 +1,298 @@ +Starting Nostr Relay Benchmark +Data Directory: /tmp/benchmark_khatru-sqlite_8 +Events: 10000, Workers: 8, Duration: 1m0s +1758363814412229ℹ️/tmp/benchmark_khatru-sqlite_8: All 0 tables opened in 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/levels.go:161 /build/pkg/database/logger.go:57 +1758363814412803ℹ️/tmp/benchmark_khatru-sqlite_8: Discard stats nextEmptySlot: 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/discard.go:55 /build/pkg/database/logger.go:57 +1758363814412840ℹ️/tmp/benchmark_khatru-sqlite_8: Set nextTxnTs to 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:358 /build/pkg/database/logger.go:57 +1758363814413123ℹ️(*types.Uint32)(0xc0001ea00c)({ + value: (uint32) 1 +}) + /build/pkg/database/migrations.go:65 +1758363814413200ℹ️migrating to version 1... /build/pkg/database/migrations.go:79 + +=== Starting test round 1/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 9.044789549s +Events/sec: 1105.61 +Avg latency: 458.035µs +P90 latency: 601.736µs +P95 latency: 660.608µs +P99 latency: 844.108µs +Bottom 10% Avg latency: 702.193µs +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 146.610877ms +Burst completed: 1000 events in 179.229665ms +Burst completed: 1000 events in 157.096919ms +Burst completed: 1000 events in 164.796374ms +Burst completed: 1000 events in 188.464354ms +Burst completed: 1000 events in 196.529596ms +Burst completed: 1000 events in 169.425581ms +Burst completed: 1000 events in 147.99354ms +Burst completed: 1000 events in 157.996252ms +Burst completed: 1000 events in 167.299262ms +Burst test completed: 10000 events in 16.003207139s +Events/sec: 624.87 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 5000 reads in 46.924555793s +Combined ops/sec: 213.11 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 3052 queries in 1m0.102264s +Queries/sec: 50.78 +Avg query latency: 128.464192ms +P95 query latency: 148.086431ms +P99 query latency: 219.275394ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 11296 operations (1296 queries, 10000 writes) in 1m0.108871986s +Operations/sec: 187.93 +Avg latency: 16.71621ms +Avg query latency: 142.320434ms +Avg write latency: 437.903µs +P95 latency: 141.357185ms +P99 latency: 163.50992ms + +Pausing 10s before next round... + +=== Test round completed === + + +=== Starting test round 2/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 9.344884331s +Events/sec: 1070.10 +Avg latency: 578.453µs +P90 latency: 742.585µs +P95 latency: 849.679µs +P99 latency: 1.122058ms +Bottom 10% Avg latency: 1.362355ms +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 185.472655ms +Burst completed: 1000 events in 194.135516ms +Burst completed: 1000 events in 176.056931ms +Burst completed: 1000 events in 161.500315ms +Burst completed: 1000 events in 157.673837ms +Burst completed: 1000 events in 167.130208ms +Burst completed: 1000 events in 182.164655ms +Burst completed: 1000 events in 156.589581ms +Burst completed: 1000 events in 154.419949ms +Burst completed: 1000 events in 158.445927ms +Burst test completed: 10000 events in 15.587711126s +Events/sec: 641.53 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 4405 reads in 1m0.043842569s +Combined ops/sec: 156.64 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 915 queries in 1m0.3452177s +Queries/sec: 15.16 +Avg query latency: 435.125142ms +P95 query latency: 520.311963ms +P99 query latency: 618.85899ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 10489 operations (489 queries, 10000 writes) in 1m0.27235761s +Operations/sec: 174.03 +Avg latency: 18.043774ms +Avg query latency: 379.681531ms +Avg write latency: 359.688µs +P95 latency: 1.316628ms +P99 latency: 400.223248ms + +=== Test round completed === + + +================================================================================ +BENCHMARK REPORT +================================================================================ + +Test: Peak Throughput +Duration: 9.044789549s +Total Events: 10000 +Events/sec: 1105.61 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 144 MB +Avg Latency: 458.035µs +P90 Latency: 601.736µs +P95 Latency: 660.608µs +P99 Latency: 844.108µs +Bottom 10% Avg Latency: 702.193µs +---------------------------------------- + +Test: Burst Pattern +Duration: 16.003207139s +Total Events: 10000 +Events/sec: 624.87 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 89 MB +Avg Latency: 193.997µs +P90 Latency: 261.969µs +P95 Latency: 302.666µs +P99 Latency: 431.933µs +Bottom 10% Avg Latency: 334.383µs +---------------------------------------- + +Test: Mixed Read/Write +Duration: 46.924555793s +Total Events: 10000 +Events/sec: 213.11 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 96 MB +Avg Latency: 9.781737ms +P90 Latency: 21.91971ms +P95 Latency: 23.653412ms +P99 Latency: 27.511972ms +Bottom 10% Avg Latency: 24.396695ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.102264s +Total Events: 3052 +Events/sec: 50.78 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 209 MB +Avg Latency: 128.464192ms +P90 Latency: 142.195039ms +P95 Latency: 148.086431ms +P99 Latency: 219.275394ms +Bottom 10% Avg Latency: 162.874217ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.108871986s +Total Events: 11296 +Events/sec: 187.93 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 159 MB +Avg Latency: 16.71621ms +P90 Latency: 127.287246ms +P95 Latency: 141.357185ms +P99 Latency: 163.50992ms +Bottom 10% Avg Latency: 145.199189ms +---------------------------------------- + +Test: Peak Throughput +Duration: 9.344884331s +Total Events: 10000 +Events/sec: 1070.10 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 1441 MB +Avg Latency: 578.453µs +P90 Latency: 742.585µs +P95 Latency: 849.679µs +P99 Latency: 1.122058ms +Bottom 10% Avg Latency: 1.362355ms +---------------------------------------- + +Test: Burst Pattern +Duration: 15.587711126s +Total Events: 10000 +Events/sec: 641.53 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 141 MB +Avg Latency: 190.235µs +P90 Latency: 254.795µs +P95 Latency: 290.563µs +P99 Latency: 437.323µs +Bottom 10% Avg Latency: 328.752µs +---------------------------------------- + +Test: Mixed Read/Write +Duration: 1m0.043842569s +Total Events: 9405 +Events/sec: 156.64 +Success Rate: 94.0% +Concurrent Workers: 8 +Memory Used: 105 MB +Avg Latency: 16.852438ms +P90 Latency: 39.677855ms +P95 Latency: 42.553634ms +P99 Latency: 48.262077ms +Bottom 10% Avg Latency: 43.994063ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.3452177s +Total Events: 915 +Events/sec: 15.16 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 157 MB +Avg Latency: 435.125142ms +P90 Latency: 482.304439ms +P95 Latency: 520.311963ms +P99 Latency: 618.85899ms +Bottom 10% Avg Latency: 545.670939ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.27235761s +Total Events: 10489 +Events/sec: 174.03 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 132 MB +Avg Latency: 18.043774ms +P90 Latency: 583.962µs +P95 Latency: 1.316628ms +P99 Latency: 400.223248ms +Bottom 10% Avg Latency: 177.440946ms +---------------------------------------- + +Report saved to: /tmp/benchmark_khatru-sqlite_8/benchmark_report.txt +AsciiDoc report saved to: /tmp/benchmark_khatru-sqlite_8/benchmark_report.adoc +1758364302230610ℹ️/tmp/benchmark_khatru-sqlite_8: Lifetime L0 stalled for: 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:536 /build/pkg/database/logger.go:57 +1758364304057942ℹ️/tmp/benchmark_khatru-sqlite_8: +Level 0 [ ]: NumTables: 00. Size: 0 B of 0 B. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 64 MiB +Level 1 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 2 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 3 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 4 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 5 [B]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 6 [ ]: NumTables: 04. Size: 87 MiB of 87 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 4.0 MiB +Level Done +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:615 /build/pkg/database/logger.go:57 +1758364304063521ℹ️/tmp/benchmark_khatru-sqlite_8: database closed /build/pkg/database/database.go:134 + +RELAY_NAME: khatru-sqlite +RELAY_URL: ws://khatru-sqlite:3334 +TEST_TIMESTAMP: 2025-09-20T10:31:44+00:00 +BENCHMARK_CONFIG: + Events: 10000 + Workers: 8 + Duration: 60s diff --git a/cmd/benchmark/reports/run_20250920_101521/next-orly_results.txt b/cmd/benchmark/reports/run_20250920_101521/next-orly_results.txt new file mode 100644 index 0000000..9062a9e --- /dev/null +++ b/cmd/benchmark/reports/run_20250920_101521/next-orly_results.txt @@ -0,0 +1,298 @@ +Starting Nostr Relay Benchmark +Data Directory: /tmp/benchmark_next-orly_8 +Events: 10000, Workers: 8, Duration: 1m0s +1758363321263384ℹ️/tmp/benchmark_next-orly_8: All 0 tables opened in 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/levels.go:161 /build/pkg/database/logger.go:57 +1758363321263864ℹ️/tmp/benchmark_next-orly_8: Discard stats nextEmptySlot: 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/discard.go:55 /build/pkg/database/logger.go:57 +1758363321263887ℹ️/tmp/benchmark_next-orly_8: Set nextTxnTs to 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:358 /build/pkg/database/logger.go:57 +1758363321264128ℹ️(*types.Uint32)(0xc0001f7ffc)({ + value: (uint32) 1 +}) + /build/pkg/database/migrations.go:65 +1758363321264177ℹ️migrating to version 1... /build/pkg/database/migrations.go:79 + +=== Starting test round 1/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 9.657904043s +Events/sec: 1035.42 +Avg latency: 470.069µs +P90 latency: 628.167µs +P95 latency: 693.101µs +P99 latency: 922.357µs +Bottom 10% Avg latency: 750.491µs +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 175.034134ms +Burst completed: 1000 events in 150.401771ms +Burst completed: 1000 events in 168.992305ms +Burst completed: 1000 events in 179.447581ms +Burst completed: 1000 events in 165.602457ms +Burst completed: 1000 events in 178.649561ms +Burst completed: 1000 events in 195.002303ms +Burst completed: 1000 events in 168.970954ms +Burst completed: 1000 events in 150.818413ms +Burst completed: 1000 events in 185.285662ms +Burst test completed: 10000 events in 15.169978801s +Events/sec: 659.20 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 5000 reads in 45.597478865s +Combined ops/sec: 219.31 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 3151 queries in 1m0.067849757s +Queries/sec: 52.46 +Avg query latency: 126.38548ms +P95 query latency: 149.976367ms +P99 query latency: 205.807461ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 11325 operations (1325 queries, 10000 writes) in 1m0.081967157s +Operations/sec: 188.49 +Avg latency: 16.694154ms +Avg query latency: 139.524748ms +Avg write latency: 419.1µs +P95 latency: 138.688202ms +P99 latency: 158.824742ms + +Pausing 10s before next round... + +=== Test round completed === + + +=== Starting test round 2/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 9.136097148s +Events/sec: 1094.56 +Avg latency: 510.7µs +P90 latency: 636.763µs +P95 latency: 705.564µs +P99 latency: 922.777µs +Bottom 10% Avg latency: 1.094965ms +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 176.337148ms +Burst completed: 1000 events in 177.351251ms +Burst completed: 1000 events in 181.515292ms +Burst completed: 1000 events in 164.043866ms +Burst completed: 1000 events in 152.697196ms +Burst completed: 1000 events in 144.231922ms +Burst completed: 1000 events in 162.606659ms +Burst completed: 1000 events in 137.485182ms +Burst completed: 1000 events in 163.19487ms +Burst completed: 1000 events in 147.900339ms +Burst test completed: 10000 events in 15.514130113s +Events/sec: 644.57 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 4489 reads in 1m0.036174989s +Combined ops/sec: 158.05 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 900 queries in 1m0.304636826s +Queries/sec: 14.92 +Avg query latency: 444.57989ms +P95 query latency: 547.598358ms +P99 query latency: 660.926147ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 10462 operations (462 queries, 10000 writes) in 1m0.362856212s +Operations/sec: 173.32 +Avg latency: 17.808607ms +Avg query latency: 395.594177ms +Avg write latency: 354.914µs +P95 latency: 1.221657ms +P99 latency: 411.642669ms + +=== Test round completed === + + +================================================================================ +BENCHMARK REPORT +================================================================================ + +Test: Peak Throughput +Duration: 9.657904043s +Total Events: 10000 +Events/sec: 1035.42 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 144 MB +Avg Latency: 470.069µs +P90 Latency: 628.167µs +P95 Latency: 693.101µs +P99 Latency: 922.357µs +Bottom 10% Avg Latency: 750.491µs +---------------------------------------- + +Test: Burst Pattern +Duration: 15.169978801s +Total Events: 10000 +Events/sec: 659.20 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 135 MB +Avg Latency: 190.573µs +P90 Latency: 252.701µs +P95 Latency: 289.761µs +P99 Latency: 408.147µs +Bottom 10% Avg Latency: 316.797µs +---------------------------------------- + +Test: Mixed Read/Write +Duration: 45.597478865s +Total Events: 10000 +Events/sec: 219.31 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 119 MB +Avg Latency: 9.381158ms +P90 Latency: 20.487026ms +P95 Latency: 22.450848ms +P99 Latency: 24.696325ms +Bottom 10% Avg Latency: 22.632933ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.067849757s +Total Events: 3151 +Events/sec: 52.46 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 145 MB +Avg Latency: 126.38548ms +P90 Latency: 142.39268ms +P95 Latency: 149.976367ms +P99 Latency: 205.807461ms +Bottom 10% Avg Latency: 162.636454ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.081967157s +Total Events: 11325 +Events/sec: 188.49 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 194 MB +Avg Latency: 16.694154ms +P90 Latency: 125.314618ms +P95 Latency: 138.688202ms +P99 Latency: 158.824742ms +Bottom 10% Avg Latency: 142.699977ms +---------------------------------------- + +Test: Peak Throughput +Duration: 9.136097148s +Total Events: 10000 +Events/sec: 1094.56 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 1441 MB +Avg Latency: 510.7µs +P90 Latency: 636.763µs +P95 Latency: 705.564µs +P99 Latency: 922.777µs +Bottom 10% Avg Latency: 1.094965ms +---------------------------------------- + +Test: Burst Pattern +Duration: 15.514130113s +Total Events: 10000 +Events/sec: 644.57 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 138 MB +Avg Latency: 230.062µs +P90 Latency: 316.624µs +P95 Latency: 389.882µs +P99 Latency: 859.548µs +Bottom 10% Avg Latency: 529.836µs +---------------------------------------- + +Test: Mixed Read/Write +Duration: 1m0.036174989s +Total Events: 9489 +Events/sec: 158.05 +Success Rate: 94.9% +Concurrent Workers: 8 +Memory Used: 182 MB +Avg Latency: 16.56372ms +P90 Latency: 38.24931ms +P95 Latency: 41.187306ms +P99 Latency: 46.02529ms +Bottom 10% Avg Latency: 42.131189ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.304636826s +Total Events: 900 +Events/sec: 14.92 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 141 MB +Avg Latency: 444.57989ms +P90 Latency: 490.730651ms +P95 Latency: 547.598358ms +P99 Latency: 660.926147ms +Bottom 10% Avg Latency: 563.628707ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.362856212s +Total Events: 10462 +Events/sec: 173.32 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 152 MB +Avg Latency: 17.808607ms +P90 Latency: 631.703µs +P95 Latency: 1.221657ms +P99 Latency: 411.642669ms +Bottom 10% Avg Latency: 175.052418ms +---------------------------------------- + +Report saved to: /tmp/benchmark_next-orly_8/benchmark_report.txt +AsciiDoc report saved to: /tmp/benchmark_next-orly_8/benchmark_report.adoc +1758363807245770ℹ️/tmp/benchmark_next-orly_8: Lifetime L0 stalled for: 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:536 /build/pkg/database/logger.go:57 +1758363809118416ℹ️/tmp/benchmark_next-orly_8: +Level 0 [ ]: NumTables: 00. Size: 0 B of 0 B. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 64 MiB +Level 1 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 2 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 3 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 4 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 5 [B]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 6 [ ]: NumTables: 04. Size: 87 MiB of 87 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 4.0 MiB +Level Done +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:615 /build/pkg/database/logger.go:57 +1758363809123697ℹ️/tmp/benchmark_next-orly_8: database closed /build/pkg/database/database.go:134 + +RELAY_NAME: next-orly +RELAY_URL: ws://next-orly:8080 +TEST_TIMESTAMP: 2025-09-20T10:23:29+00:00 +BENCHMARK_CONFIG: + Events: 10000 + Workers: 8 + Duration: 60s diff --git a/cmd/benchmark/reports/run_20250920_101521/nostr-rs-relay_results.txt b/cmd/benchmark/reports/run_20250920_101521/nostr-rs-relay_results.txt new file mode 100644 index 0000000..2679a09 --- /dev/null +++ b/cmd/benchmark/reports/run_20250920_101521/nostr-rs-relay_results.txt @@ -0,0 +1,298 @@ +Starting Nostr Relay Benchmark +Data Directory: /tmp/benchmark_nostr-rs-relay_8 +Events: 10000, Workers: 8, Duration: 1m0s +1758365785928076ℹ️/tmp/benchmark_nostr-rs-relay_8: All 0 tables opened in 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/levels.go:161 /build/pkg/database/logger.go:57 +1758365785929028ℹ️/tmp/benchmark_nostr-rs-relay_8: Discard stats nextEmptySlot: 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/discard.go:55 /build/pkg/database/logger.go:57 +1758365785929097ℹ️/tmp/benchmark_nostr-rs-relay_8: Set nextTxnTs to 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:358 /build/pkg/database/logger.go:57 +1758365785929509ℹ️(*types.Uint32)(0xc0001c820c)({ + value: (uint32) 1 +}) + /build/pkg/database/migrations.go:65 +1758365785929573ℹ️migrating to version 1... /build/pkg/database/migrations.go:79 + +=== Starting test round 1/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 8.897492256s +Events/sec: 1123.91 +Avg latency: 416.753µs +P90 latency: 546.351µs +P95 latency: 597.338µs +P99 latency: 760.549µs +Bottom 10% Avg latency: 638.318µs +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 158.263016ms +Burst completed: 1000 events in 181.558983ms +Burst completed: 1000 events in 155.219861ms +Burst completed: 1000 events in 183.834156ms +Burst completed: 1000 events in 192.398437ms +Burst completed: 1000 events in 176.450074ms +Burst completed: 1000 events in 175.050138ms +Burst completed: 1000 events in 178.883047ms +Burst completed: 1000 events in 180.74321ms +Burst completed: 1000 events in 169.39146ms +Burst test completed: 10000 events in 15.441062872s +Events/sec: 647.62 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 5000 reads in 45.847091984s +Combined ops/sec: 218.12 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 3229 queries in 1m0.085047549s +Queries/sec: 53.74 +Avg query latency: 123.209617ms +P95 query latency: 141.745618ms +P99 query latency: 154.527843ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 11298 operations (1298 queries, 10000 writes) in 1m0.096751583s +Operations/sec: 188.00 +Avg latency: 16.447175ms +Avg query latency: 139.791065ms +Avg write latency: 437.138µs +P95 latency: 137.879538ms +P99 latency: 162.020385ms + +Pausing 10s before next round... + +=== Test round completed === + + +=== Starting test round 2/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 9.674593819s +Events/sec: 1033.64 +Avg latency: 541.545µs +P90 latency: 693.862µs +P95 latency: 775.757µs +P99 latency: 1.05005ms +Bottom 10% Avg latency: 1.219386ms +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 168.056064ms +Burst completed: 1000 events in 159.819647ms +Burst completed: 1000 events in 147.500264ms +Burst completed: 1000 events in 159.150392ms +Burst completed: 1000 events in 149.954829ms +Burst completed: 1000 events in 138.082938ms +Burst completed: 1000 events in 157.234213ms +Burst completed: 1000 events in 158.468955ms +Burst completed: 1000 events in 144.346047ms +Burst completed: 1000 events in 154.930576ms +Burst test completed: 10000 events in 15.646785427s +Events/sec: 639.11 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 4415 reads in 1m0.02899167s +Combined ops/sec: 156.84 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 890 queries in 1m0.279192867s +Queries/sec: 14.76 +Avg query latency: 448.809547ms +P95 query latency: 607.28509ms +P99 query latency: 786.387053ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 10469 operations (469 queries, 10000 writes) in 1m0.190785048s +Operations/sec: 173.93 +Avg latency: 17.73903ms +Avg query latency: 388.59336ms +Avg write latency: 345.962µs +P95 latency: 1.158136ms +P99 latency: 407.947907ms + +=== Test round completed === + + +================================================================================ +BENCHMARK REPORT +================================================================================ + +Test: Peak Throughput +Duration: 8.897492256s +Total Events: 10000 +Events/sec: 1123.91 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 132 MB +Avg Latency: 416.753µs +P90 Latency: 546.351µs +P95 Latency: 597.338µs +P99 Latency: 760.549µs +Bottom 10% Avg Latency: 638.318µs +---------------------------------------- + +Test: Burst Pattern +Duration: 15.441062872s +Total Events: 10000 +Events/sec: 647.62 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 104 MB +Avg Latency: 185.217µs +P90 Latency: 241.64µs +P95 Latency: 273.191µs +P99 Latency: 412.897µs +Bottom 10% Avg Latency: 306.752µs +---------------------------------------- + +Test: Mixed Read/Write +Duration: 45.847091984s +Total Events: 10000 +Events/sec: 218.12 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 96 MB +Avg Latency: 9.446215ms +P90 Latency: 20.522135ms +P95 Latency: 22.416221ms +P99 Latency: 24.696283ms +Bottom 10% Avg Latency: 22.59535ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.085047549s +Total Events: 3229 +Events/sec: 53.74 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 175 MB +Avg Latency: 123.209617ms +P90 Latency: 137.629898ms +P95 Latency: 141.745618ms +P99 Latency: 154.527843ms +Bottom 10% Avg Latency: 145.245967ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.096751583s +Total Events: 11298 +Events/sec: 188.00 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 181 MB +Avg Latency: 16.447175ms +P90 Latency: 123.920421ms +P95 Latency: 137.879538ms +P99 Latency: 162.020385ms +Bottom 10% Avg Latency: 142.654147ms +---------------------------------------- + +Test: Peak Throughput +Duration: 9.674593819s +Total Events: 10000 +Events/sec: 1033.64 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 1441 MB +Avg Latency: 541.545µs +P90 Latency: 693.862µs +P95 Latency: 775.757µs +P99 Latency: 1.05005ms +Bottom 10% Avg Latency: 1.219386ms +---------------------------------------- + +Test: Burst Pattern +Duration: 15.646785427s +Total Events: 10000 +Events/sec: 639.11 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 146 MB +Avg Latency: 331.896µs +P90 Latency: 520.511µs +P95 Latency: 864.486µs +P99 Latency: 2.251087ms +Bottom 10% Avg Latency: 1.16922ms +---------------------------------------- + +Test: Mixed Read/Write +Duration: 1m0.02899167s +Total Events: 9415 +Events/sec: 156.84 +Success Rate: 94.2% +Concurrent Workers: 8 +Memory Used: 147 MB +Avg Latency: 16.723365ms +P90 Latency: 39.058801ms +P95 Latency: 41.904891ms +P99 Latency: 47.156263ms +Bottom 10% Avg Latency: 42.800456ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.279192867s +Total Events: 890 +Events/sec: 14.76 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 156 MB +Avg Latency: 448.809547ms +P90 Latency: 524.488485ms +P95 Latency: 607.28509ms +P99 Latency: 786.387053ms +Bottom 10% Avg Latency: 634.016595ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.190785048s +Total Events: 10469 +Events/sec: 173.93 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 226 MB +Avg Latency: 17.73903ms +P90 Latency: 561.359µs +P95 Latency: 1.158136ms +P99 Latency: 407.947907ms +Bottom 10% Avg Latency: 174.508065ms +---------------------------------------- + +Report saved to: /tmp/benchmark_nostr-rs-relay_8/benchmark_report.txt +AsciiDoc report saved to: /tmp/benchmark_nostr-rs-relay_8/benchmark_report.adoc +1758366272164052ℹ️/tmp/benchmark_nostr-rs-relay_8: Lifetime L0 stalled for: 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:536 /build/pkg/database/logger.go:57 +1758366274030399ℹ️/tmp/benchmark_nostr-rs-relay_8: +Level 0 [ ]: NumTables: 00. Size: 0 B of 0 B. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 64 MiB +Level 1 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 2 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 3 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 4 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 5 [B]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 6 [ ]: NumTables: 04. Size: 87 MiB of 87 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 4.0 MiB +Level Done +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:615 /build/pkg/database/logger.go:57 +1758366274036413ℹ️/tmp/benchmark_nostr-rs-relay_8: database closed /build/pkg/database/database.go:134 + +RELAY_NAME: nostr-rs-relay +RELAY_URL: ws://nostr-rs-relay:8080 +TEST_TIMESTAMP: 2025-09-20T11:04:34+00:00 +BENCHMARK_CONFIG: + Events: 10000 + Workers: 8 + Duration: 60s diff --git a/cmd/benchmark/reports/run_20250920_101521/relayer-basic_results.txt b/cmd/benchmark/reports/run_20250920_101521/relayer-basic_results.txt new file mode 100644 index 0000000..507d005 --- /dev/null +++ b/cmd/benchmark/reports/run_20250920_101521/relayer-basic_results.txt @@ -0,0 +1,298 @@ +Starting Nostr Relay Benchmark +Data Directory: /tmp/benchmark_relayer-basic_8 +Events: 10000, Workers: 8, Duration: 1m0s +1758364801895559ℹ️/tmp/benchmark_relayer-basic_8: All 0 tables opened in 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/levels.go:161 /build/pkg/database/logger.go:57 +1758364801896041ℹ️/tmp/benchmark_relayer-basic_8: Discard stats nextEmptySlot: 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/discard.go:55 /build/pkg/database/logger.go:57 +1758364801896078ℹ️/tmp/benchmark_relayer-basic_8: Set nextTxnTs to 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:358 /build/pkg/database/logger.go:57 +1758364801896347ℹ️(*types.Uint32)(0xc0001a801c)({ + value: (uint32) 1 +}) + /build/pkg/database/migrations.go:65 +1758364801896400ℹ️migrating to version 1... /build/pkg/database/migrations.go:79 + +=== Starting test round 1/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 9.050770003s +Events/sec: 1104.88 +Avg latency: 433.89µs +P90 latency: 567.261µs +P95 latency: 617.868µs +P99 latency: 783.593µs +Bottom 10% Avg latency: 653.813µs +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 183.738134ms +Burst completed: 1000 events in 155.035832ms +Burst completed: 1000 events in 160.066514ms +Burst completed: 1000 events in 183.724238ms +Burst completed: 1000 events in 178.910929ms +Burst completed: 1000 events in 168.905441ms +Burst completed: 1000 events in 172.584809ms +Burst completed: 1000 events in 177.214508ms +Burst completed: 1000 events in 169.921566ms +Burst completed: 1000 events in 162.042488ms +Burst test completed: 10000 events in 15.572250139s +Events/sec: 642.17 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 5000 reads in 44.509677166s +Combined ops/sec: 224.67 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 3253 queries in 1m0.095238426s +Queries/sec: 54.13 +Avg query latency: 122.100718ms +P95 query latency: 140.360749ms +P99 query latency: 148.353154ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 11408 operations (1408 queries, 10000 writes) in 1m0.117581615s +Operations/sec: 189.76 +Avg latency: 16.525268ms +Avg query latency: 130.972853ms +Avg write latency: 411.048µs +P95 latency: 132.130964ms +P99 latency: 146.285305ms + +Pausing 10s before next round... + +=== Test round completed === + + +=== Starting test round 2/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 9.265496879s +Events/sec: 1079.27 +Avg latency: 529.266µs +P90 latency: 658.033µs +P95 latency: 732.024µs +P99 latency: 953.285µs +Bottom 10% Avg latency: 1.168714ms +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 172.300479ms +Burst completed: 1000 events in 149.247397ms +Burst completed: 1000 events in 170.000198ms +Burst completed: 1000 events in 133.786958ms +Burst completed: 1000 events in 172.157036ms +Burst completed: 1000 events in 153.284738ms +Burst completed: 1000 events in 166.711903ms +Burst completed: 1000 events in 170.635427ms +Burst completed: 1000 events in 153.381031ms +Burst completed: 1000 events in 162.125949ms +Burst test completed: 10000 events in 16.674963543s +Events/sec: 599.70 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 4665 reads in 1m0.035358264s +Combined ops/sec: 160.99 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 944 queries in 1m0.383519958s +Queries/sec: 15.63 +Avg query latency: 421.75292ms +P95 query latency: 491.340259ms +P99 query latency: 664.614262ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 10479 operations (479 queries, 10000 writes) in 1m0.291926697s +Operations/sec: 173.80 +Avg latency: 18.049265ms +Avg query latency: 385.864458ms +Avg write latency: 430.918µs +P95 latency: 3.05038ms +P99 latency: 404.540502ms + +=== Test round completed === + + +================================================================================ +BENCHMARK REPORT +================================================================================ + +Test: Peak Throughput +Duration: 9.050770003s +Total Events: 10000 +Events/sec: 1104.88 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 153 MB +Avg Latency: 433.89µs +P90 Latency: 567.261µs +P95 Latency: 617.868µs +P99 Latency: 783.593µs +Bottom 10% Avg Latency: 653.813µs +---------------------------------------- + +Test: Burst Pattern +Duration: 15.572250139s +Total Events: 10000 +Events/sec: 642.17 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 134 MB +Avg Latency: 186.306µs +P90 Latency: 243.995µs +P95 Latency: 279.192µs +P99 Latency: 392.859µs +Bottom 10% Avg Latency: 303.766µs +---------------------------------------- + +Test: Mixed Read/Write +Duration: 44.509677166s +Total Events: 10000 +Events/sec: 224.67 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 163 MB +Avg Latency: 8.892738ms +P90 Latency: 19.406836ms +P95 Latency: 21.247322ms +P99 Latency: 23.452072ms +Bottom 10% Avg Latency: 21.397913ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.095238426s +Total Events: 3253 +Events/sec: 54.13 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 126 MB +Avg Latency: 122.100718ms +P90 Latency: 136.523661ms +P95 Latency: 140.360749ms +P99 Latency: 148.353154ms +Bottom 10% Avg Latency: 142.067372ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.117581615s +Total Events: 11408 +Events/sec: 189.76 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 149 MB +Avg Latency: 16.525268ms +P90 Latency: 121.696848ms +P95 Latency: 132.130964ms +P99 Latency: 146.285305ms +Bottom 10% Avg Latency: 134.054744ms +---------------------------------------- + +Test: Peak Throughput +Duration: 9.265496879s +Total Events: 10000 +Events/sec: 1079.27 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 1441 MB +Avg Latency: 529.266µs +P90 Latency: 658.033µs +P95 Latency: 732.024µs +P99 Latency: 953.285µs +Bottom 10% Avg Latency: 1.168714ms +---------------------------------------- + +Test: Burst Pattern +Duration: 16.674963543s +Total Events: 10000 +Events/sec: 599.70 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 142 MB +Avg Latency: 264.288µs +P90 Latency: 350.187µs +P95 Latency: 519.139µs +P99 Latency: 1.961326ms +Bottom 10% Avg Latency: 877.366µs +---------------------------------------- + +Test: Mixed Read/Write +Duration: 1m0.035358264s +Total Events: 9665 +Events/sec: 160.99 +Success Rate: 96.7% +Concurrent Workers: 8 +Memory Used: 151 MB +Avg Latency: 16.019245ms +P90 Latency: 36.340362ms +P95 Latency: 39.113864ms +P99 Latency: 44.271098ms +Bottom 10% Avg Latency: 40.108462ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.383519958s +Total Events: 944 +Events/sec: 15.63 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 280 MB +Avg Latency: 421.75292ms +P90 Latency: 460.902551ms +P95 Latency: 491.340259ms +P99 Latency: 664.614262ms +Bottom 10% Avg Latency: 538.014725ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.291926697s +Total Events: 10479 +Events/sec: 173.80 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 122 MB +Avg Latency: 18.049265ms +P90 Latency: 843.867µs +P95 Latency: 3.05038ms +P99 Latency: 404.540502ms +Bottom 10% Avg Latency: 177.245211ms +---------------------------------------- + +Report saved to: /tmp/benchmark_relayer-basic_8/benchmark_report.txt +AsciiDoc report saved to: /tmp/benchmark_relayer-basic_8/benchmark_report.adoc +1758365287933287ℹ️/tmp/benchmark_relayer-basic_8: Lifetime L0 stalled for: 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:536 /build/pkg/database/logger.go:57 +1758365289807797ℹ️/tmp/benchmark_relayer-basic_8: +Level 0 [ ]: NumTables: 00. Size: 0 B of 0 B. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 64 MiB +Level 1 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 2 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 3 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 4 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 5 [B]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 6 [ ]: NumTables: 04. Size: 87 MiB of 87 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 4.0 MiB +Level Done +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:615 /build/pkg/database/logger.go:57 +1758365289812921ℹ️/tmp/benchmark_relayer-basic_8: database closed /build/pkg/database/database.go:134 + +RELAY_NAME: relayer-basic +RELAY_URL: ws://relayer-basic:7447 +TEST_TIMESTAMP: 2025-09-20T10:48:10+00:00 +BENCHMARK_CONFIG: + Events: 10000 + Workers: 8 + Duration: 60s diff --git a/cmd/benchmark/reports/run_20250920_101521/strfry_results.txt b/cmd/benchmark/reports/run_20250920_101521/strfry_results.txt new file mode 100644 index 0000000..c48fbea --- /dev/null +++ b/cmd/benchmark/reports/run_20250920_101521/strfry_results.txt @@ -0,0 +1,298 @@ +Starting Nostr Relay Benchmark +Data Directory: /tmp/benchmark_strfry_8 +Events: 10000, Workers: 8, Duration: 1m0s +1758365295110579ℹ️/tmp/benchmark_strfry_8: All 0 tables opened in 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/levels.go:161 /build/pkg/database/logger.go:57 +1758365295111085ℹ️/tmp/benchmark_strfry_8: Discard stats nextEmptySlot: 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/discard.go:55 /build/pkg/database/logger.go:57 +1758365295111113ℹ️/tmp/benchmark_strfry_8: Set nextTxnTs to 0 +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:358 /build/pkg/database/logger.go:57 +1758365295111319ℹ️(*types.Uint32)(0xc000141a3c)({ + value: (uint32) 1 +}) + /build/pkg/database/migrations.go:65 +1758365295111354ℹ️migrating to version 1... /build/pkg/database/migrations.go:79 + +=== Starting test round 1/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 9.170212358s +Events/sec: 1090.49 +Avg latency: 448.058µs +P90 latency: 597.558µs +P95 latency: 667.141µs +P99 latency: 920.784µs +Bottom 10% Avg latency: 729.464µs +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 172.138862ms +Burst completed: 1000 events in 168.99322ms +Burst completed: 1000 events in 162.213786ms +Burst completed: 1000 events in 161.027417ms +Burst completed: 1000 events in 183.148824ms +Burst completed: 1000 events in 178.152837ms +Burst completed: 1000 events in 158.65623ms +Burst completed: 1000 events in 186.7166ms +Burst completed: 1000 events in 177.202878ms +Burst completed: 1000 events in 182.780071ms +Burst test completed: 10000 events in 15.336760896s +Events/sec: 652.03 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 5000 reads in 44.257468151s +Combined ops/sec: 225.95 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 3002 queries in 1m0.091429487s +Queries/sec: 49.96 +Avg query latency: 131.632043ms +P95 query latency: 175.810416ms +P99 query latency: 228.52716ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 11308 operations (1308 queries, 10000 writes) in 1m0.111257202s +Operations/sec: 188.12 +Avg latency: 16.193707ms +Avg query latency: 137.019852ms +Avg write latency: 389.647µs +P95 latency: 136.70132ms +P99 latency: 156.996779ms + +Pausing 10s before next round... + +=== Test round completed === + + +=== Starting test round 2/2 === +RunPeakThroughputTest.. + +=== Peak Throughput Test === +Events saved: 10000/10000 (100.0%) +Duration: 9.102738s +Events/sec: 1098.57 +Avg latency: 493.093µs +P90 latency: 605.684µs +P95 latency: 659.477µs +P99 latency: 826.344µs +Bottom 10% Avg latency: 1.097884ms +RunBurstPatternTest.. + +=== Burst Pattern Test === +Burst completed: 1000 events in 178.755916ms +Burst completed: 1000 events in 170.810722ms +Burst completed: 1000 events in 166.730701ms +Burst completed: 1000 events in 172.177576ms +Burst completed: 1000 events in 164.907178ms +Burst completed: 1000 events in 153.267727ms +Burst completed: 1000 events in 157.855743ms +Burst completed: 1000 events in 159.632496ms +Burst completed: 1000 events in 160.802526ms +Burst completed: 1000 events in 178.513954ms +Burst test completed: 10000 events in 15.535933443s +Events/sec: 643.67 +RunMixedReadWriteTest.. + +=== Mixed Read/Write Test === +Pre-populating database for read tests... +Mixed test completed: 5000 writes, 4550 reads in 1m0.032080518s +Combined ops/sec: 159.08 +RunQueryTest.. + +=== Query Test === +Pre-populating database with 10000 events for query tests... +Query test completed: 913 queries in 1m0.248877091s +Queries/sec: 15.15 +Avg query latency: 436.472206ms +P95 query latency: 493.12732ms +P99 query latency: 623.201275ms +RunConcurrentQueryStoreTest.. + +=== Concurrent Query/Store Test === +Pre-populating database with 5000 events for concurrent query/store test... +Concurrent test completed: 10470 operations (470 queries, 10000 writes) in 1m0.293280495s +Operations/sec: 173.65 +Avg latency: 18.084009ms +Avg query latency: 395.171481ms +Avg write latency: 360.898µs +P95 latency: 1.338148ms +P99 latency: 413.21015ms + +=== Test round completed === + + +================================================================================ +BENCHMARK REPORT +================================================================================ + +Test: Peak Throughput +Duration: 9.170212358s +Total Events: 10000 +Events/sec: 1090.49 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 108 MB +Avg Latency: 448.058µs +P90 Latency: 597.558µs +P95 Latency: 667.141µs +P99 Latency: 920.784µs +Bottom 10% Avg Latency: 729.464µs +---------------------------------------- + +Test: Burst Pattern +Duration: 15.336760896s +Total Events: 10000 +Events/sec: 652.03 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 123 MB +Avg Latency: 189.06µs +P90 Latency: 248.714µs +P95 Latency: 290.433µs +P99 Latency: 416.924µs +Bottom 10% Avg Latency: 324.174µs +---------------------------------------- + +Test: Mixed Read/Write +Duration: 44.257468151s +Total Events: 10000 +Events/sec: 225.95 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 158 MB +Avg Latency: 8.745534ms +P90 Latency: 18.980294ms +P95 Latency: 20.822884ms +P99 Latency: 23.124918ms +Bottom 10% Avg Latency: 21.006886ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.091429487s +Total Events: 3002 +Events/sec: 49.96 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 191 MB +Avg Latency: 131.632043ms +P90 Latency: 152.618309ms +P95 Latency: 175.810416ms +P99 Latency: 228.52716ms +Bottom 10% Avg Latency: 186.230874ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.111257202s +Total Events: 11308 +Events/sec: 188.12 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 146 MB +Avg Latency: 16.193707ms +P90 Latency: 122.204256ms +P95 Latency: 136.70132ms +P99 Latency: 156.996779ms +Bottom 10% Avg Latency: 140.031139ms +---------------------------------------- + +Test: Peak Throughput +Duration: 9.102738s +Total Events: 10000 +Events/sec: 1098.57 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 1441 MB +Avg Latency: 493.093µs +P90 Latency: 605.684µs +P95 Latency: 659.477µs +P99 Latency: 826.344µs +Bottom 10% Avg Latency: 1.097884ms +---------------------------------------- + +Test: Burst Pattern +Duration: 15.535933443s +Total Events: 10000 +Events/sec: 643.67 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 130 MB +Avg Latency: 186.177µs +P90 Latency: 243.915µs +P95 Latency: 276.146µs +P99 Latency: 418.787µs +Bottom 10% Avg Latency: 309.015µs +---------------------------------------- + +Test: Mixed Read/Write +Duration: 1m0.032080518s +Total Events: 9550 +Events/sec: 159.08 +Success Rate: 95.5% +Concurrent Workers: 8 +Memory Used: 115 MB +Avg Latency: 16.401942ms +P90 Latency: 37.575878ms +P95 Latency: 40.323279ms +P99 Latency: 45.453669ms +Bottom 10% Avg Latency: 41.331235ms +---------------------------------------- + +Test: Query Performance +Duration: 1m0.248877091s +Total Events: 913 +Events/sec: 15.15 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 211 MB +Avg Latency: 436.472206ms +P90 Latency: 474.430346ms +P95 Latency: 493.12732ms +P99 Latency: 623.201275ms +Bottom 10% Avg Latency: 523.084076ms +---------------------------------------- + +Test: Concurrent Query/Store +Duration: 1m0.293280495s +Total Events: 10470 +Events/sec: 173.65 +Success Rate: 100.0% +Concurrent Workers: 8 +Memory Used: 171 MB +Avg Latency: 18.084009ms +P90 Latency: 624.339µs +P95 Latency: 1.338148ms +P99 Latency: 413.21015ms +Bottom 10% Avg Latency: 177.8924ms +---------------------------------------- + +Report saved to: /tmp/benchmark_strfry_8/benchmark_report.txt +AsciiDoc report saved to: /tmp/benchmark_strfry_8/benchmark_report.adoc +1758365779337138ℹ️/tmp/benchmark_strfry_8: Lifetime L0 stalled for: 0s +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:536 /build/pkg/database/logger.go:57 +1758365780726692ℹ️/tmp/benchmark_strfry_8: +Level 0 [ ]: NumTables: 00. Size: 0 B of 0 B. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 64 MiB +Level 1 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 2 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 3 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 4 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 5 [B]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB +Level 6 [ ]: NumTables: 04. Size: 87 MiB of 87 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 4.0 MiB +Level Done +/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:615 /build/pkg/database/logger.go:57 +1758365780732292ℹ️/tmp/benchmark_strfry_8: database closed /build/pkg/database/database.go:134 + +RELAY_NAME: strfry +RELAY_URL: ws://strfry:8080 +TEST_TIMESTAMP: 2025-09-20T10:56:20+00:00 +BENCHMARK_CONFIG: + Events: 10000 + Workers: 8 + Duration: 60s diff --git a/pkg/database/fetch-event-by-serial.go b/pkg/database/fetch-event-by-serial.go index 467fd93..d8daed0 100644 --- a/pkg/database/fetch-event-by-serial.go +++ b/pkg/database/fetch-event-by-serial.go @@ -2,6 +2,7 @@ package database import ( "bytes" + "fmt" "github.com/dgraph-io/badger/v4" "lol.mleku.dev/chk" @@ -25,8 +26,23 @@ func (d *D) FetchEventBySerial(ser *types.Uint40) (ev *event.E, err error) { if v, err = item.ValueCopy(nil); chk.E(err) { return } + // Check if we have valid data before attempting to unmarshal + if len(v) < 32+32+1+2+1+1+64 { // ID + Pubkey + min varint fields + Sig + err = fmt.Errorf( + "incomplete event data: got %d bytes, expected at least %d", + len(v), 32+32+1+2+1+1+64, + ) + return + } ev = new(event.E) - if err = ev.UnmarshalBinary(bytes.NewBuffer(v)); chk.E(err) { + if err = ev.UnmarshalBinary(bytes.NewBuffer(v)); err != nil { + // Add more context to EOF errors for debugging + if err.Error() == "EOF" { + err = fmt.Errorf( + "EOF while unmarshaling event (serial=%v, data_len=%d): %w", + ser, len(v), err, + ) + } return } return diff --git a/pkg/database/fetch-events-by-serials.go b/pkg/database/fetch-events-by-serials.go index aab0e2e..6b363d0 100644 --- a/pkg/database/fetch-events-by-serials.go +++ b/pkg/database/fetch-events-by-serials.go @@ -2,105 +2,67 @@ package database import ( "bytes" - "sort" - "strconv" "github.com/dgraph-io/badger/v4" "lol.mleku.dev/chk" - "lol.mleku.dev/log" "next.orly.dev/pkg/database/indexes" "next.orly.dev/pkg/database/indexes/types" "next.orly.dev/pkg/encoders/event" ) -// FetchEventsBySerials processes multiple serials in ascending order and retrieves -// the corresponding events from the database. It optimizes database access by -// sorting the serials and seeking to each one sequentially. -func (d *D) FetchEventsBySerials(serials []*types.Uint40) ( - evMap map[string]*event.E, err error, -) { - log.T.F("FetchEventsBySerials: processing %d serials", len(serials)) - - // Initialize the result map - evMap = make(map[string]*event.E) - - // Return early if no serials are provided +// FetchEventsBySerials fetches multiple events by their serials in a single database transaction. +// Returns a map of serial uint64 value to event, only including successfully fetched events. +func (d *D) FetchEventsBySerials(serials []*types.Uint40) (events map[uint64]*event.E, err error) { + events = make(map[uint64]*event.E) + if len(serials) == 0 { - return + return events, nil } - - // Sort serials in ascending order for more efficient database access - sortedSerials := make([]*types.Uint40, len(serials)) - copy(sortedSerials, serials) - sort.Slice( - sortedSerials, func(i, j int) bool { - return sortedSerials[i].Get() < sortedSerials[j].Get() - }, - ) - - // Process all serials in a single transaction + if err = d.View( func(txn *badger.Txn) (err error) { - // Create an iterator with default options - it := txn.NewIterator(badger.DefaultIteratorOptions) - defer it.Close() - - // Process each serial sequentially - for _, ser := range sortedSerials { - // Create the key for this serial + for _, ser := range serials { buf := new(bytes.Buffer) if err = indexes.EventEnc(ser).MarshalWrite(buf); chk.E(err) { + // Skip this serial on error but continue with others continue } - key := buf.Bytes() - - // Seek to this key in the database - it.Seek(key) - if it.Valid() { - item := it.Item() - - // Verify the key matches exactly (should always be true after a Seek) - if !bytes.Equal(item.Key(), key) { - continue - } - - ev := new(event.E) - if err = item.Value( - func(val []byte) (err error) { - // Unmarshal the event - if err = ev.UnmarshalBinary(bytes.NewBuffer(val)); chk.E(err) { - return - } - // Store the event in the result map using the serial value as string key - return - }, - ); chk.E(err) { - continue - } - evMap[strconv.FormatUint(ser.Get(), 10)] = ev - // // Get the item value - // var v []byte - // if v, err = item.ValueCopy(nil); chk.E(err) { - // continue - // } - // - // // Unmarshal the event - // ev := new(event.E) - // if err = ev.UnmarshalBinary(bytes.NewBuffer(v)); chk.E(err) { - // continue - // } - + + var item *badger.Item + if item, err = txn.Get(buf.Bytes()); err != nil { + // Skip this serial if not found but continue with others + err = nil + continue } + + var v []byte + if v, err = item.ValueCopy(nil); chk.E(err) { + // Skip this serial on error but continue with others + err = nil + continue + } + + // Check if we have valid data before attempting to unmarshal + if len(v) < 32+32+1+2+1+1+64 { // ID + Pubkey + min varint fields + Sig + // Skip this serial - incomplete data + continue + } + + ev := new(event.E) + if err = ev.UnmarshalBinary(bytes.NewBuffer(v)); err != nil { + // Skip this serial on unmarshal error but continue with others + err = nil + continue + } + + // Successfully unmarshaled event, add to results + events[ser.Get()] = ev } - return + return nil }, - ); chk.E(err) { + ); err != nil { return } - - log.T.F( - "FetchEventsBySerials: found %d events out of %d requested serials", - len(evMap), len(serials), - ) - return -} + + return events, nil +} \ No newline at end of file diff --git a/pkg/database/query-events.go b/pkg/database/query-events.go index ffaed99..ef9fa18 100644 --- a/pkg/database/query-events.go +++ b/pkg/database/query-events.go @@ -52,15 +52,29 @@ func (d *D) QueryEvents(c context.Context, f *filter.F) ( // Continue with whatever IDs we found } - // Process each found serial, fetch the event, and apply filters + // Convert serials map to slice for batch fetch + var serialsSlice []*types.Uint40 + idHexToSerial := make(map[uint64]string) // Map serial value back to original ID hex for idHex, ser := range serials { - // fetch the event - var ev *event.E - if ev, err = d.FetchEventBySerial(ser); err != nil { - log.T.F( - "QueryEvents: fetch by serial failed for id=%s ser=%v err=%v", - idHex, ser, err, - ) + serialsSlice = append(serialsSlice, ser) + idHexToSerial[ser.Get()] = idHex + } + + // Fetch all events in a single batch operation + var fetchedEvents map[uint64]*event.E + if fetchedEvents, err = d.FetchEventsBySerials(serialsSlice); err != nil { + log.E.F("QueryEvents: batch fetch failed: %v", err) + return + } + + // Process each successfully fetched event and apply filters + for serialValue, ev := range fetchedEvents { + idHex := idHexToSerial[serialValue] + + // Convert serial value back to Uint40 for expiration handling + ser := new(types.Uint40) + if err = ser.Set(serialValue); err != nil { + log.T.F("QueryEvents: error converting serial %d: %v", serialValue, err) continue } @@ -134,16 +148,33 @@ func (d *D) QueryEvents(c context.Context, f *filter.F) ( // Add deletion events to the list of events to process idPkTs = append(idPkTs, deletionIdPkTs...) } - // First pass: collect all deletion events + // Prepare serials for batch fetch + var allSerials []*types.Uint40 + serialToIdPk := make(map[uint64]*store.IdPkTs) for _, idpk := range idPkTs { - var ev *event.E ser := new(types.Uint40) - if err = ser.Set(idpk.Ser); chk.E(err) { + if err = ser.Set(idpk.Ser); err != nil { continue } - if ev, err = d.FetchEventBySerial(ser); err != nil { + allSerials = append(allSerials, ser) + serialToIdPk[ser.Get()] = idpk + } + + // Fetch all events in batch + var allEvents map[uint64]*event.E + if allEvents, err = d.FetchEventsBySerials(allSerials); err != nil { + log.E.F("QueryEvents: batch fetch failed in non-IDs path: %v", err) + return + } + + // First pass: collect all deletion events + for serialValue, ev := range allEvents { + // Convert serial value back to Uint40 for expiration handling + ser := new(types.Uint40) + if err = ser.Set(serialValue); err != nil { continue } + // check for an expiration tag and delete after returning the result if CheckExpiration(ev) { expDeletes = append(expDeletes, ser) @@ -267,15 +298,7 @@ func (d *D) QueryEvents(c context.Context, f *filter.F) ( } } // Second pass: process all events, filtering out deleted ones - for _, idpk := range idPkTs { - var ev *event.E - ser := new(types.Uint40) - if err = ser.Set(idpk.Ser); chk.E(err) { - continue - } - if ev, err = d.FetchEventBySerial(ser); err != nil { - continue - } + for _, ev := range allEvents { // Add logging for tag filter debugging if f.Tags != nil && f.Tags.Len() > 0 { // var eventTags []string