perf: optimize Twenty CRM resource usage
- Reduce defaults: 4 CPU/8GB → 2 CPU/4GB (official min is 2GB) - Node.js heap: 512MB server, 384MB worker (runtime) - Build-time heap: 3072MB (only during compilation) - PG pool: reduce to 5 connections - PostgreSQL: tune shared_buffers/work_mem/effective_cache_size - Redis: cap at 64MB with noeviction policy - Unset NODE_OPTIONS after build to not leak into runtime
This commit is contained in:
parent
5ab302102b
commit
fe48d08c69
@ -8,8 +8,8 @@ source <(curl -fsSL "$COMMUNITY_SCRIPTS_URL/misc/build.func")
|
|||||||
|
|
||||||
APP="Twenty"
|
APP="Twenty"
|
||||||
var_tags="${var_tags:-crm;business;contacts}"
|
var_tags="${var_tags:-crm;business;contacts}"
|
||||||
var_cpu="${var_cpu:-4}"
|
var_cpu="${var_cpu:-2}"
|
||||||
var_ram="${var_ram:-8192}"
|
var_ram="${var_ram:-4096}"
|
||||||
var_disk="${var_disk:-20}"
|
var_disk="${var_disk:-20}"
|
||||||
var_os="${var_os:-debian}"
|
var_os="${var_os:-debian}"
|
||||||
var_version="${var_version:-13}"
|
var_version="${var_version:-13}"
|
||||||
@ -51,11 +51,12 @@ function update_script() {
|
|||||||
export COREPACK_ENABLE_DOWNLOAD_PROMPT=0
|
export COREPACK_ENABLE_DOWNLOAD_PROMPT=0
|
||||||
$STD corepack enable
|
$STD corepack enable
|
||||||
$STD corepack prepare yarn@4.9.2 --activate
|
$STD corepack prepare yarn@4.9.2 --activate
|
||||||
export NODE_OPTIONS="--max-old-space-size=4096"
|
export NODE_OPTIONS="--max-old-space-size=3072"
|
||||||
$STD yarn install --immutable || $STD yarn install
|
$STD yarn install --immutable || $STD yarn install
|
||||||
$STD npx nx run twenty-server:build
|
$STD npx nx run twenty-server:build
|
||||||
$STD npx nx build twenty-front
|
$STD npx nx build twenty-front
|
||||||
cp -r /opt/twenty/packages/twenty-front/build /opt/twenty/packages/twenty-server/dist/front
|
cp -r /opt/twenty/packages/twenty-front/build /opt/twenty/packages/twenty-server/dist/front
|
||||||
|
unset NODE_OPTIONS
|
||||||
msg_ok "Built Application"
|
msg_ok "Built Application"
|
||||||
|
|
||||||
msg_info "Running Database Migrations"
|
msg_info "Running Database Migrations"
|
||||||
|
|||||||
@ -19,8 +19,8 @@
|
|||||||
"type": "default",
|
"type": "default",
|
||||||
"script": "ct/twenty.sh",
|
"script": "ct/twenty.sh",
|
||||||
"resources": {
|
"resources": {
|
||||||
"cpu": 4,
|
"cpu": 2,
|
||||||
"ram": 8192,
|
"ram": 4096,
|
||||||
"hdd": 20,
|
"hdd": 20,
|
||||||
"os": "Debian",
|
"os": "Debian",
|
||||||
"version": "13"
|
"version": "13"
|
||||||
|
|||||||
@ -30,11 +30,12 @@ cd /opt/twenty
|
|||||||
export COREPACK_ENABLE_DOWNLOAD_PROMPT=0
|
export COREPACK_ENABLE_DOWNLOAD_PROMPT=0
|
||||||
$STD corepack enable
|
$STD corepack enable
|
||||||
$STD corepack prepare yarn@4.9.2 --activate
|
$STD corepack prepare yarn@4.9.2 --activate
|
||||||
export NODE_OPTIONS="--max-old-space-size=4096"
|
export NODE_OPTIONS="--max-old-space-size=3072"
|
||||||
$STD yarn install --immutable || $STD yarn install
|
$STD yarn install --immutable || $STD yarn install
|
||||||
$STD npx nx run twenty-server:build
|
$STD npx nx run twenty-server:build
|
||||||
$STD npx nx build twenty-front
|
$STD npx nx build twenty-front
|
||||||
cp -r /opt/twenty/packages/twenty-front/build /opt/twenty/packages/twenty-server/dist/front
|
cp -r /opt/twenty/packages/twenty-front/build /opt/twenty/packages/twenty-server/dist/front
|
||||||
|
unset NODE_OPTIONS
|
||||||
msg_ok "Built Application"
|
msg_ok "Built Application"
|
||||||
|
|
||||||
msg_info "Configuring Application"
|
msg_info "Configuring Application"
|
||||||
@ -43,6 +44,7 @@ mkdir -p /opt/twenty/packages/twenty-server/.local-storage
|
|||||||
cat <<EOF >/opt/twenty/.env
|
cat <<EOF >/opt/twenty/.env
|
||||||
NODE_PORT=3000
|
NODE_PORT=3000
|
||||||
PG_DATABASE_URL=postgresql://${PG_DB_USER}:${PG_DB_PASS}@localhost:5432/${PG_DB_NAME}
|
PG_DATABASE_URL=postgresql://${PG_DB_USER}:${PG_DB_PASS}@localhost:5432/${PG_DB_NAME}
|
||||||
|
PG_POOL_MAX_CONNECTIONS=5
|
||||||
REDIS_URL=redis://localhost:6379
|
REDIS_URL=redis://localhost:6379
|
||||||
SERVER_URL=http://${LOCAL_IP}:3000
|
SERVER_URL=http://${LOCAL_IP}:3000
|
||||||
APP_SECRET=${APP_SECRET}
|
APP_SECRET=${APP_SECRET}
|
||||||
@ -51,6 +53,23 @@ NODE_ENV=production
|
|||||||
EOF
|
EOF
|
||||||
msg_ok "Configured Application"
|
msg_ok "Configured Application"
|
||||||
|
|
||||||
|
msg_info "Tuning Services"
|
||||||
|
# Redis: cap memory at 64MB with LRU eviction
|
||||||
|
cat <<EOF >>/etc/redis/redis.conf
|
||||||
|
maxmemory 64mb
|
||||||
|
maxmemory-policy noeviction
|
||||||
|
EOF
|
||||||
|
systemctl restart redis-server
|
||||||
|
|
||||||
|
# PostgreSQL: optimize for low-memory LXC
|
||||||
|
PG_CONF="/etc/postgresql/16/main/postgresql.conf"
|
||||||
|
sed -i "s/^shared_buffers.*/shared_buffers = 128MB/" "$PG_CONF"
|
||||||
|
sed -i "s/^#work_mem.*/work_mem = 4MB/" "$PG_CONF"
|
||||||
|
sed -i "s/^#effective_cache_size.*/effective_cache_size = 256MB/" "$PG_CONF"
|
||||||
|
sed -i "s/^#maintenance_work_mem.*/maintenance_work_mem = 64MB/" "$PG_CONF"
|
||||||
|
systemctl restart postgresql
|
||||||
|
msg_ok "Tuned Services"
|
||||||
|
|
||||||
msg_info "Running Database Migrations"
|
msg_info "Running Database Migrations"
|
||||||
cd /opt/twenty/packages/twenty-server
|
cd /opt/twenty/packages/twenty-server
|
||||||
set -a && source /opt/twenty/.env && set +a
|
set -a && source /opt/twenty/.env && set +a
|
||||||
@ -71,6 +90,7 @@ User=root
|
|||||||
WorkingDirectory=/opt/twenty/packages/twenty-server
|
WorkingDirectory=/opt/twenty/packages/twenty-server
|
||||||
EnvironmentFile=/opt/twenty/.env
|
EnvironmentFile=/opt/twenty/.env
|
||||||
ExecStart=/usr/bin/node dist/main
|
ExecStart=/usr/bin/node dist/main
|
||||||
|
Environment=NODE_OPTIONS=--max-old-space-size=512
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
|
|
||||||
@ -92,6 +112,7 @@ EnvironmentFile=/opt/twenty/.env
|
|||||||
Environment=DISABLE_DB_MIGRATIONS=true
|
Environment=DISABLE_DB_MIGRATIONS=true
|
||||||
Environment=DISABLE_CRON_JOBS_REGISTRATION=true
|
Environment=DISABLE_CRON_JOBS_REGISTRATION=true
|
||||||
ExecStart=/usr/bin/node dist/queue-worker/queue-worker
|
ExecStart=/usr/bin/node dist/queue-worker/queue-worker
|
||||||
|
Environment=NODE_OPTIONS=--max-old-space-size=384
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user