Skip to content

Commit 2017056

Browse files
committed
Add readme.
1 parent 7115578 commit 2017056

File tree

2 files changed

+87
-5
lines changed

2 files changed

+87
-5
lines changed

demos/benchmarks/README.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,86 @@
11
# PowerSync Benchmark app
22

3-
# Configure the app
3+
This is an app to test:
4+
1. Initial sync time. This can be used to get a sync throughput estimate.
5+
2. Incremental sync latency.
6+
7+
Incremental sync latency tests the total latency of the following sequence:
8+
9+
1. Create a row on the client, recording the creation time.
10+
2. Upload to server via NodeJS demo backend.
11+
3. Postgres adds a default value to one column.
12+
4. The row is synced back down, including the new default column.
13+
5. The client detects that the default column is set (using a watched query).
14+
6. The client updates the row, recording the latency.
15+
16+
For initial sync, bulk data is synced without actively being used by the app, just to measure the sync time.
17+
18+
# Setup
19+
20+
To primarily measure the client-side sync overhead, run the PowerSync service on the same local network as the client.
21+
22+
## Postgres
23+
24+
```sql
25+
CREATE TABLE bulk_data (id uuid primary key default gen_random_uuid(), created_at timestamptz not null default now(), name text, size_bucket text);
26+
CREATE TABLE benchmark_items(id uuid primary key, description text, client_created_at timestamptz not null, client_received_at timestamptz, server_created_at timestamptz not null default now());
27+
28+
INSERT INTO bulk_data (name, size_bucket) SELECT repeat('a', 20), '10k' FROM generate_series(1, 10000);
29+
INSERT INTO bulk_data (name, size_bucket) SELECT repeat('a', 20), '100k' FROM generate_series(1, 100000);
30+
INSERT INTO bulk_data (name, size_bucket) SELECT repeat('a', 20), '1m' FROM generate_series(1, 1000000);
31+
INSERT INTO bulk_data (name, size_bucket) SELECT repeat('a', 20), '10m' FROM generate_series(1, 10000000);
32+
```
33+
34+
For reference, these rows are around 142 bytes each when synced. However, sync performance is more related to the number of rows than the total data size, unless you have much larger rows.
35+
36+
## PowerSync Service
37+
38+
Use this sync rules:
39+
40+
```yaml
41+
bucket_definitions:
42+
bucket_items:
43+
data:
44+
- select * from benchmark_items
45+
bulk:
46+
parameters: select request.parameters() ->> 'size_bucket' as size_bucket
47+
data:
48+
- select * from bulk_data where size_bucket = bucket.size_bucket
49+
```
50+
51+
## Demo Backend
52+
53+
The backend is not required measuring initial sync, but is required for measuring latency.
54+
55+
Use the backend here: https://github.com/powersync-ja/powersync-nodejs-backend-todolist-demo
56+
57+
It should write to the same Postgres database as configured above.
58+
59+
## Configure the app
60+
61+
Generate a temporary token, and configure the credentials in `lib/app_config.dart`.
62+
63+
Currently a size bucket must be hardcoded in the config - one of "10k", "100k", "1m" or "10m" (see the Postgres setup above).
64+
65+
# Usage
66+
67+
Run the app with:
68+
69+
```sh
70+
# Desktop / Mobile
71+
flutter run --release
72+
# Chrome, OPFS
73+
flutter run -d chrome --release --web-header "Cross-Origin-Opener-Policy=same-origin" --web-header "Cross-Origin-Embedder-Policy=require-corp"
74+
```
75+
76+
For Android, you can connect to PowerSync running on localhost by using `adb reverse`:
77+
78+
```sh
79+
adb reverse tcp:8080 tcp:8080
80+
adb reverse tcp:6060 tcp:6060
81+
```
82+
83+
Initial sync time is automatically calculated and displayed.
84+
85+
For incremental sync, create individual records or batches of records, and wait for the latency to be updated. Wait for sync to fully complete after each record before creating the next one.
486

5-
Insert the credentials of your PowerSync project into `lib/app_config.dart`

demos/benchmarks/pubspec.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,10 @@ packages:
377377
sqlite_async:
378378
dependency: "direct main"
379379
description:
380-
path: "../../../sqlite_async/packages/sqlite_async"
381-
relative: true
382-
source: path
380+
name: sqlite_async
381+
sha256: d66fb6e6d07c1a834743326c033029f75becbb1fad6823d709f921872abc3d5b
382+
url: "https://pub.dev"
383+
source: hosted
383384
version: "0.11.0"
384385
stack_trace:
385386
dependency: transitive

0 commit comments

Comments
 (0)