Skip to content

Commit

Permalink
Merge pull request #57 from Aysion/aysion
Browse files Browse the repository at this point in the history
Aysion - nodeJS
  • Loading branch information
zanfranceschi authored Feb 9, 2024
2 parents 11ba5f6 + ee2d689 commit 761afdf
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
15 changes: 15 additions & 0 deletions participantes/aysion_nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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/7/7e/Node.js_logo_2015.svg" alt="logo nodeJS" width="200" height="auto">
<img src="https://upload.wikimedia.org/wikipedia/commons/6/68/Mariadb-seal-browntext.svg" alt="logo mariaDB" width="200" height="auto">


## Aysion
Submissão feita com:
- `nginx` como load balancer
- `mariaDB` como banco de dados
- `nodeJS` para api com a lib `mysql2`
- [repositório da api](https://github.com/aysion/rinha_de_backend_2024_q1-nodejs)
[@aysiondenosfero](https://twitter.com/aysiondenosfero) @ twitter
52 changes: 52 additions & 0 deletions participantes/aysion_nodejs/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: "3.9"

services:
api_01: &api
image: aysion/rinha_de_backend_2024_q1-nodejs
restart: unless-stopped
hostname: api_01
environment:
- PORT=8080
depends_on:
- db
deploy:
resources:
limits:
cpus: "0.15"
memory: "120MB"
api_02:
<<: *api
hostname: api_02
nginx:
image: nginx:latest
restart: unless-stopped
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- api_01
- api_02
ports:
- 9999:9999
deploy:
resources:
limits:
cpus: "0.2"
memory: "10MB"
db:
image: mariadb:11
restart: unless-stopped
hostname: db
environment:
- MARIADB_ROOT_PASSWORD=adminPass
- MARIADB_DATABASE=rinha
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
deploy:
resources:
limits:
cpus: "1"
memory: "300MB"
networks:
default:
driver: bridge
name: rinha-nginx-2024q1
25 changes: 25 additions & 0 deletions participantes/aysion_nodejs/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
USE rinha;

CREATE TABLE clientes (
id INT AUTO_INCREMENT PRIMARY KEY,
nome VARCHAR(50),
limite INT DEFAULT 0,
saldo INT DEFAULT 0
);

CREATE TABLE transacoes (
id INT AUTO_INCREMENT PRIMARY KEY,
cliente_id INT,
valor INT,
tipo ENUM('d', 'c'),
descricao VARCHAR(10),
realizada_em TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (cliente_id) REFERENCES clientes(id)
);

INSERT INTO clientes (nome, limite) 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);
22 changes: 22 additions & 0 deletions participantes/aysion_nodejs/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
events {
worker_connections 256;
}

http {
access_log off;
sendfile on;
keepalive_timeout 0;

upstream api {
server api_01:8080;
server api_02:8080;
}

server {
listen 9999;

location / {
proxy_pass http://api;
}
}
}

0 comments on commit 761afdf

Please sign in to comment.