Skip to content

Commit

Permalink
Merge pull request #47 from leoralph/main
Browse files Browse the repository at this point in the history
Enviar submissão leoralph
  • Loading branch information
zanfranceschi authored Feb 9, 2024
2 parents 6868977 + bce2cbc commit 0290092
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
Binary file added participantes/leoralph/COISA_RUIM.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions participantes/leoralph/README.md
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
56 changes: 56 additions & 0 deletions participantes/leoralph/docker-compose.yml
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"
4 changes: 4 additions & 0 deletions participantes/leoralph/init.sql
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";
26 changes: 26 additions & 0 deletions participantes/leoralph/nginx.conf
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;
}
}
}
22 changes: 22 additions & 0 deletions participantes/leoralph/postgresql.conf
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

0 comments on commit 0290092

Please sign in to comment.