Skip to content

Commit 4fd6e7c

Browse files
authored
Merge pull request #462 from ropable/master
Gunicorn reconfiguration to use native ASGI worker
2 parents ec2f766 + 06212bd commit 4fd6e7c

File tree

6 files changed

+18
-203
lines changed

6 files changed

+18
-203
lines changed

gunicorn.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# Gunicorn configuration settings.
2-
import multiprocessing
32

43
bind = ":8080"
5-
# Don't start too many workers:
6-
workers = min(multiprocessing.cpu_count(), 4)
7-
# Give workers an expiry:
4+
workers = 4
5+
worker_connections = 1000 # Max connections per worker
86
max_requests = 2048
97
max_requests_jitter = 256
108
preload_app = True
11-
# Set longer timeout for workers
12-
timeout = 180
9+
keepalive = 5 # Keepalive timeout
10+
timeout = 180 # Worker timeout
11+
graceful_timeout = 30 # Graceful shutdown timeout
1312
# Disable access logging.
1413
accesslog = None
15-
# Use UvicornWorker as the worker class.
16-
worker_class = "resource_tracking.workers.UvicornWorker"
14+
15+
# asgi configuration
16+
worker_class = "asgi"
17+
asgi_loop = "auto" # Uses uvloop if available
18+
asgi_lifespan = "auto" # Auto-detect lifespan support
19+
control_socket = "/tmp/gunicorn.ctl"

kustomize/base/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ spec:
2525
resources:
2626
requests:
2727
memory: '100Mi'
28-
cpu: '5m'
28+
cpu: '10m'
2929
limits:
3030
memory: '2Gi'
3131
cpu: '1000m'

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ dependencies = [
2525
"sentry-sdk[django]==2.53.0",
2626
"django-geojson==4.2.0",
2727
"azure-storage-blob==12.28.0",
28-
"uvicorn[standard]==0.41.0",
29-
"uvicorn-worker==0.4.0",
3028
"orjson==3.11.7",
3129
"django-crispy-forms==2.5",
3230
"crispy-bootstrap5==2025.6",
3331
"h11==0.16",
3432
"django-tastypie==0.15.1",
3533
"fudgeo==1.5.4",
34+
"uvloop==0.22.1",
3635
]
3736

3837
[dependency-groups]

resource_tracking/workers.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

tracking/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ class DeviceStream(View):
762762
view_is_async = True
763763

764764
async def stream(self, *args, **kwargs):
765-
"""Returns an iterator that queries and then yields tracking device data every n seconds."""
765+
"""Returns an iterator that runs forever, queries and then yields tracking device data every n seconds."""
766766
last_location = None
767767
device = None
768768

@@ -803,7 +803,7 @@ async def stream(self, *args, **kwargs):
803803
async def get(self, request, *args, **kwargs):
804804
# Returns a streaming HTTP response that is consumed by the EventSource instance on the client.
805805
return StreamingHttpResponse(
806-
self.stream(*args, **kwargs),
806+
streaming_content=self.stream(*args, **kwargs),
807807
content_type="text/event-stream",
808808
headers={
809809
# The Cache-Control header need to be set thus to work behind Fastly caching.

0 commit comments

Comments
 (0)