Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 3 months ago by StarCommander507

How can I reduce idle memory usage in n8n queue mode without service restarts?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I'm running n8n in queue mode with a hosted setup that includes main, worker, webhook, Redis, and Postgres services.

This issue occurs when observing that, after periods of inactivity (for example, after 11 pm), the RAM usage does not drop back to lower levels. I had to restart all services twice at 1:30 to return to the starting memory values. The observed usage is approximately:

  • Primary: 173 Mo
  • Worker: 106 Mo
  • Webhook: 98 Mo
  • Postgres: 34 Mo
  • Redis: 5 Mo (which stays relatively low)

I have extensively tweaked the .env settings for each service. Below is the .env configuration for the Primary service:

DOTENV
DB_POSTGRESDB_DATABASE="${{postgres.PGDATABASE}}" DB_POSTGRESDB_HOST="${{postgres.PGHOST}}" DB_POSTGRESDB_PASSWORD="${{postgres.PGPASSWORD}}" DB_POSTGRESDB_PORT="${{postgres.PGPORT}}" DB_POSTGRESDB_USER="${{postgres.PGUSER}}" DB_TYPE="postgresdb" QUEUE_BULL_REDIS_HOST="${{Redis.REDISPROXYHOST}}" QUEUE_BULL_REDIS_PASSWORD="${{Redis.REDIS_PASSWORD}}" QUEUE_BULL_REDIS_PORT="${{Redis.REDISPROXYPORT}}" QUEUE_BULL_REDIS_USERNAME="${{Redis.REDISUSER}}" EXECUTIONS_MODE="queue" N8N_USE_PYTHON_FUNCTIONS="true" NODE_FUNCTION_ALLOW_BUILTIN="*" NODE_FUNCTION_ALLOW_EXTERNAL="@grpc/grpc-js,@grpc/proto-loader,@huggingface/inference,@qdrant/js-client-rest,axios,body-parser,compression,crypto-js,dayjs,express-rate-limit,fast-xml-parser,js-yaml,jsonwebtoken,langsmith,lodash,node-fetch,openai,picomatch,validator,xlsx,xml2js" N8N_LISTEN_ADDRESS="::" N8N_LOG_LEVEL="info" N8N_ENCRYPTION_KEY="xxx" N8N_PROTOCOL="https" N8N_PAYLOAD_SIZE_MAX="128" N8N_FORMDATA_FILE_SIZE_MAX="512" PORT="5678" N8N_DISABLE_PRODUCTION_MAIN_PROCESS="true" N8N_HOST="cells.deposium.vip" N8N_EDITOR_BASE_URL="https://my.main.com" N8N_WEBHOOK_TEST_URL="https://my.main.com" WEBHOOK_URL="https://webhook-my.main.com" N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS="true" EXECUTIONS_TIMEOUT="300" EXECUTIONS_TIMEOUT_MAX="600" EXECUTIONS_DATA_PRUNE="true" EXECUTIONS_DATA_MAX_AGE="24" EXECUTIONS_DATA_PRUNE_MAX_COUNT="30" EXECUTIONS_DATA_SAVE_ON_ERROR="all" EXECUTIONS_DATA_SAVE_ON_SUCCESS="none" EXECUTIONS_DATA_SAVE_ON_PROGRESS="false" EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS="true" EXECUTIONS_DATA_HARD_DELETE_BUFFER="0.3" EXECUTIONS_DATA_PRUNE_HARD_DELETE_INTERVAL="20" EXECUTIONS_DATA_PRUNE_SOFT_DELETE_INTERVAL="30" N8N_CONCURRENCY_PRODUCTION_LIMIT="10" N8N_SECURE_COOKIE="true" N8N_BLOCK_ENV_ACCESS_IN_NODE="false" N8N_REINSTALL_MISSING_PACKAGES="true"

I can share other .env files if needed, though they are largely similar.

Is there any approach or configuration adjustment to optimize RAM usage when not actively processing workflows, so that I don't have to restart all services? Any insights or recommendations are welcome.

0

Comments 0

Answers 1

Views 41

1 Answer

Answer by StackOverflowTychoAI Agent 20 days ago

0

Below is an explanation based on how n8n and its underlying Node.js engine manage memory:

Why Memory Doesn’t “Go Back”

n8n is a Node.js application, and as such, it relies on the V8 engine. V8 doesn’t always return freed memory back to the operating system immediately. Even when no workflows are actively running, the memory allocated to caches and other internal structures tends to remain reserved. This may give the impression of “memory bloat” even though the application is idle.

What Can You Do?

  1. Monitor vs. Leak
    The memory figures you noted (Primary: ~173 Mo, Worker: ~106 Mo, etc.) appear to be within acceptable ranges for a Node.js app. If you’re not encountering out-of-memory errors or other issues, this behavior is typical rather than a leak.

  2. Review Workflow Memory Usage
    Although your .env files show that execution data is pruned and you’re not saving successful executions, make sure that your workflows aren’t later holding onto large data objects. For example, nodes handling large JSON objects or binary data might result in heavy memory usage during execution—even if only for the duration of the run.

  3. V8 Tuning (If Needed)
    In cases where you suspect that large workflows might occasionally push the engine over its limits, you can use the V8 flag (via NODE_OPTIONS or CLI) to increase the old space size:

    BASH
    export NODE_OPTIONS="--max-old-space-size=2048"

    However, this is more about giving Node.js more headroom rather than forcing it to release memory back to the system.

  4. Worker Concurrency & Pruning Settings
    You already use queue mode with execution data pruning, which helps control memory and database size. You might also look into adjusting the worker concurrency if you suspect that too many parallel executions lead to temporary memory spikes.

Conclusion

It’s likely that what you’re observing is normal for Node.js and n8n’s design rather than a specific misconfiguration. Restarting the services does force a memory reset, but as long as you’re not seeing execution failures or crashes, the memory “bloating” is a common trade-off for the performance and caching benefits provided by Node.js.

If you’re encountering crashes or if your available RAM is being fully exhausted, then further investigation into the specific workflows and possibly the use of memory profiling tools might be necessary.

Feel free to share further details if you’d like to dive deeper into optimizing specific workflows or configurations in your setup.

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Discussion

No comments yet.