Skip to content

Instantly share code, notes, and snippets.

@ryumada
Created January 14, 2026 10:06
Show Gist options
  • Select an option

  • Save ryumada/efb67199190a91b714bc69783420f858 to your computer and use it in GitHub Desktop.

Select an option

Save ryumada/efb67199190a91b714bc69783420f858 to your computer and use it in GitHub Desktop.
Odoo Config Calculator. This is Odoo Config calculator to manage the RAM usage if Odoo and PostgreSQL deployed in one VM.
#!/usr/bin/env bash
set -e
# FORCE STANDARD MATH (Fixes the "6MB" bug by enforcing dot usage)
export LC_NUMERIC=C
# ==============================================================================
# LOGGING UTILITIES
# ==============================================================================
log() {
local color="$1"
local icon="$2"
local message="$3"
local timestamp
timestamp=$(date +"[%H:%M:%S]")
echo -e "${color}${icon} ${timestamp} ${message}\033[0m"
}
log_info() { log "\033[1;34m" "ℹ️ " "$1"; }
log_success() { log "\033[1;32m" "✅" "$1"; }
log_warn() { log "\033[1;33m" "⚠️ " "$1"; }
log_error() { log "\033[1;31m" "❌" "$1"; }
log_output() { echo -e "$1"; }
executeCommand() {
local description="$1"
local command_to_run="$2"
local success_message="$3"
local failure_message="$4"
log_info "Executing: $description"
local output
if output=$(eval "$command_to_run" 2>&1); then
log_success "$success_message"
else
log_error "$failure_message"
log_output "--- COMMAND OUTPUT ---"
log_output "$output"
if [[ "$5" != "continue" ]]; then exit 1; fi
fi
}
# ==============================================================================
# MAIN SCRIPT LOGIC
# ==============================================================================
if [[ -z "$1" || -z "$2" ]]; then
log_error "Usage: $0 <RAM_IN_GB> <CPU_CORES>"
log_output "Example: $0 10 6"
exit 1
fi
INPUT_RAM_GB=$1
INPUT_CPU=$2
log_info "Starting Configuration Calculator for ${INPUT_RAM_GB}GB RAM and ${INPUT_CPU} CPU Cores..."
# Check for awk and valid input
executeCommand "Checking for awk" "command -v awk" "Awk installed." "Awk missing."
executeCommand "Validating inputs" \
"echo '$INPUT_RAM_GB $INPUT_CPU' | awk '{if(\$1+0 == \$1 && \$2+0 == \$2) exit 0; else exit 1}'" \
"Inputs are valid." "Invalid inputs."
# ==============================================================================
# UPDATED CONSTANTS (THE FIX)
# ==============================================================================
# Soft Limit: 640MB (Recycle point for healthy workers)
WORKER_RAM_SOFT_MB=640
# Hard Limit: INCREASED to 1152MB (1.1GB)
# Reason: 768MB kills Asset Compilation. 1600MB reduces worker count too much.
# 1152MB is the "Sweet Spot" for heavy Odoo 16/17 tasks.
WORKER_RAM_HARD_MB=1152
# ==============================================================================
# CALCULATIONS
# ==============================================================================
# --- POSTGRESQL (Golden Ratio: 25%) ---
PG_SHARED_BUFFERS_GB=$(awk "BEGIN {printf \"%.2f\", $INPUT_RAM_GB * 0.25}")
PG_SHARED_BUFFERS_MB=$(awk "BEGIN {printf \"%.0f\", $PG_SHARED_BUFFERS_GB * 1024}")
PG_EFFECTIVE_CACHE_GB=$(awk "BEGIN {printf \"%.0f\", $INPUT_RAM_GB * 0.75}")
# --- ODOO WORKERS ---
THEORETICAL_WORKERS=$(( (INPUT_CPU * 2) + 1 ))
# Safety Check: Can RAM handle these workers with the NEW Hard Limit?
# RAM Available = Total - Postgres(25%) - OS(1.5GB overhead for safety)
RAM_FOR_ODOO_GB=$(awk "BEGIN {printf \"%.2f\", $INPUT_RAM_GB - $PG_SHARED_BUFFERS_GB - 1.5}")
RAM_FOR_ODOO_MB=$(awk "BEGIN {printf \"%.0f\", $RAM_FOR_ODOO_GB * 1024}")
# Max Safe Workers based on the new 1152MB Hard Limit
MAX_SAFE_WORKERS=$(awk "BEGIN {printf \"%.0f\", $RAM_FOR_ODOO_MB / $WORKER_RAM_HARD_MB}")
# Decide Workers
if [ "$THEORETICAL_WORKERS" -le "$MAX_SAFE_WORKERS" ]; then
FINAL_WORKERS=$THEORETICAL_WORKERS
REASON="Limited by CPU formula"
else
FINAL_WORKERS=$MAX_SAFE_WORKERS
REASON="Limited by RAM (Using safer Hard Limit of ${WORKER_RAM_HARD_MB}MB)"
fi
# Fallback
if [ "$FINAL_WORKERS" -lt 2 ] && [ "$MAX_SAFE_WORKERS" -ge 1 ]; then
FINAL_WORKERS=2
REASON="Forced Minimum"
fi
# Bytes for .env
LIMIT_MEMORY_SOFT_BYTES=$(awk "BEGIN {printf \"%.0f\", $WORKER_RAM_SOFT_MB * 1024 * 1024}")
LIMIT_MEMORY_HARD_BYTES=$(awk "BEGIN {printf \"%.0f\", $WORKER_RAM_HARD_MB * 1024 * 1024}")
# ==============================================================================
# OUTPUT REPORT
# ==============================================================================
echo ""
log_info "CALCULATION RESULTS (OPTIMIZED FOR STABILITY)"
echo "---------------------------------------------------"
log_output " \033[1;36mSERVER RESOURCES:\033[0m"
log_output " • RAM Total: ${INPUT_RAM_GB} GB"
log_output " • CPU Cores: ${INPUT_CPU}"
echo ""
log_output " \033[1;35mPOSTGRESQL CONFIGURATION:\033[0m"
log_output " • shared_buffers = ${PG_SHARED_BUFFERS_MB}MB"
log_output " • effective_cache_size = ${PG_EFFECTIVE_CACHE_GB}GB"
echo ""
log_output " \033[1;35mODOO CONFIGURATION (.env):\033[0m"
log_output " • WORKERS = ${FINAL_WORKERS} ($REASON)"
log_output " • MAX_CRON_THREADS = 2"
log_output " • LIMIT_MEMORY_SOFT = ${LIMIT_MEMORY_SOFT_BYTES} (${WORKER_RAM_SOFT_MB} MB)"
log_output " • LIMIT_MEMORY_HARD = ${LIMIT_MEMORY_HARD_BYTES} (${WORKER_RAM_HARD_MB} MB)"
log_output " • LIMIT_TIME_CPU = 600"
log_output " • LIMIT_TIME_REAL = 1200"
echo "---------------------------------------------------"
echo ""
log_success "Use these values to fix the Fresh Browser crash."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment