Commit b6297c5f authored by Nilanjan Daw's avatar Nilanjan Daw

Changed args passing from file to commandline

Bug Fix. Passing startup data like port etc via config.json caused concurrency issues. Moved to passing variable through commandline
parent 283b7f36
......@@ -17,6 +17,7 @@ function runIsolate(local_repository, metadata) {
return new Promise((resolve, reject) => {
const worker = new Worker(filename, {
argv: [resource_id, functionHash, port, "isolate"],
resourceLimits: {
maxOldGenerationSizeMb: memory
}
......@@ -42,7 +43,7 @@ function runProcess(local_repository, metadata) {
return new Promise((resolve, reject) => {
let timeStart = Date.now()
const process = spawn('node', [`--max-old-space-size=${memory}`, filename, port]);
const process = spawn('node', [filename, resource_id, functionHash, port, "process", `--max-old-space-size=${memory}` ]);
process.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
let timeDifference = Math.ceil((Date.now() - timeStart))
......@@ -90,7 +91,7 @@ function runContainer(metadata) {
if (code != 0)
reject("error")
else {
const process = spawn('docker', ["run", "--rm", "-p", `${port}:5000`, "--name", resource_id, registry_url + imageName,
const process = spawn('docker', ["run", "--rm", "-p", `${port}:${port}`, "--name", resource_id, registry_url + imageName,
resource_id, imageName, port, "container"]);
let result = "";
// timeStart = Date.now()
......@@ -117,7 +118,7 @@ function runContainer(metadata) {
} else {
logger.info("container starting at port", port);
const process = spawn('docker', ["run", "--rm", "-p", `${port}:5000`, "--name", resource_id,
const process = spawn('docker', ["run", "--rm", "-p", `${port}:${port}`, "--name", resource_id,
registry_url + imageName, resource_id, imageName, port, "container"]);
let result = "";
// timeStart = Date.now()
......
......@@ -113,14 +113,8 @@ function startWorker(local_repository, producer, metadata) {
let runtime = metadata.runtime
console.log(metadata);
logger.info(`Using port ${metadata.port} for functionHash ${metadata.functionHash}`);
fs.writeFile('./local_repository/config.json', JSON.stringify({
port: metadata.port,
functionHash: metadata.functionHash,
resource_id: metadata.resource_id,
runtime: metadata.runtime,
memory: metadata.resources.memory
}), () => {
logger.info(`Using port ${metadata.port} for functionHash ${metadata.functionHash}`)
if (runtime === "isolate")
execute.runIsolate(local_repository, metadata)
.catch(err => {
......@@ -156,7 +150,6 @@ function startWorker(local_repository, producer, metadata) {
return
}
});
}
......
......@@ -2,21 +2,12 @@
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
let port = 5000, resource_id, functionHash, portExternal, runtime
let config = null;
try {
config = require('./config.json')
port = config.port
resource_id = config.resource_id
functionHash = config.functionHash
runtime = config.runtime
} catch (e) {
port = 5000
resource_id = process.argv[2]
functionHash = process.argv[3]
portExternal = process.argv[4]
runtime = process.argv[5]
}
let port = 5000, resource_id, functionHash, runtime
resource_id = process.argv[2]
functionHash = process.argv[3]
port = process.argv[4]
runtime = process.argv[5]
let kafka = require('kafka-node'),
Producer = kafka.Producer,
......@@ -47,7 +38,7 @@ app.listen(port, () => {
producer.send(
[{
topic: "deployed",
messages: JSON.stringify({ functionHash, portExternal, runtime, resource_id }),
messages: JSON.stringify({ functionHash, portExternal: port, runtime, resource_id }),
"status": true
}], () => { })
})
......@@ -59,7 +50,7 @@ function shouldDie() {
producer.send(
[{
topic: "removeWorker",
messages: JSON.stringify({ functionHash, portExternal, runtime, resource_id })
messages: JSON.stringify({ functionHash, portExternal: port, runtime, resource_id })
}], () => {
console.log("Ending worker for function", functionHash, "resource_id", resource_id);
process.exit(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment