Gaston895 commited on
Commit
da4a637
·
verified ·
1 Parent(s): d4c04d4

Upload gunicorn_config.py

Browse files
Files changed (1) hide show
  1. gunicorn_config.py +23 -8
gunicorn_config.py CHANGED
@@ -1,6 +1,6 @@
1
  """
2
  Gunicorn configuration for AEGIS Economics AI
3
- Optimized for Hugging Face Spaces deployment
4
  """
5
 
6
  import multiprocessing
@@ -10,16 +10,16 @@ import os
10
  bind = "0.0.0.0:7860"
11
  backlog = 2048
12
 
13
- # Worker processes
14
- workers = 1 # Single worker for model loading efficiency
15
  worker_class = "sync"
16
  worker_connections = 1000
17
- timeout = 300 # 5 minutes for model loading
18
  keepalive = 2
19
 
20
- # Restart workers
21
- max_requests = 1000
22
- max_requests_jitter = 50
23
  preload_app = True
24
 
25
  # Logging
@@ -37,4 +37,19 @@ worker_tmp_dir = "/dev/shm" # Use shared memory for better performance
37
  # Security
38
  limit_request_line = 4094
39
  limit_request_fields = 100
40
- limit_request_field_size = 8190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  """
2
  Gunicorn configuration for AEGIS Economics AI
3
+ Optimized for Hugging Face Spaces deployment with memory constraints
4
  """
5
 
6
  import multiprocessing
 
10
  bind = "0.0.0.0:7860"
11
  backlog = 2048
12
 
13
+ # Worker processes - optimized for memory constraints
14
+ workers = 1 # Single worker to avoid memory issues
15
  worker_class = "sync"
16
  worker_connections = 1000
17
+ timeout = 600 # 10 minutes timeout for model inference
18
  keepalive = 2
19
 
20
+ # Restart workers to prevent memory leaks
21
+ max_requests = 50 # Restart more frequently to prevent memory buildup
22
+ max_requests_jitter = 10
23
  preload_app = True
24
 
25
  # Logging
 
37
  # Security
38
  limit_request_line = 4094
39
  limit_request_fields = 100
40
+ limit_request_field_size = 8190
41
+
42
+ # Graceful shutdown
43
+ graceful_timeout = 60
44
+
45
+ def when_ready(server):
46
+ server.log.info("AEGIS Economics AI server is ready. Listening on %s", server.address)
47
+
48
+ def worker_int(worker):
49
+ worker.log.info("Worker received INT or QUIT signal")
50
+
51
+ def pre_fork(server, worker):
52
+ server.log.info("Worker spawned (pid: %s)", worker.pid)
53
+
54
+ def post_fork(server, worker):
55
+ server.log.info("Worker spawned (pid: %s)", worker.pid)