ssbc / ssb-db2

A new database for secure-scuttlebutt
47 stars 8 forks source link

avoid pull.collect to avoid OOM crashes #409

Closed staltz closed 1 year ago

staltz commented 1 year ago

Context

Out-of-memory crashes in Manyverse.

Problem

pull.collect considered harmful for RAM usage, because it internally accumulates an array of all stream items.

Solution

In a few cases, we don't strictly need pull.collect, and pull.drain / pull.onEnd are just fine.

github-actions[bot] commented 1 year ago

Benchmark results

Part Duration
Create 5000 new messages 363.16ms
Validate 5000 messages 455.88ms
Native to db format 5000 messages 115.26ms
Db to native format 5000 messages 85.79ms
Add 1000 elements 488.68ms
Add 1000 box1 msgs 926.84ms
Unbox 1000 box1 msgs first run 209.37ms
Unbox 1000 box1 msgs second run 107.38ms
Add 1000 box1 msgs 894.66ms
Query 1000 msgs first run 51.93ms
Query 1000 msgs second run 13.20ms
Add 1000 box2 msgs 1265.38ms
Unbox 1000 box2 msgs first run 353.66ms
Unbox 1000 box2 msgs second run 179.89ms
Migrate (+db1) 11570.85ms
Migrate (alone) 3977.36ms
Migrate (+db1 +db2) 7979.24ms
Migrate (+db2) 6110.64ms
Migrate continuation (+db2) 1186.63ms
Memory usage without indexes 736.14 MB = 40.19 MB + etc
Initial indexing 1613.91ms
Initial indexing maxcpu=86 4636.54ms
Initial indexing compat 672.16ms
Two indexes updating concurrently 2782.18ms
Key one initial 47.90ms
Key two 1.87ms
Key one again 1.24ms
Reboot and key one again 44.00ms
Latest root posts 1773.59ms
Latest posts 8.39ms
Votes one initial 1435.45ms
Votes again 0.58ms
HasRoot 1311.07ms
HasRoot again 0.53ms
Author one posts 1361.42ms
Author two posts 17.77ms
Dedicated author one posts 1415.13ms
Dedicated author one posts again 0.83ms
DeleteFeed 5541.71ms
Maximum memory usage 1008.28 MB = 63.05 MB + etc
Indexes folder size 10.01mb
github-actions[bot] commented 1 year ago

Benchmark results

Part Duration
Create 5000 new messages 390.46ms
Validate 5000 messages 477.95ms
Native to db format 5000 messages 109.09ms
Db to native format 5000 messages 79.70ms
Add 1000 elements 370.21ms
Add 1000 box1 msgs 1000.79ms
Unbox 1000 box1 msgs first run 211.32ms
Unbox 1000 box1 msgs second run 107.51ms
Add 1000 box1 msgs 969.20ms
Query 1000 msgs first run 50.66ms
Query 1000 msgs second run 13.68ms
Add 1000 box2 msgs 1276.48ms
Unbox 1000 box2 msgs first run 282.90ms
Unbox 1000 box2 msgs second run 144.98ms
Migrate (+db1) 10598.44ms
Migrate (alone) 3585.82ms
Migrate (+db1 +db2) 7957.67ms
Migrate (+db2) 5551.20ms
Migrate continuation (+db2) 826.84ms
Memory usage without indexes 747.40 MB = 38.29 MB + etc
Initial indexing 1593.85ms
Initial indexing maxcpu=86 4513.61ms
Initial indexing compat 659.28ms
Two indexes updating concurrently 2724.60ms
Key one initial 50.16ms
Key two 1.87ms
Key one again 1.82ms
Reboot and key one again 47.06ms
Latest root posts 1640.26ms
Latest posts 8.75ms
Votes one initial 1436.06ms
Votes again 0.57ms
HasRoot 1351.60ms
HasRoot again 0.30ms
Author one posts 1401.84ms
Author two posts 15.84ms
Dedicated author one posts 1396.83ms
Dedicated author one posts again 0.57ms
DeleteFeed 4806.87ms
Maximum memory usage 1009.85 MB = 57.05 MB + etc
Indexes folder size 10.01mb