-
Notifications
You must be signed in to change notification settings - Fork 932
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 #47 from leoralph/main
Enviar submissão leoralph
- Loading branch information
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
# Submissão para Rinha de Backend, Segunda Edição: 2024/Q1 - 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/2/27/PHP-logo.svg" alt="logo php" width="200" height="auto"> | ||
<img src="https://upload.wikimedia.org/wikipedia/commons/2/29/Postgresql_elephant.svg" alt="logo postgres" width="200" height="auto"> | ||
|
||
<hr/> | ||
<img src="./COISA_RUIM.jpeg" alt="meme coisa ruim" /> | ||
<hr/> | ||
|
||
## Leonardo Ralph | ||
|
||
Submissão feita com: | ||
|
||
- `nginx` como load balancer | ||
- `postgres` como banco de dados | ||
- `php` para api com o webserver frankenphp | ||
- [repositório da api](https://github.com/leoralph/RinhaBackend-Q1-2024-Franken) | ||
|
||
[@leoralph](https://twitter.com/leoralph) @ twitter |
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,56 @@ | ||
version: "3.5" | ||
|
||
services: | ||
api01: &api | ||
image: leoralph/rinha-backend-q1-2024:latest | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.5" | ||
memory: "150MB" | ||
|
||
api02: | ||
<<: *api | ||
|
||
nginx: | ||
image: nginx:latest | ||
volumes: | ||
- ./nginx.conf:/etc/nginx/nginx.conf | ||
depends_on: | ||
- api01 | ||
- api02 | ||
ports: | ||
- "9999:9999" | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.1" | ||
memory: "50MB" | ||
|
||
db: | ||
image: postgres | ||
hostname: db | ||
environment: | ||
POSTGRES_USER: root | ||
POSTGRES_PASSWORD: 1234 | ||
POSTGRES_DB: rinhadb | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- ./init.sql:/docker-entrypoint-initdb.d/init.sql | ||
- ./postgresql.conf:/docker-entrypoint-initdb.d/postgresql.conf | ||
command: postgres -c config_file=/docker-entrypoint-initdb.d/postgresql.conf | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready"] | ||
interval: 5s | ||
timeout: 5s | ||
retries: 20 | ||
start_period: 10s | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.4" | ||
memory: "200MB" |
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,4 @@ | ||
create table "clients" ("id" bigserial not null primary key, "limite" integer not null, "saldo" bigint not null default '0'); | ||
create table "transactions" ("id" bigserial not null primary key, "client_id" bigint not null, "valor" bigint not null, "tipo" varchar(1) not null, "descricao" varchar(10) not null, "realizada_em" varchar(255) not null); | ||
create index "transactions_client_id_id_index" on "transactions" ("client_id", "id"); | ||
insert into "clients" ("id", "limite") values (1, 100000), (2, 80000), (3, 1000000), (4, 10000000), (5, 500000) on conflict ("id") do update set "id" = "excluded"."id", "limite" = "excluded"."limite"; |
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,26 @@ | ||
worker_processes auto; | ||
worker_rlimit_nofile 500000; | ||
|
||
events { | ||
use epoll; | ||
worker_connections 1024; | ||
} | ||
http { | ||
access_log off; | ||
error_log /dev/null emerg; | ||
|
||
upstream api { | ||
server api01 weight=1; | ||
server api02 weight=1; | ||
keepalive 200; | ||
} | ||
|
||
server { | ||
listen 9999; | ||
location / { | ||
proxy_pass http://api; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
} | ||
} | ||
} |
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 @@ | ||
synchronous_commit=off | ||
fsync=off | ||
listen_addresses = '*' | ||
max_connections = 400 | ||
superuser_reserved_connections = 3 | ||
unix_socket_directories = '/var/run/postgresql' | ||
shared_buffers = 512MB | ||
work_mem = 4MB | ||
maintenance_work_mem = 256MB | ||
effective_cache_size = 1GB | ||
wal_buffers = 64MB | ||
checkpoint_timeout = 10min | ||
checkpoint_completion_target = 0.9 | ||
random_page_cost = 4.0 | ||
effective_io_concurrency = 2 | ||
autovacuum = on | ||
log_statement = 'none' | ||
log_duration = off | ||
log_lock_waits = on | ||
log_error_verbosity = terse | ||
log_min_messages = panic | ||
log_min_error_statement = panic |