-
Notifications
You must be signed in to change notification settings - Fork 933
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from itujo/itujo
submission: itujo
- Loading branch information
Showing
4 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Rinha de Backend 2024-Q1 | ||
|
||
### Ronaldo Junior | ||
|
||
Github: [@itujo](https://github.com/itujo) | ||
Repositório: [https://github.com/itujo/rinha-backend](https://github.com/itujo/rinha-backend) | ||
|
||
|
||
### Stack: Node com uWebSockets, Postgres | ||
- Node | ||
- uWebSockets | ||
- zod | ||
- drizzle | ||
- Postgres | ||
- Nginx | ||
|
||
100% success rate, 23ms mean response time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
version: "3.5" | ||
|
||
services: | ||
api01: &api | ||
image: itujo/rinha-backend-node-uws:latest | ||
hostname: api01 | ||
environment: | ||
- POSTGRES_USER=admin | ||
- POSTGRES_PASSWORD=123 | ||
- POSTGRES_DB=rinha | ||
- POSTGRES_HOST=db | ||
- PORT=3000 | ||
ports: | ||
- "3001:3000" | ||
depends_on: | ||
- db | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.45" | ||
memory: "200MB" | ||
|
||
api02: | ||
<<: *api | ||
hostname: api02 | ||
environment: | ||
- POSTGRES_USER=admin | ||
- POSTGRES_PASSWORD=123 | ||
- POSTGRES_DB=rinha | ||
- POSTGRES_HOST=db | ||
- PORT=3000 | ||
ports: | ||
- "3002:3000" | ||
|
||
nginx: | ||
image: nginx:latest | ||
volumes: | ||
- ./nginx.conf:/etc/nginx/nginx.conf:ro | ||
depends_on: | ||
- api01 | ||
- api02 | ||
ports: | ||
- "9999:9999" | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.15" | ||
memory: "10MB" | ||
|
||
db: | ||
image: postgres:latest | ||
hostname: db | ||
environment: | ||
- POSTGRES_PASSWORD=123 | ||
- POSTGRES_USER=admin | ||
- POSTGRES_DB=rinha | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- ./init.sql:/docker-entrypoint-initdb.d/init.sql | ||
command: postgres -c checkpoint_timeout=600 -c max_wal_size=4096 | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.45" | ||
memory: "140MB" | ||
|
||
networks: | ||
default: | ||
driver: bridge | ||
name: rinha-nginx-2024q1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
CREATE TABLE clientes ( | ||
id SERIAL PRIMARY KEY, | ||
nome VARCHAR(50) NOT NULL, | ||
limite INTEGER NOT NULL | ||
); | ||
|
||
CREATE TABLE transacoes ( | ||
id SERIAL PRIMARY KEY, | ||
cliente_id INTEGER NOT NULL, | ||
valor INTEGER NOT NULL, | ||
tipo CHAR(1) NOT NULL, | ||
descricao VARCHAR(10) NOT NULL, | ||
realizada_em TIMESTAMP NOT NULL DEFAULT NOW(), | ||
CONSTRAINT fk_clientes_transacoes_id | ||
FOREIGN KEY (cliente_id) REFERENCES clientes(id) | ||
); | ||
|
||
CREATE TABLE saldos ( | ||
id SERIAL PRIMARY KEY, | ||
cliente_id INTEGER NOT NULL, | ||
valor INTEGER NOT NULL, | ||
CONSTRAINT fk_clientes_saldos_id | ||
FOREIGN KEY (cliente_id) REFERENCES clientes(id) | ||
); | ||
|
||
DO $$ | ||
BEGIN | ||
INSERT INTO clientes (nome, limite) | ||
VALUES | ||
('o barato sai caro', 1000 * 100), | ||
('zan corp ltda', 800 * 100), | ||
('les cruders', 10000 * 100), | ||
('padaria joia de cocaia', 100000 * 100), | ||
('kid mais', 5000 * 100); | ||
|
||
INSERT INTO saldos (cliente_id, valor) | ||
SELECT id, 0 FROM clientes; | ||
END; | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
worker_processes auto; | ||
|
||
events { | ||
worker_connections 1000; | ||
} | ||
|
||
http { | ||
access_log off; | ||
sendfile on; | ||
|
||
upstream api { | ||
server api01:3000; | ||
server api02:3000; | ||
} | ||
|
||
server { | ||
listen 9999; | ||
|
||
location / { | ||
proxy_buffering off; | ||
proxy_set_header Connection ""; | ||
proxy_http_version 1.1; | ||
proxy_set_header Keep-Alive ""; | ||
proxy_set_header Proxy-Connection "keep-alive"; | ||
proxy_pass http://api; | ||
} | ||
} | ||
} |