Skip to content

Commit

Permalink
synapse-compress: auto-compress all rooms and workaround matrix-org/r…
Browse files Browse the repository at this point in the history
  • Loading branch information
csett86 committed Apr 14, 2022
1 parent bb53996 commit b375ffe
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions scripts/synapse-compress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@

API_TOKEN=<ADD HERE>
HOST=http://localhost:8008
ROOMLIMIT=5000
ROOMLIMIT=10000
PSQL_USER=synapse
PSQL_PASSWORD=password
PSQL_HOST=localhost
PSQL_DB=synapse

ROOMLIST=$(curl --silent --header "Authorization: Bearer $API_TOKEN" $HOST/_synapse/admin/v1/rooms?limit=$ROOMLIMIT)
ROOMLIST=$(curl --silent --fail --header "Authorization: Bearer $API_TOKEN" $HOST/_synapse/admin/v1/rooms?limit=$ROOMLIMIT)

ROOMS_WITHOUT_LOCAL_USERS=$(echo $ROOMLIST | jq --raw-output '.rooms[] | select(.joined_local_members == 0) | .room_id')

for room in $ROOMS_WITHOUT_LOCAL_USERS; do
curl --silent --header "Authorization: Bearer $API_TOKEN" --header "Content-Type: application/json" -XDELETE -d "{}" --output /dev/null "$HOST/_synapse/admin/v1/rooms/$room"
curl --silent --fail --header "Authorization: Bearer $API_TOKEN" --header "Content-Type: application/json" -XDELETE -d "{}" --output /dev/null "$HOST/_synapse/admin/v1/rooms/$room"
# workaround https://github.com/matrix-org/rust-synapse-compress-state/issues/78
psql -w -U $PSQL_USER -h $PSQL_HOST --quiet -t -c "DELETE FROM state_compressor_progress WHERE room_id='$room';" $PSQL_DB
psql -w -U $PSQL_USER -h $PSQL_HOST --quiet -t -c "DELETE FROM state_compressor_state WHERE room_id='$room';" $PSQL_DB
done

TIMESTAMPMS30DAYS=$(date --date="-30 days" +%s000)
curl --silent --header "Authorization: Bearer $API_TOKEN" --header "Content-Type: application/json" -d "{}" --output /dev/null "$HOST/_synapse/admin/v1/purge_media_cache?before_ts=$TIMESTAMPMS30DAYS"
curl --silent --fail --header "Authorization: Bearer $API_TOKEN" --header "Content-Type: application/json" -d "{}" --output /dev/null "$HOST/_synapse/admin/v1/purge_media_cache?before_ts=$TIMESTAMPMS30DAYS"

# manual state compression disabled, it uses too much RAM and gets OOM killed
#ROOMS_TO_COMPRESS=$(psql -w -U $PSQL_USER -h $PSQL_HOST --quiet -t -c 'SELECT room_id FROM state_groups_state GROUP BY room_id HAVING count(*) > 100000;' $PSQL_DB)
Expand All @@ -29,8 +32,8 @@ curl --silent --header "Authorization: Bearer $API_TOKEN" --header "Content-Type
# psql -w -U $PSQL_USER -h $PSQL_HOST --quiet $PSQL_DB < /tmp/state-compressor.sql
#done

# auto state compress with "big" settings from https://gitlab.com/mb-saces/synatainer
RUST_LOG=error $HOME/rust-synapse-compress-state/target/debug/synapse_auto_compressor -c 1500 -n 300 -p "postgresql://$PSQL_USER:$PSQL_PASSWORD@$PSQL_HOST/$PSQL_DB"
# auto state compress with "big" settings from https://gitlab.com/mb-saces/synatainer and all rooms
RUST_LOG=error $HOME/rust-synapse-compress-state/target/debug/synapse_auto_compressor -c 1500 -n $ROOMLIMIT -p "postgresql://$PSQL_USER:$PSQL_PASSWORD@$PSQL_HOST/$PSQL_DB"

# when performing stop, dependencies are stopped
monit stop synapse
Expand Down

0 comments on commit b375ffe

Please sign in to comment.