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

Inscriçao Jose Baroni - GoLang #31

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions participantes/josebaroni/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Jose Baroni - Rinha de Backend


Stack:
- Go
- Go Fiber
- pgx (SQL Driver)
- PostgreSQL
- Nginx

Autor:
- [LinkedIn](https://www.linkedin.com/in/josebaroni/)
- [Repositório](https://github.com/zebaroni/rinha-backend-2024-q1)

Resultados:
- Mean Request Time: **2ms**
- Max Request Time: **18ms**

![Test Screenshot](/test-ss.png)
20 changes: 20 additions & 0 deletions participantes/josebaroni/config/database/postgresql.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
listen_addresses = '*'
max_connections = 250
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
32 changes: 32 additions & 0 deletions participantes/josebaroni/config/database/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
CREATE TABLE clients
(
id INT PRIMARY KEY,
account_limit INTEGER NOT NULL,
balance INTEGER NOT NULL DEFAULT 0
);

CREATE UNLOGGED TABLE transactions
zebaroni marked this conversation as resolved.
Show resolved Hide resolved
(
id SERIAL PRIMARY KEY,
client_id INTEGER NOT NULL,
amount INTEGER NOT NULL,
operation CHAR(1) NOT NULL,
description VARCHAR(10) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
CONSTRAINT fk_transactions_client_id
FOREIGN KEY (client_id) REFERENCES clients (id)
);

ALTER TABLE transactions SET (autovacuum_enabled = false);

DO
$$
BEGIN
INSERT INTO clients (id, account_limit)
VALUES (1, 100000),
(2, 80000),
(3, 1000000),
(4, 10000000),
(5, 500000);
END;
$$
22 changes: 22 additions & 0 deletions participantes/josebaroni/config/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
events {
worker_connections 2048;
}

http {
access_log off;

upstream api {
server api01:3000;
server api02:3000;
}

server {
http2 on;
gzip on;
listen 9999;

location / {
proxy_pass http://api;
}
}
}
66 changes: 66 additions & 0 deletions participantes/josebaroni/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: "3.5"

services:
api01: &api
image: zebaroni/rinha-backend-2024-q1:latest
hostname: api01
restart: unless-stopped
networks:
- default
environment:
- APP_PORT=3000
- DATABASE_URL=postgres://rinha:rinha@db:5432/rinha
depends_on:
- db
deploy:
resources:
limits:
cpus: "0.15"
memory: "100MB"

api02:
<<: *api
hostname: api02

db:
image: postgres:latest
hostname: db
restart: unless-stopped
networks:
- default
environment:
POSTGRES_DB: rinha
POSTGRES_USER: rinha
POSTGRES_PASSWORD: rinha
ports:
- "5432:5432"
volumes:
- ./config/database/schema.sql:/docker-entrypoint-initdb.d/init.sql
- ./config/database/postgresql.conf:/docker-entrypoint-initdb.d/postgresql.conf
command: postgres -c config_file=/docker-entrypoint-initdb.d/postgresql.conf
deploy:
resources:
limits:
cpus: '1'
memory: "300MB"

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

networks:
default:
driver: bridge
name: rinha-network
Binary file added participantes/josebaroni/test-ss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading