Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enviar minha submissão #45

Closed
wants to merge 1 commit into from
Closed
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
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.
26 changes: 26 additions & 0 deletions participantes/leoralph/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
{$CADDY_GLOBAL_OPTIONS}

frankenphp {
worker /srv/public/index.php 2
{$FRANKENPHP_CONFIG}
}
order php_server before file_server
}

{$CADDY_EXTRA_CONFIG}

http://localhost {
root * /srv/public/

{$CADDY_SERVER_EXTRA_DIRECTIVES}

@indexFiles file {
try_files {path} index.php
split_path .php
}
rewrite @indexFiles {http.matchers.file.relative}

encode zstd gzip
php_server
}
10 changes: 10 additions & 0 deletions participantes/leoralph/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM dunglas/frankenphp

RUN echo "variables_order = \"EGPCS\"" >> $PHP_INI_DIR/conf.d/990-php.ini

RUN install-php-extensions pdo pdo_pgsql

WORKDIR /srv

COPY . /srv
COPY Caddyfile /etc/caddy/Caddyfile
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
58 changes: 58 additions & 0 deletions participantes/leoralph/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: "3.5"

services:
api01: &api
image: frankapp
build: .
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
# network_mode: host
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 5s
timeout: 5s
retries: 20
start_period: 10s
deploy:
resources:
limits:
cpus: "0.4"
memory: "200MB"
5 changes: 5 additions & 0 deletions participantes/leoralph/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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);
alter table "transactions" add constraint "transactions_client_id_foreign" foreign key ("client_id") references "clients" ("id");
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;
}
}
}
20 changes: 20 additions & 0 deletions participantes/leoralph/postgresql.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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
Loading