Skip to content

Commit 3b5d7fd

Browse files
authored
Add information on running options to README and --help output (#51)
1 parent 0f7f2c2 commit 3b5d7fd

File tree

2 files changed

+86
-6
lines changed

2 files changed

+86
-6
lines changed

README.md

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ transaction should not affect the results from any of the queries that synapse
1919
performs.
2020

2121
The tool will also ensure that the generated state deltas do give the same state
22-
as the existing state deltas.
22+
as the existing state deltas before generating any SQL.
2323

2424
## Algorithm
2525

@@ -35,7 +35,8 @@ L2 <-------------------- L2 <---------- ...
3535
^--- L1 <--- L1 <--- L1 ^--- L1 <--- L1 <--- L1
3636
```
3737

38-
The sizes and number of levels used can be controlled via `-l`.
38+
The sizes and number of levels used can be controlled via `-l`, and defaults to 3
39+
levels of sizes 100, 50 and 25.
3940

4041
**Note**: Increasing the sum of the sizes of levels will increase the time it
4142
takes for to query the full state of a given state group. By default Synapse
@@ -61,11 +62,59 @@ New state map matches old one
6162
$ psql synapse < out.data
6263
```
6364

65+
## Running Options
66+
67+
- -p [URL] **Required**
68+
The url for connecting to the postgres database. This should be of the form
69+
"postgresql://username:password@mydomain.com/database"
70+
71+
- -r [ROOM_ID] **Required**
72+
The room to process. This is the value found in the `rooms` table of the database
73+
not the common name for the room - is should look like: "!wOlkWNmgkAZFxbTaqj:matrix.org"
74+
75+
- -b [MIN_STATE_GROUP]
76+
The state group to start processing from (non inclusive)
77+
78+
- -n [GROUPS_TO_COMPRESS]
79+
How many groups to load into memory to compress (starting
80+
from the 1st group in the room or the group specified by -s)
81+
82+
- -l [LEVELS]
83+
Sizes of each new level in the compression algorithm, as a comma separated list.
84+
The first entry in the list is for the lowest, most granular level, with each
85+
subsequent entry being for the next highest level. The number of entries in the
86+
list determines the number of levels that will be used. The sum of the sizes of
87+
the levels effect the performance of fetching the state from the database, as the
88+
sum of the sizes is the upper bound on number of iterations needed to fetch a
89+
given set of state. [default's to 100,50,25]
90+
91+
- -m [COUNT]
92+
If the compressor cannot save this many rows from the database then it will stop early
93+
94+
- -s [MAX_STATE_GROUP]
95+
If a max_state_group is specified then only state groups with id's lower than this number are able to be
96+
compressed.
97+
98+
- -o [FILE]
99+
File to output the SQL transactions to (for later running on the database)
100+
101+
- -t
102+
If this flag is set then then each change to a particular state group is wrapped in a transaction. This should be done if you wish to apply the changes while synapse is still running.
103+
104+
- -g
105+
If this flag is set then output the node and edge information for the state_group
106+
directed graph built up from the predecessor state_group links. These can be looked
107+
at in something like Gephi (https://gephi.org)
108+
64109
## Using as python library
65110

66111
The compressor can also be built into a python library as it uses PyO3. It can be
67112
built and installed into the current virtual environment by running `maturin develop`
68113

114+
All the same running options are available, see the comments in the Config struct
115+
in lib.rs for the names of each argument. All arguments other than `db_url` and `room_id`
116+
are optional.
117+
69118
The following code does exactly the same as the command-line example from above:
70119
```
71120
import synapse_compress_state as comp
@@ -89,4 +138,18 @@ LD_PATH=/[LONG_PATH]/synapse_compress_state.abi3.so ./my_python_script
89138
Or just try disabling jemalloc:
90139
```
91140
$ maturin develop --cargo-extra-args="--no-default-features"
92-
```
141+
```
142+
143+
## Running tests
144+
There are integration tests for these tool stored in `compressor_integration_tests/`
145+
146+
To run the integration tests, you first need to start up a postgres database
147+
for the libary to talk to. There is a docker-compose file that sets one up
148+
with all of the correct tables. The tests can therefore be run as follows:
149+
150+
```
151+
$ cd compressor_integration_tests/
152+
$ docker-compose up -d
153+
$ cargo test --workspace
154+
$ docker-compose down
155+
```

src/lib.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,21 @@ impl Config {
120120
Arg::with_name("postgres-url")
121121
.short("p")
122122
.value_name("URL")
123-
.help("The url for connecting to the postgres database")
123+
.help("The url for connecting to the postgres database.")
124+
.long_help(concat!(
125+
"The url for connecting to the postgres database.This should be of",
126+
" the form \"postgresql://username:[email protected]/database\""))
124127
.takes_value(true)
125128
.required(true),
126129
).arg(
127130
Arg::with_name("room_id")
128131
.short("r")
129132
.value_name("ROOM_ID")
130133
.help("The room to process")
134+
.long_help(concat!(
135+
"The room to process. This is the value found in the rooms table of the database",
136+
" not the common name for the room - is should look like: \"!wOlkWNmgkAZFxbTaqj:matrix.org\""
137+
))
131138
.takes_value(true)
132139
.required(true),
133140
).arg(
@@ -142,13 +149,17 @@ impl Config {
142149
.short("m")
143150
.value_name("COUNT")
144151
.help("Abort if fewer than COUNT rows would be saved")
152+
.long_help("If the compressor cannot save this many rows from the database then it will stop early")
145153
.takes_value(true)
146154
.required(false),
147155
).arg(
148156
Arg::with_name("groups_to_compress")
149157
.short("n")
150158
.value_name("GROUPS_TO_COMPRESS")
151-
.help("How many groups to load into memory to compress")
159+
.help("How many groups to load into memory to compress")
160+
.long_help(concat!(
161+
"How many groups to load into memory to compress (starting from",
162+
" the 1st group in the room or the group specified by -s)"))
152163
.takes_value(true)
153164
.required(false),
154165
).arg(
@@ -188,11 +199,17 @@ impl Config {
188199
Arg::with_name("transactions")
189200
.short("t")
190201
.help("Whether to wrap each state group change in a transaction")
202+
.long_help(concat!("If this flag is set then then each change to a particular",
203+
" state group is wrapped in a transaction. This should be done if you wish to",
204+
" apply the changes while synapse is still running."))
191205
.requires("output_file"),
192206
).arg(
193207
Arg::with_name("graphs")
194208
.short("g")
195-
.help("Whether to produce graphs of state groups before and after compression instead of SQL")
209+
.help("Output before and after graphs")
210+
.long_help(concat!("If this flag is set then output the node and edge information for",
211+
" the state_group directed graph built up from the predecessor state_group links.",
212+
" These can be looked at in something like Gephi (https://gephi.org)"))
196213
).get_matches();
197214

198215
let db_url = matches

0 commit comments

Comments
 (0)