Samuraiog commited on
Commit
053e790
·
verified ·
1 Parent(s): 4ca9b24

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +25 -26
main.py CHANGED
@@ -35,46 +35,45 @@ app = FastAPI(
35
  CPU_COUNT = psutil.cpu_count(logical=True) or 8
36
  TOTAL_RAM_GB = psutil.virtual_memory().total / (1024 ** 3)
37
 
38
- # SMART AUTO-DETECTION based on actual system specs
39
- # Calculates optimal workers based on CPU cores AND available RAM
40
  def calculate_optimal_config():
41
  """Auto-calculate optimal configuration based on system resources."""
42
- # Base calculation: workers per core based on CPU count
 
 
43
  if CPU_COUNT >= 48:
44
- # Mega servers (48-128 cores)
45
- workers_per_core = 2048 # 64 cores = 131,072 workers
 
 
46
  elif CPU_COUNT >= 32:
47
  # High-end servers (32-47 cores)
48
- workers_per_core = 2560 # 32 cores = 81,920 workers
 
 
49
  elif CPU_COUNT >= 16:
50
  # Mid-range servers (16-31 cores)
51
- workers_per_core = 3072 # 16 cores = 49,152 workers
 
 
52
  elif CPU_COUNT >= 8:
53
  # Standard servers (8-15 cores)
54
- workers_per_core = 4096 # 8 cores = 32,768 workers
 
 
55
  elif CPU_COUNT >= 4:
56
  # Small servers (4-7 cores)
57
- workers_per_core = 6144 # 4 cores = 24,576 workers
 
 
58
  else:
59
  # Minimal systems (2-3 cores)
60
- workers_per_core = 8192 # 2 cores = 16,384 workers
61
-
62
- total_workers = CPU_COUNT * workers_per_core
63
 
64
- # Calculate process/thread split for optimal performance
65
- # More cores = more processes, fewer threads per process
66
- if CPU_COUNT >= 32:
67
- MAX_PROCESSES = CPU_COUNT * 2 # 128 procs for 64 cores
68
- THREADS_PER_PROCESS = total_workers // MAX_PROCESSES
69
- elif CPU_COUNT >= 16:
70
- MAX_PROCESSES = CPU_COUNT * 3
71
- THREADS_PER_PROCESS = total_workers // MAX_PROCESSES
72
- elif CPU_COUNT >= 8:
73
- MAX_PROCESSES = CPU_COUNT * 4
74
- THREADS_PER_PROCESS = total_workers // MAX_PROCESSES
75
- else:
76
- MAX_PROCESSES = CPU_COUNT * 2
77
- THREADS_PER_PROCESS = total_workers // MAX_PROCESSES
78
 
79
  return MAX_PROCESSES, THREADS_PER_PROCESS, total_workers
80
 
 
35
  CPU_COUNT = psutil.cpu_count(logical=True) or 8
36
  TOTAL_RAM_GB = psutil.virtual_memory().total / (1024 ** 3)
37
 
38
+ # REALISTIC AUTO-DETECTION - Respects OS thread limits
39
+ # Linux default: ~32K threads per process, ~unlimited processes
40
  def calculate_optimal_config():
41
  """Auto-calculate optimal configuration based on system resources."""
42
+ # MUCH MORE CONSERVATIVE: Max 200 threads per process to avoid hitting limits
43
+ # Focus on MORE PROCESSES with FEWER THREADS each
44
+
45
  if CPU_COUNT >= 48:
46
+ # Mega servers (48-128 cores) - 48 cores example
47
+ MAX_PROCESSES = CPU_COUNT * 6 # 288 processes
48
+ THREADS_PER_PROCESS = 200 # 200 threads each
49
+ # Total: 57,600 workers
50
  elif CPU_COUNT >= 32:
51
  # High-end servers (32-47 cores)
52
+ MAX_PROCESSES = CPU_COUNT * 8 # 256 processes for 32 cores
53
+ THREADS_PER_PROCESS = 250
54
+ # Total: 64,000 workers
55
  elif CPU_COUNT >= 16:
56
  # Mid-range servers (16-31 cores)
57
+ MAX_PROCESSES = CPU_COUNT * 12 # 192 processes for 16 cores
58
+ THREADS_PER_PROCESS = 300
59
+ # Total: 57,600 workers
60
  elif CPU_COUNT >= 8:
61
  # Standard servers (8-15 cores)
62
+ MAX_PROCESSES = CPU_COUNT * 16 # 128 processes for 8 cores
63
+ THREADS_PER_PROCESS = 400
64
+ # Total: 51,200 workers
65
  elif CPU_COUNT >= 4:
66
  # Small servers (4-7 cores)
67
+ MAX_PROCESSES = CPU_COUNT * 24 # 96 processes for 4 cores
68
+ THREADS_PER_PROCESS = 500
69
+ # Total: 48,000 workers
70
  else:
71
  # Minimal systems (2-3 cores)
72
+ MAX_PROCESSES = CPU_COUNT * 32 # 64 processes for 2 cores
73
+ THREADS_PER_PROCESS = 600
74
+ # Total: 38,400 workers
75
 
76
+ total_workers = MAX_PROCESSES * THREADS_PER_PROCESS
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  return MAX_PROCESSES, THREADS_PER_PROCESS, total_workers
79