src dir, adaptations
This commit is contained in:
@@ -1,2 +1,4 @@
|
|||||||
logs/
|
logs/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
dist/
|
||||||
|
.gitea/
|
||||||
13
Dockerfile
13
Dockerfile
@@ -1,15 +1,18 @@
|
|||||||
FROM node:23-alpine
|
FROM node:23-alpine
|
||||||
|
|
||||||
WORKDIR /home/node
|
|
||||||
USER node
|
USER node
|
||||||
|
WORKDIR /home/node
|
||||||
RUN mkdir -p app/logs && chown -R node:node app
|
RUN mkdir -p app/logs && chown -R node:node app
|
||||||
|
|
||||||
WORKDIR /home/node/app
|
WORKDIR /home/node/app
|
||||||
|
|
||||||
COPY --chown=node:node package*.json ./
|
COPY --chown=node:node package*.json ./
|
||||||
RUN npm install
|
RUN npm install
|
||||||
COPY --chown=node:node main.js util.js worker.js ./
|
|
||||||
# Expose logs directory as a volume
|
COPY --chown=node:node src ./
|
||||||
|
|
||||||
VOLUME ["/home/node/app/logs"]
|
VOLUME ["/home/node/app/logs"]
|
||||||
# Use an environment variable for thread count (default to 0 to use auto)
|
|
||||||
ENV THREAD_COUNT=0
|
ENV THREAD_COUNT=0
|
||||||
# Run the application - using JSON array format
|
|
||||||
CMD ["sh", "-c", "node main.js ${THREAD_COUNT}"]
|
CMD ["sh", "-c", "node main.js ${THREAD_COUNT}"]
|
||||||
13
package.json
13
package.json
@@ -1,14 +1,15 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "multithreaded-http-app",
|
"name": "bot-farmacia",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "A multithreaded Node.js app that performs repeated HTTP POST requests using worker threads.",
|
"description": "A multithreaded Node.js app that performs repeated HTTP POST requests using worker threads.",
|
||||||
"main": "main.js",
|
"main": "src/main.js",
|
||||||
|
"output": "bot-farmacia.exe",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node main.js",
|
"start": "node src/main.js",
|
||||||
"start:single": "node main.js 1",
|
"start:single": "node src/main.js 1",
|
||||||
"start:quad": "node main.js 4",
|
"start:quad": "node src/main.js 4",
|
||||||
"start:octa": "node main.js 8"
|
"start:octa": "node src/main.js 8"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.6.0"
|
"axios": "^1.6.0"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ let totalSuccess = 0;
|
|||||||
let totalError = 0;
|
let totalError = 0;
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
|
|
||||||
const logsDir = path.join(__dirname, 'logs');
|
const logsDir = 'logs';
|
||||||
if (!fs.existsSync(logsDir)) {
|
if (!fs.existsSync(logsDir)) {
|
||||||
fs.mkdirSync(logsDir);
|
fs.mkdirSync(logsDir);
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ module.exports = {
|
|||||||
onMessage = ({ id, payload }) => console.log("onMessage", id, payload),
|
onMessage = ({ id, payload }) => console.log("onMessage", id, payload),
|
||||||
onError = ({ id, error }) => console.error("onError", id, error),
|
onError = ({ id, error }) => console.error("onError", id, error),
|
||||||
onExit = ({ id, status }) => console.log("onExit", id, status)) => {
|
onExit = ({ id, status }) => console.log("onExit", id, status)) => {
|
||||||
return new Worker('./worker.js', { workerData })
|
return new Worker(path.join(__dirname, 'worker.js'), { workerData })
|
||||||
.on('message', (payload) => onMessage({ id: workerData.id, payload }))
|
.on('message', (payload) => onMessage({ id: workerData.id, payload }))
|
||||||
.on('error', (error) => onError({ id: workerData.id, error }))
|
.on('error', (error) => onError({ id: workerData.id, error }))
|
||||||
.on('exit', (status) => onExit({ id: workerData.id, status }));
|
.on('exit', (status) => onExit({ id: workerData.id, status }));
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const {workerFactory, onMessage, onError, onExit, logger} = require('./util');
|
const {workerFactory, onMessage, onError, onExit, logger} = require('./bot-util');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
|
|
||||||
let THREAD_COUNT = Math.max(1, os.cpus().length - 1);;
|
let THREAD_COUNT = Math.max(1, os.cpus().length - 1);;
|
||||||
Reference in New Issue
Block a user