From f457fb686b00bd2939c4721f26e404ef80dba597 Mon Sep 17 00:00:00 2001 From: fryorcraken Date: Tue, 11 Feb 2025 12:59:44 +1100 Subject: [PATCH] Moving shm script to own script --- README.md | 14 +++++++++++++- set_postgres_shm.sh | 28 ++++++++++++++++++++++++++++ set_storage_retention.sh | 13 ------------- setup_wizard.sh | 15 +++++++++++++-- 4 files changed, 54 insertions(+), 16 deletions(-) create mode 100755 set_postgres_shm.sh diff --git a/README.md b/README.md index 6e8a76d..710449d 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Note that if you just want to relay traffic (not publish), you don't need one. ./register_rln.sh ``` -### 💽 2. Select storage size +### 💽 2. Select DB Parameters Waku runs a PostgreSQL Database to store messages from the network and serve them to other peers. To prevent the database to grow indefinitely, you need to select how much disk space to allocate. @@ -63,6 +63,18 @@ Or select your own value. For example, `50GB`: echo "STORAGE_SIZE=50GB" >> .env ``` +Depending on your machine's memory, it may be worth allocating more memory to the Postgres container to ensure heavy queries are served: + +```shell +./set_postgres_shm.sh +``` + +Or select your own value manually, for example, `4g`: + +```shell +echo "POSTGRES_SHM=4g" >> .env +``` + ### 🖥️ 3. Start your node Start all processes: nwaku node, database and grafana for metrics. Your [RLN](https://rate-limiting-nullifier.github.io/rln-docs/what_is_rln.html) membership is loaded into nwaku under the hood. diff --git a/set_postgres_shm.sh b/set_postgres_shm.sh new file mode 100755 index 0000000..cf7297a --- /dev/null +++ b/set_postgres_shm.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +# check if POSTGRES_SHM is already specified +if [ -f "./.env" ]; then + . ./.env +fi + +if [ -n "$POSTGRES_SHM" ]; then + >&2 echo "POSTGRES_SHM is specified in .env file, doing nothing" + exit 0 +fi + +# Set PostgreSQL container Shared Memory value +TOTAL_MEM_MB=$(free -m|grep Mem| awk '{ print $2 }') +if [ "${TOTAL_MEM_MB}" -ge 4096 ]; then + # Allocate 2GB of Shared Memory for Postgres if machine has more than 4GB RAM + POSTGRES_SHM='2g' +else + # Allocate 1GB of Shared Memory for Postgres + POSTGRES_SHM='1g' +fi + +>&2 echo "Setting PostgreSQL container SHM to ${POSTGRES_SHM}" +if [ "$1" = "echo-value" ]; then + echo ${POSTGRES_SHM} +else + echo "POSTGRES_SHM=${POSTGRES_SHM}" >> .env +fi diff --git a/set_storage_retention.sh b/set_storage_retention.sh index 986397d..c98c5a0 100755 --- a/set_storage_retention.sh +++ b/set_storage_retention.sh @@ -56,19 +56,6 @@ if [ -f "./.env" ]; then . ./.env fi -# Set PostgreSQL container Shared Memory value -if [ -z "${POSTGRES_SHM}" ]; then - TOTAL_MEM_MB=$(free -m|grep Mem| awk '{ print $2 }') - if [ "${TOTAL_MEM_MB}" -ge 4096 ]; then - # Allocate 2GB of Shared Memory for Postgres if machine has more than 4GB RAM - POSTGRES_SHM='2g' - echo "Setting PostgreSQL container SHM to ${POSTGRES_SHM}" - echo "POSTGRES_SHM=${POSTGRES_SHM}" >> .env - fi -else - >&2 echo "POSTGRES_SHM is already specified in .env file" -fi - if [ -n "$STORAGE_SIZE" ]; then >&2 echo "STORAGE_SIZE is specified in .env file, doing nothing" exit 0 diff --git a/setup_wizard.sh b/setup_wizard.sh index 257fe2e..3bc7b6d 100755 --- a/setup_wizard.sh +++ b/setup_wizard.sh @@ -66,18 +66,29 @@ if [ -z "$STORAGE_SIZE" ]; then exit 1 fi +echocol "...." +echocol "Selecting a SHM for Postgres..." +POSTGRES_SHM=$(./set_postgres_shm.sh echo-value) + +if [ -z "$POSTGRES_SHM" ]; then + echo "Error encountered when estimating postgres container shm, exiting" + exit 1 +fi + echocol "...." echocol "The following parameters will be saved to your .env file. Press ENTER to confirm or quit with CONTROL-C to abort:" echo "RLN_RELAY_ETH_CLIENT_ADDRESS='$RLN_RELAY_ETH_CLIENT_ADDRESS' ETH_TESTNET_KEY=$ETH_TESTNET_KEY RLN_RELAY_CRED_PASSWORD='$RLN_RELAY_CRED_PASSWORD' -STORAGE_SIZE=$STORAGE_SIZE" +STORAGE_SIZE=$STORAGE_SIZE +POSTGRES_SHM=$POSTGRES_SHM" read foo echo "RLN_RELAY_ETH_CLIENT_ADDRESS='$RLN_RELAY_ETH_CLIENT_ADDRESS' ETH_TESTNET_KEY=$ETH_TESTNET_KEY RLN_RELAY_CRED_PASSWORD='$RLN_RELAY_CRED_PASSWORD' -STORAGE_SIZE=$STORAGE_SIZE" > ./.env +STORAGE_SIZE=$STORAGE_SIZE +POSTGRES_SHM=$POSTGRES_SHM" > ./.env SUDO="" if ! docker info > /dev/null 2>&1; then