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,26 +515,86 @@ function autoscalar() { ...@@ -515,26 +515,86 @@ 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) {
if (constants.JIT_deployment) {
/**
* Perform Speculation with JIT
*/
for (let node of branchInfo.mle_path) for (let node of branchInfo.mle_path)
node.id = node.node node.id = node.node
let metrics = await libSupport.fetchData(metricsDB + "_bulk_get", { let metricsPromise = libSupport.fetchData(metricsDB + "_bulk_get", {
method: 'post',
body: JSON.stringify({
docs: branchInfo.mle_path
}),
headers: { 'Content-Type': 'application/json' },
})
let chainDataPromise = libSupport.fetchData(implicitChainDB + "_bulk_get", {
method: 'post', method: 'post',
body: JSON.stringify({ body: JSON.stringify({
docs: branchInfo.mle_path docs: branchInfo.mle_path
}), }),
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
}) })
console.log(util.inspect(metrics, false, null, true /* enable colors */))
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) { for (let node of branchInfo.mle_path) {
// console.log(functionToResource); // console.log(functionToResource);
...@@ -552,6 +612,7 @@ async function speculative_deployment(req, runtime) { ...@@ -552,6 +612,7 @@ async function speculative_deployment(req, runtime) {
} }
} }
} }
}
} }
setInterval(libSupport.metrics.broadcastMetrics, 5000) setInterval(libSupport.metrics.broadcastMetrics, 5000)
setInterval(autoscalar, 1000); setInterval(autoscalar, 1000);
......
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