From 43977b16f27784233c166ff8fc42cf8ed5c891ed Mon Sep 17 00:00:00 2001 From: Mateus Cruz Date: Wed, 7 Feb 2024 23:51:09 -0300 Subject: chore: adjust resources --- docker-compose.yml | 16 ++++++---------- init.sql | 40 ++++++++++++++++++++++++++++++++++++++++ nginx.conf | 2 +- script.sql | 40 ---------------------------------------- 4 files changed, 47 insertions(+), 51 deletions(-) create mode 100644 init.sql delete mode 100644 script.sql diff --git a/docker-compose.yml b/docker-compose.yml index bcbd47f..09156b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,20 +3,16 @@ version: '3.5' services: api01: &api image: ghcr.io/molvrr/combattant:latest - environment: - - DB_HOST=db depends_on: - db deploy: resources: limits: - cpus: "0.20" - memory: "150mb" + cpus: "0.45" + memory: "50mb" api02: <<: *api - environment: - - DB_HOST=db nginx: image: nginx:latest @@ -30,7 +26,7 @@ services: deploy: resources: limits: - cpus: "0.17" + cpus: "0.20" memory: "110MB" db: @@ -43,9 +39,9 @@ services: ports: - "5432:5432" volumes: - - ./script.sql:/docker-entrypoint-initdb.d/script.sql + - ./init.sql:/docker-entrypoint-initdb.d/init.sql deploy: resources: limits: - cpus: "0.63" - memory: "140MB" + cpus: "0.40" + memory: "340MB" diff --git a/init.sql b/init.sql new file mode 100644 index 0000000..a02895a --- /dev/null +++ b/init.sql @@ -0,0 +1,40 @@ +CREATE TABLE clients ( + id SERIAL PRIMARY KEY, + name VARCHAR(50) NOT NULL, + mov_limit INTEGER NOT NULL +); + +CREATE TYPE transaction_type AS ENUM ('credit', 'debit'); + +CREATE TABLE transactions ( + id SERIAL PRIMARY KEY, + client_id INTEGER REFERENCES clients, + value INTEGER NOT NULL, + type transaction_type NOT NULL, + description VARCHAR(10) NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +CREATE INDEX idx_client_id_transactions ON transactions (client_id); + +CREATE TABLE balances ( + id SERIAL PRIMARY KEY, + client_id INTEGER REFERENCES clients, + value INTEGER NOT NULL +); + +CREATE INDEX idx_client_id_balances ON balances (client_id); + +DO $$ +BEGIN + INSERT INTO clients (name, mov_limit) + VALUES + ('naruto', 100000), + ('mob', 80000), + ('jojo', 1000000), + ('hellboy', 10000000), + ('ultramega', 500000); + INSERT INTO balances (client_id, value) + SELECT id, 0 FROM clients; +END; +$$ diff --git a/nginx.conf b/nginx.conf index c005fad..9a00391 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,5 +1,5 @@ events { - worker_connections 256; + worker_connections 1000; } http { diff --git a/script.sql b/script.sql deleted file mode 100644 index a02895a..0000000 --- a/script.sql +++ /dev/null @@ -1,40 +0,0 @@ -CREATE TABLE clients ( - id SERIAL PRIMARY KEY, - name VARCHAR(50) NOT NULL, - mov_limit INTEGER NOT NULL -); - -CREATE TYPE transaction_type AS ENUM ('credit', 'debit'); - -CREATE TABLE transactions ( - id SERIAL PRIMARY KEY, - client_id INTEGER REFERENCES clients, - value INTEGER NOT NULL, - type transaction_type NOT NULL, - description VARCHAR(10) NOT NULL, - created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() -); - -CREATE INDEX idx_client_id_transactions ON transactions (client_id); - -CREATE TABLE balances ( - id SERIAL PRIMARY KEY, - client_id INTEGER REFERENCES clients, - value INTEGER NOT NULL -); - -CREATE INDEX idx_client_id_balances ON balances (client_id); - -DO $$ -BEGIN - INSERT INTO clients (name, mov_limit) - VALUES - ('naruto', 100000), - ('mob', 80000), - ('jojo', 1000000), - ('hellboy', 10000000), - ('ultramega', 500000); - INSERT INTO balances (client_id, value) - SELECT id, 0 FROM clients; -END; -$$ -- cgit v1.2.3