Skip to content

Conversation

@zaorinu
Copy link

@zaorinu zaorinu commented Jan 19, 2026

Automatic Cluster Optimization

The script now includes an intelligent cluster optimization system that can automatically determine the optimal number of worker clusters based on your system resources and account count, because sometimes people use like "99" clusters, even if the computer really doesn't have 99 clusters to be used, causing the script/machine to crash.

Why this should be implemented on this project? Simple, it's a way to simplify the configuration to users, ensuring they don't need to change cluster ammount manually to find her optimal results when using the script.

How It Works

The ClusterOptimizer analyzes:

  1. Number of Accounts: Targets 2 clusters per account (e.g., 4 accounts = up to 8 clusters)
  2. CPU Cores Available: Uses up to 100% of available CPU cores
  3. Available Memory: Allocates ~128MB per cluster + 512MB for main process (lightweight)

Configuration

Set "clusters": "auto" in your config.json to enable automatic optimization:

{
  "clusters": "auto"
}

Examples

Example 1: 4 Accounts, 8-Core CPU, 16GB RAM

  • Target from accounts: 8 (2 per account)
  • Max from CPU: 8 (100% of 8)
  • Max from memory: 32 (16GB = 16384MB, (16384 * 0.8) / 128 ≈ 102, minus 512MB for main)
  • Result: 8 clusters (fully utilized!)

Example 2: 2 Accounts, 2-Core CPU, 4GB RAM

  • Target from accounts: 4 (2 per account)
  • Max from CPU: 2 (100% of 2)
  • Max from memory: 12
  • Result: 2 clusters (limited by CPU)

Example 3: 10 Accounts, 4-Core CPU, 8GB RAM

  • Target from accounts: 20 (2 per account)
  • Max from CPU: 4 (100% of 4)
  • Max from memory: 12
  • Result: 4 clusters (limited by CPU)

Manual Configuration

To manually set cluster count, use any positive number:

{
  "clusters": 2
}

Logging Output

When auto-optimization ("clusters": "auto") is enabled, you'll see:

[INFO] CLUSTER-OPTIMIZATION - System Info | CPUs: 8 | Total Memory: 16384MB | Usable Memory: 13107MB
[INFO] CLUSTER-OPTIMIZATION - Automatic cluster calculation: 4 accounts → 4 clusters

Performance Tips

  • Docker/Container: Check available CPU and memory limits
  • VPS/Cloud: The script respects the container's cgroup limits
  • Desktop: Use "auto" for automatic optimization for best performance
  • Server: Monitor CPU and memory usage to fine-tune if needed

Fallback Behavior

  • If clusters: "auto" and no accounts are loaded, defaults to 1 cluster
  • Never creates 0 clusters; always creates at least 1
  • User-provided values (positive integers) always take precedence over auto-optimization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant