Skip to content

Commit

Permalink
introduce haproxy to test horizontal scalability
Browse files Browse the repository at this point in the history
  • Loading branch information
vieiralucas committed Nov 24, 2024
1 parent 0c22707 commit b9ef058
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 46 deletions.
30 changes: 0 additions & 30 deletions apps/api/nodemon.js

This file was deleted.

5 changes: 5 additions & 0 deletions apps/api/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"watch": ["src", ".env", "package.json"],
"ext": "ts",
"exec": "node --max-old-space-size=16384 --inspect --loader ts-node/esm ./src/index.ts | pino-pretty"
}
3 changes: 2 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"start": "node ./dist/index.js",
"dev": "node nodemon.js",
"dev": "cross-env PORT=${PORT:-8081} nodemon",
"build": "tsc",
"test": "jest --passWithNoTests"
},
Expand Down Expand Up @@ -92,6 +92,7 @@
"@types/split2": "^4.2.3",
"@types/uuid": "^9.0.7",
"@types/ws": "^8.5.9",
"cross-env": "^7.0.3",
"deep-diff": "^1.0.2",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
Expand Down
21 changes: 6 additions & 15 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,16 @@ services:
volumes:
- ./data/mysql/ecommerce/data:/var/lib/mysql

api-nginx:
image: nginx:1.27
command: /bin/sh -c "/generate-nginx-config.sh && nginx -g 'daemon off;'"
ports:
- '8080:8080'
environment:
MULTI_INSTANCE: ${MULTI_INSTANCE:-false}
haproxy:
image: haproxy:3.0
volumes:
- type: bind
source: ./dev/nginx/nginx.conf
target: /etc/nginx/nginx.conf
source: ./haproxy.cfg
target: /usr/local/etc/haproxy/haproxy.cfg
volume:
nocopy: true
- type: bind
source: ./dev/nginx/generate-nginx-config.sh
target: /generate-nginx-config.sh
volume:
nocopy: true
restart: always
ports:
- '8080:8080'

volumes:
postgres_dev_data:
Expand Down
21 changes: 21 additions & 0 deletions haproxy.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
global
# No 'log' directive here
daemon

defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
option httplog
option http-server-close

frontend main
bind *:8080
default_backend servers

backend servers
balance roundrobin
cookie SERVERID insert
server app1 host.docker.internal:8081 check cookie app1
server app2 host.docker.internal:8082 check cookie app2
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5373,6 +5373,13 @@ cronstrue@^2.44.0:
resolved "https://registry.yarnpkg.com/cronstrue/-/cronstrue-2.50.0.tgz#eabba0f915f186765258b707b7a3950c663b5573"
integrity sha512-ULYhWIonJzlScCCQrPUG5uMXzXxSixty4djud9SS37DoNxDdkeRocxzHuAo4ImRBUK+mAuU5X9TSwEDccnnuPg==

cross-env@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf"
integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==
dependencies:
cross-spawn "^7.0.1"

cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
Expand All @@ -5382,6 +5389,15 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"

cross-spawn@^7.0.1:
version "7.0.6"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f"
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
dependencies:
path-key "^3.1.0"
shebang-command "^2.0.0"
which "^2.0.1"

css-font-size-keywords@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/css-font-size-keywords/-/css-font-size-keywords-1.0.0.tgz#854875ace9aca6a8d2ee0d345a44aae9bb6db6cb"
Expand Down

0 comments on commit b9ef058

Please sign in to comment.