rkihacker commited on
Commit
5ea344f
·
verified ·
1 Parent(s): cf3a924

Update gunicorn_config.py

Browse files
Files changed (1) hide show
  1. gunicorn_config.py +12 -17
gunicorn_config.py CHANGED
@@ -1,31 +1,26 @@
1
- # Gunicorn configuration file
2
 
3
  # --- Server Socket ---
4
- # Bind to all network interfaces on port 8000.
5
- # This is required for containerized environments.
6
  bind = "0.0.0.0:8000"
7
 
8
  # --- Worker Processes ---
9
- # Based on (2 * number_of_cpus) + 1 for your 2 CPU container.
10
- workers = 5
11
 
12
- # Use Uvicorn's worker class for async applications.
13
  worker_class = "uvicorn.workers.UvicornWorker"
14
 
15
- # The maximum number of simultaneous clients that a single worker can handle.
16
- worker_connections = 1000
17
 
18
- # The maximum number of requests a worker will process before restarting.
19
- # This helps prevent memory leaks in long-running applications.
20
- max_requests = 2048
21
-
22
- # Add a random jitter to max_requests to prevent all workers from restarting at once.
23
- max_requests_jitter = 512
24
 
25
  # --- Logging ---
26
  loglevel = "info"
27
- accesslog = "-" # Log to stdout
28
- errorlog = "-" # Log to stderr
29
 
30
  # --- Process Naming ---
31
- proc_name = "fastapi_reverse_proxy"
 
1
+ import multiprocessing
2
 
3
  # --- Server Socket ---
 
 
4
  bind = "0.0.0.0:8000"
5
 
6
  # --- Worker Processes ---
7
+ # Dynamically calculate based on CPU count
8
+ workers = multiprocessing.cpu_count() * 2 + 1
9
 
10
+ # For async FastAPI apps
11
  worker_class = "uvicorn.workers.UvicornWorker"
12
 
13
+ # Use a high but safe connection limit
14
+ worker_connections = 100000
15
 
16
+ # Disable forced restarts (optional, not recommended for memory-leaky apps)
17
+ max_requests = 0
18
+ max_requests_jitter = 0
 
 
 
19
 
20
  # --- Logging ---
21
  loglevel = "info"
22
+ accesslog = "-"
23
+ errorlog = "-"
24
 
25
  # --- Process Naming ---
26
+ proc_name = "fastapi_reverse_proxy"