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

Add leandronsp/agostinho #14

Merged
Merged
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
41 changes: 41 additions & 0 deletions participantes/agostinho/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# agostinho (by leandronsp)

[agostinho](https://github.com/leandronsp/agostinho) é uma modesta versão Ruby (sem Rails) para esta segunda edição da **famosa e distinta** rinha de backend que visa a utilização de bibliotecas nem um pouco ortodoxas criadas pelo autor _just for fun_.

## Stack

* 2x Ruby 3.3 [+YJIT](https://shopify.engineering/ruby-yjit-is-production-ready)
* 1x PostgreSQL
* 1x NGINX

Esta versão contempla uma stack _handmade_ com Ruby puro, sem Rails nem outro framework mainstream, com o intuito de explorar e testar a utilização de duas bibliotecas construídas pelo autor _só porque sim_ ainda em fase alpha:

* [leandronsp/adelnor](https://github.com/leandronsp/adelnor) (web server)
* [leandronsp/chespirito](https://github.com/leandronsp/chespirito) (web framework)

## Autor

### Leandro Proença

[Agostinho](https://github.com/leandronsp/agostinho) • [Github](https://github.com/leandronsp) • [Twitter](https://twitter.com/leandronsp) • [DEV](https://dev.to/leandronsp)

## Running

```bash
$ docker compose up -d
```

## Confira comigo no replay

Como o critério de avaliação é um mistério que só será desvendado na live da rinha, compartilho aqui um print clássico de como está a app neste momento (6/Fev/2024) só pra não perder o costume:

<img width="1032" alt="Screenshot 2024-02-06 at 01 07 14" src="https://github.com/leandronsp/rinha-de-backend-2024-q1/assets/385640/7459d89c-6277-4d03-a387-324a8b5766ac">

## Outras participações

O autor também participou da primeira edição da rinha com duas submissões, sendo uma em Ruby e outra em Bash (pelo meme):

* [leandronsp/rinha-backend-ruby](https://github.com/leandronsp/rinha-backend-ruby)
* [leandronsp/rinha-backend-bash](https://github.com/leandronsp/rinha-backend-bash)

A versão Ruby ficou em 20º lugar (not too bad), ao passo que a versão Bash se deleitou na última posição das submissões que funcionaram, conquistando o tão sonhado 51º lugar (not too bad too).
39 changes: 39 additions & 0 deletions participantes/agostinho/config/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
CREATE TABLE accounts (
id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
limit_amount INTEGER NOT NULL
);

CREATE TABLE transactions (
id SERIAL PRIMARY KEY,
account_id INTEGER NOT NULL,
amount INTEGER NOT NULL,
transaction_type CHAR(1) NOT NULL,
description VARCHAR(10) NOT NULL,
date TIMESTAMP NOT NULL DEFAULT NOW(),
CONSTRAINT fk_accounts_transactions_id
FOREIGN KEY (account_id) REFERENCES accounts(id)
);

CREATE TABLE balances (
id SERIAL PRIMARY KEY,
account_id INTEGER NOT NULL,
amount INTEGER NOT NULL,
CONSTRAINT fk_accounts_balances_id
FOREIGN KEY (account_id) REFERENCES accounts(id)
);

DO $$
BEGIN
INSERT INTO accounts (name, limit_amount)
VALUES
('o barato sai caro', 1000 * 100),
('zan corp ltda', 800 * 100),
('les cruders', 10000 * 100),
('padaria joia de cocaia', 100000 * 100),
('kid mais', 5000 * 100);

INSERT INTO balances (account_id, amount)
SELECT id, 0 FROM accounts;
END;
$$;
22 changes: 22 additions & 0 deletions participantes/agostinho/config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
worker_processes auto;

events {
worker_connections 256;
}

http {
access_log off;

upstream api {
server api1:3000;
server api2:3000;
}

server {
listen 9999;

location / {
proxy_pass http://api;
}
}
}
12 changes: 12 additions & 0 deletions participantes/agostinho/config/postgresql.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -----------------------------
# PostgreSQL configuration file
# -----------------------------

listen_addresses = '*'

# RESOURCE USAGE
max_connections = 30

# QUERY TUNING
random_page_cost = 1.1
effective_io_concurrency = 30
51 changes: 51 additions & 0 deletions participantes/agostinho/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
services:
api1: &api
image: leandronsp/agostinho
container_name: api1
environment:
- RUBY_YJIT_ENABLE=1
- DB_POOL_SIZE=5
depends_on:
- postgres
deploy:
resources:
limits:
cpus: '0.3'
memory: '150MB'

api2:
<<: *api
container_name: api2

postgres:
image: postgres
container_name: postgres
environment:
- POSTGRES_PASSWORD=postgres
ports:
- 5432:5432
volumes:
- ./config/init.sql:/docker-entrypoint-initdb.d/init.sql
- ./config/postgresql.conf:/etc/postgresql/postgresql.conf
command: postgres -c config_file=/etc/postgresql/postgresql.conf
deploy:
resources:
limits:
cpus: '0.7'
memory: '200MB'

nginx:
image: nginx
container_name: nginx
volumes:
- ./config/nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- 9999:9999
depends_on:
- api1
- api2
deploy:
resources:
limits:
cpus: '0.2'
memory: '50MB'