Skip to content

Commit

Permalink
wip: failed-68% <800ms-20% >1200-11%
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas8219 committed Aug 15, 2023
1 parent 7e0d606 commit f16c2fc
Show file tree
Hide file tree
Showing 8 changed files with 6,061 additions and 229 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Expand Up @@ -3,6 +3,6 @@ FROM node:18.12.1-alpine
COPY . .
RUN npm ci

RUN npm install pm2 -g
RUN npm install -g forever

CMD ["pm2-runtime", "--instances", "4", "index.js"]
CMD ["forever", "-f", "index.js"]
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -7,5 +7,9 @@
- Postgres


### WIP

preciso descobrir porque os Nodos estao morrendo e não estão voltando, nem com PM2

### Tática:
Apenas fazer batch no client e rezar pro eventloop não morrer
7 changes: 3 additions & 4 deletions database.js
Expand Up @@ -30,6 +30,7 @@ pool.once('connect', () => {

async function connect() {
try {
logger.info(`Connecting to db ${URL}`);
await pool.connect();
} catch(err){
setTimeout(() => {
Expand Down Expand Up @@ -121,10 +122,8 @@ process.env.BATCH === 'true' ? (() => {
const realCb = arguments[arguments.length - 1];
const cb = function () {
realCb(...arguments);
setImmediate(() => {
(queue || []).forEach((cb) => cb(...arguments))
batchItems[moduleKey].delete(key);
});
(queue || []).forEach((cb) => cb(...arguments))
batchItems[moduleKey].delete(key);
};
if (queue) {
logger.debug(`${moduleKey} has been queued: for args ${key}`);
Expand Down
52 changes: 43 additions & 9 deletions docker-compose.yaml
Expand Up @@ -11,14 +11,14 @@ services:
deploy:
resources:
limits:
cpus: '0.50'
cpus: '1'
memory: '0.5GB'
app1:
image: lukas8219/rinha-be-2023-q3:latest
environment:
DB_URL: "postgres://postgres:12345678@postgres:5432/postgres"
BATCH: "true"
CLUSTER: "true"
BATCH: "false"
CLUSTER: "false"
PINO_LOG_LEVEL: "error"
REQ_TIMEOUT: "10000"
ports:
Expand All @@ -28,14 +28,14 @@ services:
deploy:
resources:
limits:
cpus: '0.45'
memory: '0.5GB'
cpus: '0.225'
memory: '0.2GB'
app2:
image: lukas8219/rinha-be-2023-q3:latest
environment:
DB_URL: "postgres://postgres:12345678@postgres:5432/postgres"
BATCH: "true"
CLUSTER: "true"
BATCH: "false"
CLUSTER: "false"
REQ_TIMEOUT: "10000"
PINO_LOG_LEVEL: "error"
ports:
Expand All @@ -45,8 +45,42 @@ services:
deploy:
resources:
limits:
cpus: '0.45'
memory: '0.5GB'
cpus: '0.1'
memory: '0.2GB'
app3:
image: lukas8219/rinha-be-2023-q3:latest
environment:
DB_URL: "postgres://postgres:12345678@postgres:5432/postgres"
BATCH: "false"
CLUSTER: "false"
REQ_TIMEOUT: "10000"
PINO_LOG_LEVEL: "error"
ports:
- "8080"
depends_on:
- postgres
deploy:
resources:
limits:
cpus: '0.1'
memory: '0.2GB'
app4:
image: lukas8219/rinha-be-2023-q3:latest
environment:
DB_URL: "postgres://postgres:12345678@postgres:5432/postgres"
BATCH: "false"
CLUSTER: "false"
REQ_TIMEOUT: "10000"
PINO_LOG_LEVEL: "error"
ports:
- "8080"
depends_on:
- postgres
deploy:
resources:
limits:
cpus: '0.1'
memory: '0.2GB'
nginx: # Load Balancer
image: nginx:latest
volumes:
Expand Down
3 changes: 1 addition & 2 deletions index.js
Expand Up @@ -85,5 +85,4 @@ if(cluster.isPrimary && process.env.CLUSTER === 'true'){
socket.end();
})
}
}

}
2 changes: 2 additions & 0 deletions nginx.conf
Expand Up @@ -9,6 +9,8 @@ http {
upstream api {
server app1:8080;
server app2:8080;
server app3:8080;
server app4:8080;
}

server {
Expand Down

0 comments on commit f16c2fc

Please sign in to comment.