ssbc / ssb-db2

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

allow heterogenous feed formats in addTransaction #389

Closed staltz closed 2 years ago

staltz commented 2 years ago

Context

https://github.com/ssbc/ssb-ebt/pull/71

Problem

We need to add an index message [indexMsg, payload] with the sbot.db.addTransaction API, such that the indexMsg is the "normal" part and the payload is the OOO part, but current addTransaction assumes that all of them have the same feed format.

Solution

This PR changes addTransaction internally, in a backwards-compatible way, so that the "nativeMsgs" part can be a different feed format to the "oooNativeMsgs" part.

github-actions[bot] commented 2 years ago

Benchmark results

Part Duration
Create 5000 new messages 356.51ms
Validate 5000 messages 449.82ms
Native to db format 5000 messages 115.12ms
Db to native format 5000 messages 82.19ms
Add 1000 elements 367.62ms
Add 1000 box1 msgs 928.86ms
Unbox 1000 box1 msgs first run 219.65ms
Unbox 1000 box1 msgs second run 109.18ms
Add 1000 box1 msgs 890.15ms
Query 1000 msgs first run 49.67ms
Query 1000 msgs second run 12.90ms
Add 1000 box2 msgs 1270.48ms
Unbox 1000 box2 msgs first run 287.25ms
Unbox 1000 box2 msgs second run 145.76ms
Migrate (+db1) 11282.38ms
Migrate (alone) 3902.59ms
Migrate (+db1 +db2) 7981.49ms
Migrate (+db2) 6024.20ms
Migrate continuation (+db2) 853.81ms
Memory usage without indexes 761.15 MB = 39.98 MB + etc
Initial indexing 1599.53ms
Initial indexing maxcpu=86 4936.70ms
Initial indexing compat 682.75ms
Two indexes updating concurrently 2810.02ms
Key one initial 47.33ms
Key two 0.72ms
Key one again 1.32ms
Reboot and key one again 41.10ms
Latest root posts 1729.63ms
Latest posts 11.74ms
Votes one initial 1461.93ms
Votes again 0.54ms
HasRoot 1287.28ms
HasRoot again 0.30ms
Author one posts 1372.47ms
Author two posts 38.60ms
Dedicated author one posts 1416.95ms
Dedicated author one posts again 0.86ms
DeleteFeed 2874.55ms
Maximum memory usage 1010.08 MB = 59.86 MB + etc
Indexes folder size 10.01mb
github-actions[bot] commented 2 years ago

Benchmark results

Part Duration
Create 5000 new messages 353.40ms
Validate 5000 messages 476.95ms
Native to db format 5000 messages 108.89ms
Db to native format 5000 messages 84.30ms
Add 1000 elements 370.10ms
Add 1000 box1 msgs 997.53ms
Unbox 1000 box1 msgs first run 218.44ms
Unbox 1000 box1 msgs second run 111.02ms
Add 1000 box1 msgs 970.40ms
Query 1000 msgs first run 48.11ms
Query 1000 msgs second run 12.50ms
Add 1000 box2 msgs 1273.09ms
Unbox 1000 box2 msgs first run 272.96ms
Unbox 1000 box2 msgs second run 140.81ms
Migrate (+db1) 10935.12ms
Migrate (alone) 3616.22ms
Migrate (+db1 +db2) 8228.22ms
Migrate (+db2) 5664.08ms
Migrate continuation (+db2) 834.14ms
Memory usage without indexes 757.16 MB = 38.18 MB + etc
Initial indexing 1584.67ms
Initial indexing maxcpu=86 4748.96ms
Initial indexing compat 643.39ms
Two indexes updating concurrently 2798.60ms
Key one initial 46.54ms
Key two 1.04ms
Key one again 1.73ms
Reboot and key one again 51.08ms
Latest root posts 1689.31ms
Latest posts 8.35ms
Votes one initial 1492.46ms
Votes again 0.31ms
HasRoot 1291.82ms
HasRoot again 0.28ms
Author one posts 1424.59ms
Author two posts 18.08ms
Dedicated author one posts 1430.63ms
Dedicated author one posts again 0.77ms
DeleteFeed 2608.62ms
Maximum memory usage 973.94 MB = 59.45 MB + etc
Indexes folder size 10.01mb