Commit c7f1b2a2 authored by nilanjandaw's avatar nilanjandaw

Added worker start time metrics

parent 5d3d4f56
...@@ -330,7 +330,7 @@ function postDeploy(message) { ...@@ -330,7 +330,7 @@ function postDeploy(message) {
"status": true, "status": true,
starttime: (Date.now() - resource.deploy_request_time) starttime: (Date.now() - resource.deploy_request_time)
}, message.resource_id, resourceMap) }, message.resource_id, resourceMap)
if (db.has(id)) { if (db.has(id)) {
let sendQueue = db.get(id) let sendQueue = db.get(id)
logger.info("forwarding request via reverse proxy to: " + JSON.stringify(resource)); logger.info("forwarding request via reverse proxy to: " + JSON.stringify(resource));
...@@ -345,8 +345,9 @@ function postDeploy(message) { ...@@ -345,8 +345,9 @@ function postDeploy(message) {
} }
libSupport.metrics.collectMetrics({type: "scale", value: libSupport.metrics.collectMetrics({type: "scale", value:
functionToResource.get(id).length, functionToResource.get(id).length,
functionHash: message.functionHash, runtime: message.runtime}) functionHash: message.functionHash, runtime: message.runtime,
starttime: (Date.now() - resource.deploy_request_time)})
} catch (e) { } catch (e) {
logger.error(e.message) logger.error(e.message)
} }
......
...@@ -37,8 +37,10 @@ function collectMetrics(metric) { ...@@ -37,8 +37,10 @@ function collectMetrics(metric) {
coldstart: 0, coldstart: 0,
coldstart_total_request: 0, coldstart_total_request: 0,
warm_total_request: 0, warm_total_request: 0,
scale_count: 0,
warmstart: 0, warmstart: 0,
worker_count: 0 worker_count: 0,
starttime: 0
} }
} }
} }
...@@ -50,9 +52,12 @@ function collectMetrics(metric) { ...@@ -50,9 +52,12 @@ function collectMetrics(metric) {
metrics[metric.functionHash][metric.runtime].shortterm.warm_total_request += 1 metrics[metric.functionHash][metric.runtime].shortterm.warm_total_request += 1
} else if (metric.type === 'scale') { } else if (metric.type === 'scale') {
metrics[metric.functionHash][metric.runtime].shortterm.worker_count = metric.value metrics[metric.functionHash][metric.runtime].shortterm.worker_count = metric.value
if (metric.starttime !== undefined) {
metrics[metric.functionHash][metric.runtime].shortterm.starttime += metric.starttime
metrics[metric.functionHash][metric.runtime].shortterm.scale_count += 1
}
} }
} }
...@@ -71,26 +76,32 @@ async function broadcastMetrics() { ...@@ -71,26 +76,32 @@ async function broadcastMetrics() {
for (let [runtime, metricData] of Object.entries(data)) { for (let [runtime, metricData] of Object.entries(data)) {
if (metricData.shortterm.coldstart != 0 || metricData.shortterm.longterm != 0) { if (metricData.shortterm.coldstart != 0 || metricData.shortterm.longterm != 0) {
let { metric, dbData } = await fetchData(functionHash, metricData, runtime) let { metric, dbData } = await fetchData(functionHash, metricData, runtime)
/** /**
* Shortterm moving average * Shortterm moving average
*/ */
metric.shortterm.coldstart /= (metric.shortterm.coldstart_total_request != 0) ? metric.shortterm.coldstart /= (metric.shortterm.coldstart_total_request != 0) ?
metric.shortterm.coldstart_total_request : 1 metric.shortterm.coldstart_total_request : 1
metric.shortterm.starttime /= (metric.shortterm.scale_count != 0) ?
metric.shortterm.scale_count : 1
metric.shortterm.warmstart /= (metric.shortterm.warm_total_request != 0) ? metric.shortterm.warmstart /= (metric.shortterm.warm_total_request != 0) ?
metric.shortterm.warm_total_request : 1 metric.shortterm.warm_total_request : 1
/** /**
* Longterm exponential moving average * Longterm exponential moving average
*/ */
if (metric.shortterm.coldstart != 0) if (metric.shortterm.coldstart != 0)
metric.longterm.coldstart = (metric.longterm.coldstart != 0) ? metric.longterm.coldstart * alpha metric.longterm.coldstart = (metric.longterm.coldstart != 0) ? metric.longterm.coldstart * alpha
+ metric.shortterm.coldstart * (1 - alpha) : metric.shortterm.coldstart + metric.shortterm.coldstart * (1 - alpha) : metric.shortterm.coldstart
if (metric.shortterm.starttime && metric.shortterm.starttime != 0)
metric.longterm.starttime = (metric.longterm.starttime != 0) ? metric.longterm.starttime * alpha
+ metric.shortterm.starttime * (1 - alpha) : metric.shortterm.starttime
if (metric.shortterm.warmstart != 0) if (metric.shortterm.warmstart != 0)
metric.longterm.warmstart = (metric.longterm.warmstart != 0) ? metric.longterm.warmstart * alpha metric.longterm.warmstart = (metric.longterm.warmstart != 0) ? metric.longterm.warmstart * alpha
+ metric.shortterm.warmstart * (1 - alpha) : metric.shortterm.warmstart + metric.shortterm.warmstart * (1 - alpha) : metric.shortterm.warmstart
dbData[runtime] = { dbData[runtime] = {
coldstart: metric.longterm.coldstart, coldstart: metric.longterm.coldstart,
warmstart: metric.longterm.warmstart, warmstart: metric.longterm.warmstart,
starttime: metric.longterm.starttime
} }
let payload = { let payload = {
method: 'put', method: 'put',
...@@ -120,7 +131,9 @@ async function broadcastMetrics() { ...@@ -120,7 +131,9 @@ async function broadcastMetrics() {
coldstart_total_request: 0, coldstart_total_request: 0,
warm_total_request: 0, warm_total_request: 0,
warmstart: 0, warmstart: 0,
worker_count: 0 worker_count: 0,
starttime: 0,
scale_count: 0
} }
} }
} }
...@@ -139,12 +152,14 @@ async function fetchData(functionHash, metric, runtime) { ...@@ -139,12 +152,14 @@ async function fetchData(functionHash, metric, runtime) {
if (json.error === "not_found" || json[runtime] === undefined) { if (json.error === "not_found" || json[runtime] === undefined) {
metric.longterm = { metric.longterm = {
coldstart: 0, coldstart: 0,
warmstart: 0 warmstart: 0,
starttime: 0
} }
} else { } else {
metric.longterm = { metric.longterm = {
coldstart: json[runtime].coldstart, coldstart: json[runtime].coldstart,
warmstart: json[runtime].warmstart, warmstart: json[runtime].warmstart,
starttime: (json[runtime].starttime) ? json[runtime].starttime: 0
} }
} }
return { return {
......
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