diff --git a/participantes/thiagoGomes/README.md b/participantes/thiagoGomes/README.md new file mode 100644 index 0000000..13bd4ba --- /dev/null +++ b/participantes/thiagoGomes/README.md @@ -0,0 +1,15 @@ +# Submissão Teste Backend - Controle de Concorrência + +logo nginx +
+logo clojure +logo postgres + +## 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) diff --git a/participantes/thiagoGomes/docker-compose.yml b/participantes/thiagoGomes/docker-compose.yml new file mode 100644 index 0000000..adcf049 --- /dev/null +++ b/participantes/thiagoGomes/docker-compose.yml @@ -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 diff --git a/participantes/thiagoGomes/init.sql b/participantes/thiagoGomes/init.sql new file mode 100644 index 0000000..77b86bf --- /dev/null +++ b/participantes/thiagoGomes/init.sql @@ -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); diff --git a/participantes/thiagoGomes/nginx.conf b/participantes/thiagoGomes/nginx.conf new file mode 100644 index 0000000..20fdb4e --- /dev/null +++ b/participantes/thiagoGomes/nginx.conf @@ -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; + } + } +} \ No newline at end of file