Commit 05a35530 authored by Nilanjan Daw's avatar Nilanjan Daw

JIT deployment for implicit chains

Added support for JIT deployment of implicit chains. Primary testing done
parent 190809a4
...@@ -522,5 +522,5 @@ function createDirectory(path) { ...@@ -522,5 +522,5 @@ function createDirectory(path) {
module.exports = { module.exports = {
router router, notify
} }
...@@ -515,38 +515,99 @@ function autoscalar() { ...@@ -515,38 +515,99 @@ function autoscalar() {
* *
* FIXME: Currently supports homogenous runtime chain i.e takes runtime as a param. * FIXME: Currently supports homogenous runtime chain i.e takes runtime as a param.
* Change it to also profile runtime * Change it to also profile runtime
* FIXME: Hardcoded container as a runtime. Make dynamic.
*/ */
async function speculative_deployment(req, runtime) { async function speculative_deployment(req, runtime) {
if (constants.speculative_deployment && req.headers['x-resource-id'] === undefined) { if (constants.speculative_deployment && req.headers['x-resource-id'] === undefined) {
// console.log(functionBranchTree, req.params.id); // console.log(functionBranchTree, req.params.id);
if (!functionBranchTree.has(req.params.id)) {
let data = await libSupport.fetchData(implicitChainDB + req.params.id)
if (data.error !== "not_found") {
data.branches = new Map(data.branches)
functionBranchTree.set(req.params.id, data)
}
}
console.log(util.inspect(functionBranchTree, false, null, true /* enable colors */));
if (functionBranchTree.has(req.params.id)) { if (functionBranchTree.has(req.params.id)) {
let branchInfo = functionBranchTree.get(req.params.id) let branchInfo = functionBranchTree.get(req.params.id)
console.log("mle_path", branchInfo.mle_path); console.log("mle_path", branchInfo.mle_path);
if (branchInfo.mle_path && branchInfo.mle_path.length > 1) { if (branchInfo.mle_path && branchInfo.mle_path.length > 1) {
for (let node of branchInfo.mle_path)
node.id = node.node if (constants.JIT_deployment) {
let metrics = await libSupport.fetchData(metricsDB + "_bulk_get", { /**
method: 'post', * Perform Speculation with JIT
body: JSON.stringify({ */
docs: branchInfo.mle_path for (let node of branchInfo.mle_path)
}), node.id = node.node
headers: { 'Content-Type': 'application/json' }, let metricsPromise = libSupport.fetchData(metricsDB + "_bulk_get", {
}) method: 'post',
console.log(util.inspect(metrics, false, null, true /* enable colors */)) body: JSON.stringify({
docs: branchInfo.mle_path
for (let node of branchInfo.mle_path) { }),
// console.log(functionToResource); headers: { 'Content-Type': 'application/json' },
})
if (!functionToResource.has(node.node + runtime) && !db.has(node.node + runtime)) {
console.log("Deploying according to MLE path: ", node.node); let chainDataPromise = libSupport.fetchData(implicitChainDB + "_bulk_get", {
method: 'post',
let payload = [{ body: JSON.stringify({
topic: constants.topics.hscale, docs: branchInfo.mle_path
messages: JSON.stringify({ "runtime": "container", "functionHash": node.node }) }),
}] headers: { 'Content-Type': 'application/json' },
producer.send(payload, function () { }) })
db.set(node.node + runtime, [])
Promise.all([metricsPromise, chainDataPromise])
.then(data => {
let metrics = new Map(), chainData = new Map()
let currentDelay = 0
data[0] = data[0].results, data[1] = data[1].results
for (let i = 0; i < branchInfo.mle_path.length; i++) {
let id = data[0][i].id
metrics[id] = data[0][i].docs[0].ok
id = data[1][i].id
chainData[id] = data[1][i].docs[0].ok
if (chainData[id])
chainData[id].branches = new Map(chainData[id].branches)
}
currentDelay = metrics[branchInfo.mle_path[0].id].container.starttime
for (let i = 1; i < branchInfo.mle_path.length; i++) {
let parent = chainData[branchInfo.mle_path[i - 1].id]
let self = branchInfo.mle_path[i].id
console.log(self);
console.log("parent branches", parent.branches.get(self)[1]);
currentDelay += parent.branches.get(self)[1]
let invokeTime = currentDelay - metrics[self].container.starttime
invokeTime = (invokeTime < 0)? 0: invokeTime
console.log(self, "invoke time:", currentDelay - metrics[self].container.starttime);
console.log("current delay", currentDelay, "start time", metrics[self].container.starttime);
setTimeout(chainHandler.notify, invokeTime, "container", self)
}
})
} else {
/**
* Perform Speculation without JIT
*/
for (let node of branchInfo.mle_path) {
// console.log(functionToResource);
if (!functionToResource.has(node.node + runtime) && !db.has(node.node + runtime)) {
console.log("Deploying according to MLE path: ", node.node);
let payload = [{
topic: constants.topics.hscale,
messages: JSON.stringify({ "runtime": "container", "functionHash": node.node })
}]
producer.send(payload, function () { })
db.set(node.node + runtime, [])
}
} }
} }
} }
......
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