Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions participantes/thiagoGomes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Submissão Teste Backend - Controle de Concorrência

<img src="https://upload.wikimedia.org/wikipedia/commons/c/c5/Nginx_logo.svg" alt="logo nginx" width="300" height="auto">
<br />
<img src="https://upload.wikimedia.org/wikipedia/commons/5/5d/Clojure_logo.svg" alt="logo clojure" width="200" height="auto">
<img src="https://upload.wikimedia.org/wikipedia/commons/2/29/Postgresql_elephant.svg" alt="logo postgres" width="200" height="auto">

## Thiago Gonçalves Gomes

Submissão feita com:

- `nginx` como load balancer
- `postgres` como banco de dados
- `Java` para api com `Spring`
- [repositório da api](https://github.com/Tenshyn/transactions)
69 changes: 69 additions & 0 deletions participantes/thiagoGomes/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
services:
api01: &api
image: tenshinran/test-backend:latest
hostname: api01
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/transaction
- SPRING_DATASOURCE_USERNAME=admin
- SPRING_DATASOURCE_PASSWORD=123
- SPRING_DATASOURCE_HIKARI_MAXIMUM-POOL-SIZE=10
- SPRING_DATASOURCE_HIKARI_MINIMUM-IDLE=5
- SERVER_PORT=3000
ports:
- "3001:3000"
depends_on:
- db
deploy:
resources:

limits:
cpus: "0.55"
memory: "200MB"

api02:
<<: *api
hostname: api02
ports:
- "3002:3000"

nginx:
image: nginx:latest
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- api01
- api02
ports:
- "9999:9999"
sysctls:
- net.ipv4.ip_local_port_range=10000 65535
- net.ipv4.tcp_tw_reuse=1
- net.ipv4.tcp_fin_timeout=30
deploy:
resources:
limits:
cpus: "0.15"
memory: "10MB"

db:
image: postgres:latest
hostname: db
environment:
- POSTGRES_PASSWORD=123
- POSTGRES_USER=admin
- POSTGRES_DB=transaction
ports:
- "5432:5432"
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
command: postgres -c checkpoint_timeout=600 -c max_wal_size=4096 -c synchronous_commit=0 -c full_page_writes=0
deploy:
resources:
limits:
cpus: "0.25"
memory: "140MB"

networks:
default:
driver: bridge
name: net-nginx-test-backend
24 changes: 24 additions & 0 deletions participantes/thiagoGomes/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE TABLE IF NOT EXISTS client (
id INT PRIMARY KEY,
client_limit INT NOT NULL,
balance INT NOT NULL
);

INSERT INTO client (id, client_limit, balance) VALUES (1, 100000, 0);
INSERT INTO client (id, client_limit, balance) VALUES (2, 80000, 0);
INSERT INTO client (id, client_limit, balance) VALUES (3, 1000000, 0);
INSERT INTO client (id, client_limit, balance) VALUES (4, 10000000, 0);
INSERT INTO client (id, client_limit, balance) VALUES (5, 500000, 0);

CREATE TABLE IF NOT EXISTS transaction (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
value INT NOT NULL,
type INT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
description VARCHAR(10),
client_id INT NOT NULL,
CONSTRAINT fk_client FOREIGN KEY (client_id) REFERENCES client(id)
);

CREATE INDEX idx_transaction_client_id ON transaction(client_id);
CREATE INDEX idx_transaction_created_at ON transaction(created_at DESC);
35 changes: 35 additions & 0 deletions participantes/thiagoGomes/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
events {
worker_connections 2000;
}

http {
access_log off;
sendfile on;

keepalive_timeout 65;
keepalive_requests 1000;

upstream api {
server api01:3000;
server api02:3000;
keepalive 64;
keepalive_requests 1000;
keepalive_timeout 60s;
}

server {
listen 9999;

location / {
proxy_pass http://api;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;

# Buffering
proxy_buffering on;
proxy_buffer_size 4k;
proxy_buffers 8 4k;
}
}
}