-
Notifications
You must be signed in to change notification settings - Fork 923
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adicionando arquivos da primeira submissão em go
- Loading branch information
Showing
5 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
# Rinha de Backend 2024-Q1 | ||
|
||
### Samuel Luiz | ||
|
||
Github: [@samluiz](https://github.com/samluiz) | ||
|
||
Twitter: [@real_vvs_](https://twitter.com/real_vvs_) | ||
|
||
LinkedIn: [@samuelluizrl](https://www.linkedin.com/in/samuelluizrl) | ||
|
||
Repositório: [https://github.com/samluiz/concurrency-control](https://github.com/samluiz/concurrency-control) | ||
|
||
--- | ||
|
||
Menção honrosa ao [repositório do @zebaroni](https://github.com/zebaroni/rinha-backend-2024-q1), me inspirei nele pra aplicar algumas otimizações que eu não conhecia | ||
|
||
|
||
### Stack: Go com Postgres (muito criativo) | ||
- Go + Fiber + Pgx | ||
- Postgres | ||
- Nginx |
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,28 @@ | ||
CREATE TABLE IF NOT EXISTS clientes ( | ||
id SERIAL PRIMARY KEY, | ||
limite INT, | ||
saldo INT DEFAULT 0 | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS transacoes ( | ||
id SERIAL PRIMARY KEY, | ||
valor INT, | ||
tipo CHAR(1), | ||
descricao VARCHAR(10), | ||
realizada_em TIMESTAMP, | ||
id_cliente INT | ||
); | ||
|
||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS (SELECT * FROM clientes WHERE id BETWEEN 1 AND 5) THEN | ||
INSERT INTO clientes (limite) | ||
VALUES | ||
(1000 * 100), | ||
(800 * 100), | ||
(10000 * 100), | ||
(100000 * 100), | ||
(5000 * 100); | ||
END IF; | ||
END; | ||
$$; |
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,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_completion_target = 0.9 | ||
random_page_cost = 4.0 | ||
effective_io_concurrency = 10 | ||
autovacuum = on | ||
log_statement = 'none' | ||
log_duration = off | ||
log_lock_waits = off | ||
log_error_verbosity = terse | ||
log_min_messages = panic | ||
log_min_error_statement = panic | ||
synchronous_commit=off |
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,73 @@ | ||
version: "3.5" | ||
|
||
services: | ||
api01: &api | ||
image: samluiz/concurrency-control | ||
hostname: api01 | ||
restart: unless-stopped | ||
environment: | ||
- DATABASE_URL=postgres://postgres:postgres@db:5432/bank | ||
- SERVER_PORT=3000 | ||
ports: | ||
- "3001:3000" | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.25" | ||
memory: "100MB" | ||
|
||
api02: | ||
<<: *api | ||
hostname: api02 | ||
ports: | ||
- "3002:3000" | ||
|
||
nginx: | ||
image: nginx:latest | ||
volumes: | ||
- ../nginx/nginx.conf:/etc/nginx/nginx.conf:ro | ||
depends_on: | ||
- api01 | ||
- api02 | ||
ports: | ||
- "9999:9999" | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.2" | ||
memory: "50MB" | ||
|
||
db: | ||
image: postgres:latest | ||
hostname: db | ||
restart: unless-stopped | ||
environment: | ||
- POSTGRES_PASSWORD=postgres | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_DB=bank | ||
- PGUSER=postgres | ||
ports: | ||
- "5432:5432" | ||
- "2345:5432" | ||
volumes: | ||
- ../db/init.sql:/docker-entrypoint-initdb.d/init.sql | ||
- ../db/postgresql.conf:/docker-entrypoint-initdb.d/postgresql.conf | ||
healthcheck: | ||
test: ["CMD", "pg_isready", "-h", "db", "-p", "5432", "-q"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
command: postgres -c config_file=/docker-entrypoint-initdb.d/postgresql.conf | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.8" | ||
memory: "300MB" | ||
|
||
networks: | ||
default: | ||
driver: bridge | ||
name: concurrency-control |
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 @@ | ||
events { | ||
worker_connections 1000; | ||
} | ||
|
||
http { | ||
access_log off; | ||
|
||
upstream api { | ||
server api01:3000; | ||
server api02:3000; | ||
} | ||
|
||
server { | ||
http2 on; | ||
gzip on; | ||
listen 9999; | ||
|
||
location / { | ||
proxy_pass http://api; | ||
} | ||
} | ||
} |