@dxos/echo-db 2.33.4 → 2.33.5-dev.22471d71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/database/item-demuxer.d.ts.map +1 -1
- package/dist/src/database/item-demuxer.js +0 -2
- package/dist/src/database/item-demuxer.js.map +1 -1
- package/dist/src/halo/halo-party.d.ts.map +1 -1
- package/dist/src/halo/halo-party.js +3 -1
- package/dist/src/halo/halo-party.js.map +1 -1
- package/dist/src/parties/data-party.d.ts.map +1 -1
- package/dist/src/parties/data-party.js +3 -1
- package/dist/src/parties/data-party.js.map +1 -1
- package/dist/src/pipeline/party-core.test.js +2 -1
- package/dist/src/pipeline/party-core.test.js.map +1 -1
- package/dist/src/protocol/party-protocol-factory.d.ts +1 -14
- package/dist/src/protocol/party-protocol-factory.d.ts.map +1 -1
- package/dist/src/protocol/party-protocol-factory.js +2 -55
- package/dist/src/protocol/party-protocol-factory.js.map +1 -1
- package/dist/src/protocol/replicator-plugin.d.ts +7 -0
- package/dist/src/protocol/replicator-plugin.d.ts.map +1 -0
- package/dist/src/protocol/replicator-plugin.js +38 -0
- package/dist/src/protocol/replicator-plugin.js.map +1 -0
- package/dist/src/testing/benchmark.test.d.ts +2 -0
- package/dist/src/testing/benchmark.test.d.ts.map +1 -0
- package/dist/src/testing/benchmark.test.js +25 -0
- package/dist/src/testing/benchmark.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/database/item-demuxer.ts +0 -2
- package/src/halo/halo-party.ts +2 -1
- package/src/parties/data-party.ts +2 -1
- package/src/pipeline/party-core.test.ts +4 -7
- package/src/protocol/party-protocol-factory.ts +3 -56
- package/src/protocol/replicator-plugin.ts +39 -0
- package/src/testing/benchmark.test.ts +30 -0
|
@@ -16,7 +16,8 @@ import { ObjectModel } from '@dxos/object-model';
|
|
|
16
16
|
import { createStorage, StorageType } from '@dxos/random-access-multi-storage';
|
|
17
17
|
import { afterTest } from '@dxos/testutils';
|
|
18
18
|
|
|
19
|
-
import { MetadataStore, PartyFeedProvider
|
|
19
|
+
import { MetadataStore, PartyFeedProvider } from '../pipeline';
|
|
20
|
+
import { createReplicatorPlugin } from '../protocol/replicator-plugin';
|
|
20
21
|
import { SnapshotStore } from '../snapshots';
|
|
21
22
|
import { PartyCore } from './party-core';
|
|
22
23
|
|
|
@@ -286,12 +287,8 @@ describe('PartyCore', () => {
|
|
|
286
287
|
afterTest(async () => party2.close());
|
|
287
288
|
|
|
288
289
|
createTestProtocolPair(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
).createPlugins().map(r => r.createExtension()),
|
|
292
|
-
new ReplicatorProtocolPluginFactory(
|
|
293
|
-
partyFeedProvider
|
|
294
|
-
).createPlugins().map(r => r.createExtension())
|
|
290
|
+
[createReplicatorPlugin(peer1.partyFeedProvider).createExtension()],
|
|
291
|
+
[createReplicatorPlugin(partyFeedProvider).createExtension()]
|
|
295
292
|
);
|
|
296
293
|
|
|
297
294
|
const item1 = await peer1.party.database.createItem();
|
|
@@ -4,17 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import debug from 'debug';
|
|
6
6
|
|
|
7
|
-
import { synchronized } from '@dxos/async';
|
|
8
7
|
import { discoveryKey, keyToString, PublicKey } from '@dxos/crypto';
|
|
9
|
-
import {
|
|
10
|
-
import type { HypercoreFeed } from '@dxos/feed-store';
|
|
8
|
+
import { PartyKey } from '@dxos/echo-protocol';
|
|
11
9
|
import { Protocol } from '@dxos/mesh-protocol';
|
|
12
10
|
import { MMSTTopology, NetworkManager, Plugin } from '@dxos/network-manager';
|
|
13
11
|
import { PresencePlugin } from '@dxos/protocol-plugin-presence';
|
|
14
|
-
import { Replicator } from '@dxos/protocol-plugin-replicator';
|
|
15
12
|
|
|
16
13
|
import { CredentialsProvider } from '.';
|
|
17
|
-
import { PartyFeedProvider } from '../pipeline/party-feed-provider';
|
|
18
14
|
|
|
19
15
|
const log = debug('dxos:echo-db:party-protocol-factory');
|
|
20
16
|
|
|
@@ -23,21 +19,15 @@ const log = debug('dxos:echo-db:party-protocol-factory');
|
|
|
23
19
|
*/
|
|
24
20
|
export class PartyProtocolFactory {
|
|
25
21
|
private readonly _presencePlugin = new PresencePlugin(this._peerId.asBuffer());
|
|
26
|
-
private readonly _replicatorProtocolPluginFactory: ReplicatorProtocolPluginFactory;
|
|
27
22
|
|
|
28
23
|
private _started = false;
|
|
29
24
|
|
|
30
25
|
constructor (
|
|
31
26
|
private readonly _partyKey: PartyKey,
|
|
32
27
|
private readonly _networkManager: NetworkManager,
|
|
33
|
-
private readonly _feedProvider: PartyFeedProvider,
|
|
34
28
|
private readonly _peerId: PublicKey,
|
|
35
29
|
private readonly _credentials: CredentialsProvider
|
|
36
|
-
) {
|
|
37
|
-
// Replication.
|
|
38
|
-
this._replicatorProtocolPluginFactory =
|
|
39
|
-
new ReplicatorProtocolPluginFactory(this._feedProvider);
|
|
40
|
-
}
|
|
30
|
+
) {}
|
|
41
31
|
|
|
42
32
|
async start (plugins: Plugin[]) {
|
|
43
33
|
if (this._started) {
|
|
@@ -73,9 +63,8 @@ export class PartyProtocolFactory {
|
|
|
73
63
|
await this._networkManager.leaveProtocolSwarm(this._partyKey);
|
|
74
64
|
}
|
|
75
65
|
|
|
76
|
-
private _createProtocol (channel: any, opts: {initiator: boolean}, extraPlugins: Plugin[]) {
|
|
66
|
+
private _createProtocol (channel: any, opts: { initiator: boolean }, extraPlugins: Plugin[]) {
|
|
77
67
|
const plugins: Plugin[] = [
|
|
78
|
-
...this._replicatorProtocolPluginFactory.createPlugins(),
|
|
79
68
|
...extraPlugins,
|
|
80
69
|
this._presencePlugin
|
|
81
70
|
];
|
|
@@ -118,45 +107,3 @@ export class PartyProtocolFactory {
|
|
|
118
107
|
return protocol;
|
|
119
108
|
}
|
|
120
109
|
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Creates the protocol plugin for feed replication.
|
|
124
|
-
*/
|
|
125
|
-
export class ReplicatorProtocolPluginFactory {
|
|
126
|
-
constructor (
|
|
127
|
-
private readonly _feedProvider: PartyFeedProvider
|
|
128
|
-
) {}
|
|
129
|
-
|
|
130
|
-
createPlugins () {
|
|
131
|
-
return [
|
|
132
|
-
new Replicator({
|
|
133
|
-
load: async () => {
|
|
134
|
-
const feeds = this._feedProvider.getFeeds();
|
|
135
|
-
log(`Loading feeds: ${feeds.map(feed => keyToString(feed.key))}`);
|
|
136
|
-
return feeds.map((feed) => ({ discoveryKey: feed.feed.discoveryKey }));
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
subscribe: (addFeedToReplicatedSet: (feed: any) => void) => {
|
|
140
|
-
return this._feedProvider.feedOpened.on(async (feed) => {
|
|
141
|
-
log(`Adding feed: ${feed.key.toHex()}`);
|
|
142
|
-
addFeedToReplicatedSet({ discoveryKey: feed.feed.discoveryKey });
|
|
143
|
-
});
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
replicate: async (remoteFeeds, info) => {
|
|
147
|
-
// We can ignore remoteFeeds entirely, since the set of feeds we want to replicate is dictated by the Party.
|
|
148
|
-
// TODO(telackey): Why are we opening feeds? Necessary or belt/braces thinking, or because open party does it?
|
|
149
|
-
const feeds = this._feedProvider.getFeeds();
|
|
150
|
-
log(`Replicating: peerId=${info.session}; feeds=${feeds.map(feed => feed.key.toHex())}`);
|
|
151
|
-
return feeds.map(feed => feed.feed);
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
];
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
@synchronized
|
|
158
|
-
private async _openFeed (key: FeedKey): Promise<HypercoreFeed> {
|
|
159
|
-
const descriptor = await this._feedProvider.createOrOpenReadOnlyFeed(key);
|
|
160
|
-
return descriptor.feed;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import debug from 'debug';
|
|
6
|
+
|
|
7
|
+
import { keyToString } from '@dxos/crypto';
|
|
8
|
+
import { Replicator } from '@dxos/protocol-plugin-replicator';
|
|
9
|
+
|
|
10
|
+
import { PartyFeedProvider } from '../pipeline';
|
|
11
|
+
|
|
12
|
+
const log = debug('dxos:echo-db:protocol:replicator');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates the protocol plugin for feed replication.
|
|
16
|
+
*/
|
|
17
|
+
export const createReplicatorPlugin = (feedProvider: PartyFeedProvider) =>
|
|
18
|
+
new Replicator({
|
|
19
|
+
load: async () => {
|
|
20
|
+
const feeds = feedProvider.getFeeds();
|
|
21
|
+
log(`Loading feeds: ${feeds.map(feed => keyToString(feed.key))}`);
|
|
22
|
+
return feeds.map((feed) => ({ discoveryKey: feed.feed.discoveryKey }));
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
subscribe: (addFeedToReplicatedSet: (feed: any) => void) => {
|
|
26
|
+
return feedProvider.feedOpened.on(async (feed) => {
|
|
27
|
+
log(`Adding feed: ${feed.key.toHex()}`);
|
|
28
|
+
addFeedToReplicatedSet({ discoveryKey: feed.feed.discoveryKey });
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
replicate: async (remoteFeeds, info) => {
|
|
33
|
+
// We can ignore remoteFeeds entirely, since the set of feeds we want to replicate is dictated by the Party.
|
|
34
|
+
// TODO(telackey): Why are we opening feeds? Necessary or belt/braces thinking, or because open party does it?
|
|
35
|
+
const feeds = feedProvider.getFeeds();
|
|
36
|
+
log(`Replicating: peerId=${info.session}; feeds=${feeds.map(feed => feed.key.toHex())}`);
|
|
37
|
+
return feeds.map(feed => feed.feed);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { ObjectModel } from '@dxos/object-model';
|
|
6
|
+
|
|
7
|
+
import { ECHO } from '../echo';
|
|
8
|
+
|
|
9
|
+
const ITEMS = 100;
|
|
10
|
+
const MUTATIONS = 1000;
|
|
11
|
+
|
|
12
|
+
it.skip('Database benchmark', async () => {
|
|
13
|
+
const echo = new ECHO({ snapshots: false });
|
|
14
|
+
await echo.open();
|
|
15
|
+
await echo.halo.createProfile();
|
|
16
|
+
const party = await echo.createParty();
|
|
17
|
+
|
|
18
|
+
const start = Date.now();
|
|
19
|
+
for (let i = 0; i < ITEMS; i++) {
|
|
20
|
+
const item = await party.database.createItem({ model: ObjectModel, type: 'test:item' });
|
|
21
|
+
|
|
22
|
+
for (let j = 0; j < MUTATIONS; j++) {
|
|
23
|
+
await item.model.set(`key${j % 100}`, `value-${j}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
console.log(`${i * MUTATIONS}/${ITEMS * MUTATIONS} ${((Date.now() - start) / ((i + 1) * MUTATIONS / 1000)).toFixed(1)} µs/mut ${((i + 1) * MUTATIONS / (Date.now() - start) * 1000).toFixed(1)} mut/s`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await echo.close();
|
|
30
|
+
});
|