Commit 583d2163 authored by Nilanjan Daw's avatar Nilanjan Daw

Removed redundant event listeners

parent 79adfd7d
...@@ -5,3 +5,4 @@ package-lock.json ...@@ -5,3 +5,4 @@ package-lock.json
firecracker* firecracker*
secrets.json secrets.json
resource_manager/bin/** resource_manager/bin/**
grunt
...@@ -4,9 +4,6 @@ const fs = require('fs') ...@@ -4,9 +4,6 @@ const fs = require('fs')
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const { Worker, isMainThread, workerData } = require('worker_threads'); const { Worker, isMainThread, workerData } = require('worker_threads');
const registry_url = "10.129.6.5:5000/" const registry_url = "10.129.6.5:5000/"
const events = require('events');
const workerEvent = new events.EventEmitter();
const parentProcess = require('process');
function runIsolate(local_repository, functionHash, port, resource_id) { function runIsolate(local_repository, functionHash, port, resource_id) {
let filename = local_repository + functionHash + ".js" let filename = local_repository + functionHash + ".js"
...@@ -19,7 +16,6 @@ function runIsolate(local_repository, functionHash, port, resource_id) { ...@@ -19,7 +16,6 @@ function runIsolate(local_repository, functionHash, port, resource_id) {
if (code !== 0) if (code !== 0)
reject(new Error(`Worker stopped with exit code ${code}`)); reject(new Error(`Worker stopped with exit code ${code}`));
console.log("worker exited"); console.log("worker exited");
workerEvent.emit('end', port, "isolate");
}) })
worker.on('online', () => { worker.on('online', () => {
workerEvent.emit('start', functionHash, port, "isolate") workerEvent.emit('start', functionHash, port, "isolate")
...@@ -41,7 +37,6 @@ function runProcess(local_repository, functionHash, port, resource_id) { ...@@ -41,7 +37,6 @@ function runProcess(local_repository, functionHash, port, resource_id) {
result += data; result += data;
let timeDifference = Math.ceil((Date.now() - timeStart)) let timeDifference = Math.ceil((Date.now() - timeStart))
console.log("process time taken: ", timeDifference); console.log("process time taken: ", timeDifference);
// workerEvent.emit('start', functionHash, port, "process")
resolve(result); resolve(result);
}); });
...@@ -52,7 +47,6 @@ function runProcess(local_repository, functionHash, port, resource_id) { ...@@ -52,7 +47,6 @@ function runProcess(local_repository, functionHash, port, resource_id) {
process.on('close', (code) => { process.on('close', (code) => {
console.log(`child process exited with code ${code}`); console.log(`child process exited with code ${code}`);
// workerEvent.emit('end', port, "process");
}); });
}) })
...@@ -89,7 +83,6 @@ function runContainer(imageName, port, resource_id) { ...@@ -89,7 +83,6 @@ function runContainer(imageName, port, resource_id) {
let timeDifference = Math.ceil((Date.now() - timeStart)) let timeDifference = Math.ceil((Date.now() - timeStart))
console.log("container run time taken: ", timeDifference); console.log("container run time taken: ", timeDifference);
result += data; result += data;
workerEvent.emit('start', imageName, port, "container")
resolve(result); resolve(result);
}); });
...@@ -99,7 +92,8 @@ function runContainer(imageName, port, resource_id) { ...@@ -99,7 +92,8 @@ function runContainer(imageName, port, resource_id) {
}); });
process.on('close', (code) => { process.on('close', (code) => {
workerEvent.emit('end', port, "container"); console.log("Exiting container");
}) })
} }
...@@ -115,8 +109,6 @@ function runContainer(imageName, port, resource_id) { ...@@ -115,8 +109,6 @@ function runContainer(imageName, port, resource_id) {
console.log(`stdout: ${data}`); console.log(`stdout: ${data}`);
let timeDifference = Math.ceil((Date.now() - timeStart)) let timeDifference = Math.ceil((Date.now() - timeStart))
console.log("container run time taken: ", timeDifference); console.log("container run time taken: ", timeDifference);
// result += data;
workerEvent.emit('start', imageName, port, "container")
resolve(result); resolve(result);
}); });
...@@ -126,7 +118,7 @@ function runContainer(imageName, port, resource_id) { ...@@ -126,7 +118,7 @@ function runContainer(imageName, port, resource_id) {
}); });
process.on('close', (code) => { process.on('close', (code) => {
workerEvent.emit('end', port, "container"); console.log("Exiting container");
}) })
} }
...@@ -138,11 +130,6 @@ function runContainer(imageName, port, resource_id) { ...@@ -138,11 +130,6 @@ function runContainer(imageName, port, resource_id) {
} }
parentProcess.stdout.on('data', data => {
console.log("handler", data);
})
module.exports.runContainer = runContainer; module.exports.runContainer = runContainer;
module.exports.runProcess = runProcess; module.exports.runProcess = runProcess;
module.exports.runIsolate = runIsolate; module.exports.runIsolate = runIsolate;
......
...@@ -13,10 +13,7 @@ const kafka = require('kafka-node') ...@@ -13,10 +13,7 @@ const kafka = require('kafka-node')
const local_repository = __dirname + "/local_repository/" const local_repository = __dirname + "/local_repository/"
const host_url = "http://" + constants.master_address + ":" + constants.master_port const host_url = "http://" + constants.master_address + ":" + constants.master_port
let usedPort = new Map()
let Producer = kafka.Producer, let Producer = kafka.Producer,
KeyedMessage = kafka.KeyedMessage,
client = new kafka.KafkaClient({ client = new kafka.KafkaClient({
kafkaHost: constants.kafka_host, kafkaHost: constants.kafka_host,
autoConnect: true autoConnect: true
...@@ -97,27 +94,6 @@ function heartbeat() { ...@@ -97,27 +94,6 @@ function heartbeat() {
producer.send(payload, function() {}) producer.send(payload, function() {})
} }
execute.workerEvent.on("start", (functionHash, port, runtime) => {
console.log("started function Port: ", port, functionHash);
// producer.send(
// [{
// topic: "deployed",
// messages: JSON.stringify({ functionHash, port, runtime, node_id })
// }], () => { })
})
execute.workerEvent.on('end', (port, runtime) => {
let functionHash = usedPort.get(port)
usedPort.delete(port)
// producer.send(
// [{
// topic: "removeWorker",
// messages: JSON.stringify({ functionHash, port, runtime, node_id })
// }], () => {
// console.log("Ending worker for function", functionHash, usedPort);
// })
})
grunt.stdout.on('data', data => { grunt.stdout.on('data', data => {
console.log(data.toString()); console.log(data.toString());
...@@ -130,6 +106,11 @@ grunt.stderr.on('data', data => { ...@@ -130,6 +106,11 @@ grunt.stderr.on('data', data => {
}) })
grunt.on('close', (code) => {
console.log("Grunt exited with exit code", code);
})
setInterval(heartbeat, 1000); setInterval(heartbeat, 1000);
/** /**
......
...@@ -43,6 +43,7 @@ function makeTopic(id) { ...@@ -43,6 +43,7 @@ function makeTopic(id) {
}) })
}) })
} }
var download = function (url, dest, cb) { var download = function (url, dest, cb) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log(url); console.log(url);
......
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