Skip to content

Commit

Permalink
feat: add gunicorn and gevent
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelpadovezi committed Feb 26, 2024
1 parent 37b8f8f commit 7e3edd7
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
!poetry.lock
!pyproject.toml
!manage.py
!rinha/**
!rinha/**
!gunicorn.conf.py
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ COPY --from=builder /usr/local/bin /usr/local/bin

COPY . .

ENTRYPOINT ["python", "manage.py", "runserver", "0:8080"]
ENTRYPOINT ["gunicorn", "rinha.wsgi", "-b", "0:8080"]
2 changes: 1 addition & 1 deletion conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
events {
worker_connections 512;
worker_connections 1024;
}

http {
Expand Down
14 changes: 12 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ services:
deploy:
resources:
limits:
cpus: "0.5"
cpus: "0.4"
memory: "200MB"
command: postgres -c max_connections=100
command: postgres -c max_connections=500
healthcheck:
test:
[
Expand Down Expand Up @@ -46,6 +46,11 @@ services:
condition: service_healthy
environment:
- DB_HOST=db
deploy:
resources:
limits:
cpus: "0.47"
memory: "165MB"
api2:
<<: *api1
hostname: api2
Expand All @@ -60,3 +65,8 @@ services:
depends_on:
- api1
- api2
deploy:
resources:
limits:
cpus: "0.16"
memory: "20MB"
7 changes: 7 additions & 0 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from gevent import monkey
import multiprocessing

monkey.patch_all()

workers = 4
worker_class = "gevent"
329 changes: 328 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ python = "^3.12"
django = "^5.0.2"
django-rest-framework = "^0.1.0"
psycopg = {extras = ["binary", "pool"], version = "^3.1.18"}
gevent = "^24.2.1"
gunicorn = "^21.2.0"


[build-system]
Expand Down
5 changes: 5 additions & 0 deletions rinha/settings.py
Original file line number Diff line number Diff line change