Skip to content

Commit

Permalink
Merge pull request #13 from itujo/itujo
Browse files Browse the repository at this point in the history
submission: itujo
  • Loading branch information
zanfranceschi authored Feb 6, 2024
2 parents 7ac967c + 01b485f commit 6e7890b
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
17 changes: 17 additions & 0 deletions participantes/itujo/README.md
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
71 changes: 71 additions & 0 deletions participantes/itujo/docker-compose.yml
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
39 changes: 39 additions & 0 deletions participantes/itujo/init.sql
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;
$$;
28 changes: 28 additions & 0 deletions participantes/itujo/nginx.conf
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;
}
}
}

0 comments on commit 6e7890b

Please sign in to comment.