-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
Signed-off-by: Guilherme Mafra da Costa <[email protected]>
- Loading branch information
Showing
95 changed files
with
6,514 additions
and
952 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,21 @@ | ||
# Specifies a parent image | ||
FROM golang:1.22.0-alpine3.19 | ||
|
||
# Creates an app directory to hold your app’s source code | ||
WORKDIR /app | ||
ADD . /app | ||
|
||
# Copies everything from your root directory into /app | ||
COPY . . | ||
|
||
# Installs Go dependencies | ||
RUN go mod download | ||
|
||
# Builds your app with optional configuration | ||
RUN go build -o /godocker | ||
|
||
# Tells Docker which network port your container listens on | ||
EXPOSE 8080 | ||
|
||
# Specifies the executable command that runs when the container starts | ||
CMD [ "/godocker" ] |
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
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,7 @@ | ||
# entrega no rinha de backend | ||
|
||
- nome: estêvão ruas | ||
- tecnologias: | ||
- go (com gin e gorm) | ||
- postgresql | ||
- nginx |
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,97 @@ | ||
version: "3.5" | ||
|
||
services: | ||
api01: &api | ||
# Lembre-se de que seu serviço HTTP deve estar hospedado num repositório | ||
# publicamente acessível! Ex.: hub.docker.com | ||
image: legustalagosta/rinha-api:no-gin | ||
hostname: api01 | ||
environment: | ||
- DB_HOSTNAME=db | ||
- DB_PORT=5432 | ||
- DB_DATABASE=rinha | ||
- DB_USER=admin | ||
- DB_PASSWORD=123 | ||
|
||
# Não é necessário expor qualquer porta além da porta do load balancer, | ||
# mas é comum as pessoas o fazerem para testarem suas APIs e conectarem | ||
# ao banco de dados na fase de desenvolvimento. | ||
ports: | ||
- "8081:8080" | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.35" | ||
memory: "60MB" | ||
|
||
api02: | ||
# Essa sintaxe reusa o que foi declarado em 'api01'. | ||
<<: *api | ||
hostname: api02 | ||
environment: | ||
- DB_HOSTNAME=db | ||
- DB_PORT=5432 | ||
- DB_DATABASE=rinha | ||
- DB_USER=admin | ||
- DB_PASSWORD=123 | ||
ports: | ||
- "8082:8080" | ||
|
||
nginx: | ||
image: nginx:latest | ||
volumes: | ||
- ./nginx.conf:/etc/nginx/nginx.conf:ro | ||
depends_on: | ||
- api01 | ||
- api02 | ||
ports: | ||
# Obrigatório expor/usar a porta 9999 no load balancer! | ||
- "9999:9999" | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.25" | ||
memory: "60MB" | ||
|
||
db: | ||
image: postgres:latest | ||
hostname: db | ||
environment: | ||
- POSTGRES_PASSWORD=123 | ||
- POSTGRES_USER=admin | ||
- POSTGRES_DB=rinha | ||
ports: | ||
- "5432:5432" | ||
restart: always | ||
healthcheck: | ||
test: "pg_isready -U admin -d rinha" | ||
interval: 5s | ||
timeout: 5s | ||
retries: 5 | ||
volumes: | ||
- ./sql/script.sql:/docker-entrypoint-initdb.d/script.sql | ||
- ./postgresql.conf:/etc/postgresql/postgresql.conf:ro | ||
command: ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"] | ||
deploy: | ||
resources: | ||
limits: | ||
# Note que a soma de todos os limites dos serviços | ||
# aqui declarados é de 1.5 unidades de CPU e 550MB | ||
# de memória. A distribuição feita aqui é apenas | ||
# um exemplo – distribua como quiser. | ||
cpus: "0.55" | ||
memory: "370MB" | ||
|
||
# O uso do modo `bridge` deve ser adequado à carga que será usada no teste. | ||
# A edição anterior se beneficiou do modo host pois o volume de requisições | ||
# era relativamente alto e a virtualização da rede se tornou um gargalo, mas | ||
# este modo é mais complexo de ser configurado. Fique à vontade para usar o | ||
# modo que quiser desde que não conflite com portas trivialmente usadas em um | ||
# SO. | ||
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,64 @@ | ||
worker_processes auto; | ||
worker_rlimit_nofile 32768; | ||
# worker_rlimit_nofile 20000; | ||
|
||
events { | ||
worker_connections 16384; # Adjusted to fit within memory constraint | ||
# worker_connections 20000; # Adjusted to fit within memory constraint | ||
multi_accept on; # Enable multiple accept calls to handle more connections efficiently | ||
use epoll; # Use epoll event notification mechanism for better performance on Linux | ||
} | ||
|
||
http { | ||
sendfile on; | ||
tcp_nopush on; | ||
tcp_nodelay on; | ||
keepalive_timeout 5; # Reduced to reclaim connections faster | ||
|
||
# Buffer sizes reduced to fit within memory constraint | ||
# client_body_buffer_size 4k; | ||
# client_max_body_size 10m; | ||
# client_header_buffer_size 1k; | ||
# large_client_header_buffers 2 1k; | ||
client_body_buffer_size 2k; | ||
client_max_body_size 2k; | ||
client_header_buffer_size 1k; | ||
large_client_header_buffers 2 1k; | ||
|
||
# Disable logging or set to a minimal level | ||
access_log off; # Turn off access logging to save resources | ||
# error_log /var/log/nginx/error.log crit; # Set error log level to 'crit' for critical errors only | ||
|
||
# Gzip compression disabled due to memory constraint | ||
gzip off; | ||
|
||
# Load balancing configuration for API servers | ||
upstream api { | ||
server api01:8080; | ||
server api02:8080; | ||
keepalive 500; | ||
} | ||
|
||
server { | ||
listen 9999; # Lembra da porta 9999 obrigatória? | ||
|
||
location / { | ||
proxy_pass http://api; | ||
proxy_http_version 1.1; | ||
|
||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
# proxy_set_header Connection ""; | ||
# proxy_set_header Keep-Alive ""; | ||
# proxy_set_header Proxy-Connection "keep-alive"; | ||
|
||
# Buffer requests and responses above a certain size | ||
proxy_buffering on; | ||
proxy_buffer_size 12k; # Buffer size for proxied request or response | ||
proxy_buffers 4 8k; # Number and size of buffers for proxied request or response | ||
# proxy_buffering off; | ||
} | ||
} | ||
} |
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,37 @@ | ||
# General Settings | ||
listen_addresses = '*' # Listen on all interfaces | ||
max_connections = 1024 # Maximum concurrent connections (adjust according to your system's capacity) | ||
shared_buffers = 32MB # Amount of memory used for caching data (reduced to fit within memory constraint) | ||
work_mem = 8MB # Amount of memory used for internal sort operations | ||
maintenance_work_mem = 64MB # Amount of memory used for maintenance tasks like VACUUM, CREATE INDEX | ||
# wal_level = minimal # Set WAL level to 'minimal' for reduced write overhead | ||
wal_level = replica # Set WAL level to 'replica' for replication support | ||
synchronous_commit = off # Asynchronous commit for better performance | ||
checkpoint_timeout = 5min # Interval between automatic WAL checkpoints (reduced for more frequent checkpoints) | ||
checkpoint_completion_target = 0.7 # Target duration for completing checkpoints | ||
|
||
# Autovacuum Settings | ||
autovacuum = on # Enable autovacuum | ||
autovacuum_max_workers = 2 # Maximum number of autovacuum worker processes | ||
autovacuum_naptime = 1min # Time between autovacuum runs | ||
autovacuum_vacuum_scale_factor = 0.05 # Threshold to trigger a VACUUM | ||
autovacuum_analyze_scale_factor = 0.02 # Threshold to trigger an ANALYZE | ||
|
||
# Logging | ||
# log_statement = 'all' # Log all SQL statements | ||
# log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d,app=%a,client=%h ' # Customize log line format | ||
# log_min_duration_statement = 200 # Log SQL statements longer than 200ms | ||
|
||
# Logging | ||
log_statement = 'none' # Disable logging of SQL statements to save resources | ||
log_connections = off # Turn off logging of successful connections | ||
log_disconnections = off # Turn off logging of disconnections | ||
|
||
# Connection Settings | ||
tcp_keepalives_idle = 60 # TCP keepalives idle time | ||
tcp_keepalives_interval = 5 # TCP keepalives interval | ||
tcp_keepalives_count = 5 # TCP keepalives count | ||
|
||
# Other Settings | ||
effective_cache_size = 100MB # Estimate of how much memory is available for caching data (reduced to fit within memory constraint) | ||
random_page_cost = 2.0 # Relative cost of a non-sequentially fetched disk page compared to a page fetched sequentially |
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,22 @@ | ||
create table clientes ( | ||
id serial primary key, | ||
limite integer, | ||
saldo integer | ||
); | ||
|
||
create table transacoes ( | ||
id serial primary key, | ||
valor integer, | ||
tipo varchar(1), | ||
descricao varchar(20), | ||
data_transacao timestamp, | ||
id_cliente integer references clientes(id) | ||
); | ||
|
||
create index on transacoes (id_cliente); | ||
|
||
insert into clientes (limite, saldo) values (100000, 0); | ||
insert into clientes (limite, saldo) values (80000, 0); | ||
insert into clientes (limite, saldo) values (1000000, 0); | ||
insert into clientes (limite, saldo) values (10000000, 0); | ||
insert into clientes (limite, saldo) values (500000, 0); |
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,22 @@ | ||
# Submissão para Rinha de Backend, Segunda Edição: 2024/Q1 - Controle de Concorrência | ||
|
||
<div style="display: flex; align-items: center; gap: 12px"> | ||
<img src="https://upload.wikimedia.org/wikipedia/en/thumb/3/30/Java_programming_language_logo.svg/800px-Java_programming_language_logo.svg.png" alt="logo java" width="50" height="auto"> | ||
<img src="https://upload.wikimedia.org/wikipedia/commons/2/29/Postgresql_elephant.svg" alt="logo postgres" width="50" height="auto"> | ||
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c5/Nginx_logo.svg" alt="logo nginx" width="100" height="auto"> | ||
<br /> | ||
</div> | ||
|
||
## Adriano Souza Arruda | ||
|
||
Submissão feita com: | ||
|
||
- `nginx` como load balancer | ||
- `postgres` como banco de dados | ||
- `java` para api com os frameworks `quarkus` e `hibernate` | ||
- [repositório da api](https://github.com/adrianog3/rinha-backend-2024-q1-java) | ||
|
||
|
||
### Contato | ||
- [adrianog3](https://www.linkedin.com/in/adrianog3/) - linkedin | ||
- [@adriano_g5](https://twitter.com/adriano_g5) - twitter |
Oops, something went wrong.