diff --git a/participantes/josebaroni/README.md b/participantes/josebaroni/README.md new file mode 100644 index 000000000..d06b48713 --- /dev/null +++ b/participantes/josebaroni/README.md @@ -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: **2ms** +- max: **18ms** + +![Test Screenshot](https://raw.githubusercontent.com/zebaroni/rinha-backend-2024-q1/master/test-ss.png) \ No newline at end of file diff --git a/participantes/josebaroni/config/database/postgresql.conf b/participantes/josebaroni/config/database/postgresql.conf new file mode 100644 index 000000000..5e47d6b61 --- /dev/null +++ b/participantes/josebaroni/config/database/postgresql.conf @@ -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 \ No newline at end of file diff --git a/participantes/josebaroni/config/database/schema.sql b/participantes/josebaroni/config/database/schema.sql new file mode 100644 index 000000000..d0c646baa --- /dev/null +++ b/participantes/josebaroni/config/database/schema.sql @@ -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 +( + 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; +$$ \ No newline at end of file diff --git a/participantes/josebaroni/config/nginx/nginx.conf b/participantes/josebaroni/config/nginx/nginx.conf new file mode 100644 index 000000000..e9cc1a782 --- /dev/null +++ b/participantes/josebaroni/config/nginx/nginx.conf @@ -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; + } + } +} \ No newline at end of file diff --git a/participantes/josebaroni/docker-compose.yml b/participantes/josebaroni/docker-compose.yml new file mode 100644 index 000000000..94d973632 --- /dev/null +++ b/participantes/josebaroni/docker-compose.yml @@ -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