Commit 4cc7e9e3 authored by Nilanjan Daw's avatar Nilanjan Daw

Moved longterm metrics to Exponential Average

parent 96dd7f78
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
"master_port": 8080, "master_port": 8080,
"master_address": "localhost", "master_address": "localhost",
"grunt_host": "https://www.namandixit.net/lovecraftian_nightmares/grunt", "grunt_host": "https://www.namandixit.net/lovecraftian_nightmares/grunt",
"log_channel": "LOG_COMMON",
"couchdb_host": "localhost:5984", "couchdb_host": "localhost:5984",
"couchdb_db_name": "serverless", "couchdb_db_name": "serverless",
"network": { "network": {
...@@ -21,7 +20,8 @@ ...@@ -21,7 +20,8 @@
"deployed": "deployed", "deployed": "deployed",
"remove_worker": "removeWorker", "remove_worker": "removeWorker",
"response_rm_2_dm": "RESPONSE_RM_2_DM_DUMMY", "response_rm_2_dm": "RESPONSE_RM_2_DM_DUMMY",
"hscale": "hscale" "hscale": "hscale",
"log_channel": "LOG_COMMON"
}, },
"autoscalar_metrics": { "autoscalar_metrics": {
"open_request_threshold": 100 "open_request_threshold": 100
......
...@@ -23,7 +23,7 @@ const app = express() ...@@ -23,7 +23,7 @@ const app = express()
const libSupport = require('./lib') const libSupport = require('./lib')
const logger = libSupport.logger const logger = libSupport.logger
let date = new Date(); let date = new Date();
let log_channel = constants.log_channel let log_channel = constants.topics.log_channel
let usedPort = new Map(), // TODO: remove after integration with RM let usedPort = new Map(), // TODO: remove after integration with RM
db = new Map(), // queue holding request to be dispatched db = new Map(), // queue holding request to be dispatched
......
...@@ -283,7 +283,7 @@ function logBroadcast(message, resource_id, resourceMap) { ...@@ -283,7 +283,7 @@ function logBroadcast(message, resource_id, resourceMap) {
message.function_id = resource.functionHash message.function_id = resource.functionHash
} }
let log = [{ let log = [{
topic: constants.log_channel, topic: constants.topics.log_channel,
messages: JSON.stringify(message), messages: JSON.stringify(message),
partition: 0 partition: 0
}] }]
......
const constants = require('.././constants.json'); const constants = require('.././constants.json');
const alpha = 0.99
let log_channel = constants.log_channel, let log_channel = constants.topics.log_channel,
metrics = { } metrics = { }
let kafka = require('kafka-node'), let kafka = require('kafka-node'),
...@@ -11,8 +11,15 @@ let kafka = require('kafka-node'), ...@@ -11,8 +11,15 @@ let kafka = require('kafka-node'),
}), }),
producer = new Producer(client) producer = new Producer(client)
/**
* Function called to report metric data related to functions
* @param {JSON} metric
*/
function collectMetrics(metric) { function collectMetrics(metric) {
/**
* If metrics for a new function comes in,
* provision required structure for the function
*/
if (!(metric.functionHash in metrics)) { if (!(metric.functionHash in metrics)) {
metrics[metric.functionHash] = { metrics[metric.functionHash] = {
shortterm: { shortterm: {
...@@ -36,6 +43,16 @@ function collectMetrics(metric) { ...@@ -36,6 +43,16 @@ function collectMetrics(metric) {
} }
/**
* Run periodically to calculate average runtime metrics like coldstart and
* warmstart latencies.
* The module provides two granularities for metrics - shortterm and longterm
* shortterm - realtime data at a granularity of 5s (set in dispatch_manager/lib.js)
* shortterm data is calculated using Simple Moving Average (SMA)
* longterm - longterm data is held and averaged out over a period of time.
* longterm data is calculated using Expontential Moving Average (EMA)
*/
function broadcastMetrics() { function broadcastMetrics() {
if (Object.keys(metrics).length !== 0) { if (Object.keys(metrics).length !== 0) {
...@@ -44,31 +61,26 @@ function broadcastMetrics() { ...@@ -44,31 +61,26 @@ function broadcastMetrics() {
if (metric.longterm === undefined) { if (metric.longterm === undefined) {
metric.longterm = { metric.longterm = {
coldstart: 0, coldstart: 0,
coldstart_total_request: 0,
warm_total_request: 0,
warmstart: 0 warmstart: 0
} }
} }
/**
metric.longterm.coldstart = metric.longterm.coldstart * Shortterm moving average
* metric.longterm.coldstart_total_request */
+ metric.shortterm.coldstart metric.shortterm.coldstart /= (metric.shortterm.coldstart_total_request != 0) ?
metric.shortterm.coldstart_total_request : 1
metric.longterm.coldstart_total_request += metric.shortterm.coldstart_total_request metric.shortterm.warmstart /= (metric.shortterm.warm_total_request != 0) ?
metric.longterm.coldstart /= (metric.longterm.coldstart_total_request != 0)? metric.shortterm.warm_total_request : 1
metric.longterm.coldstart_total_request: 1 /**
* Longterm exponential moving average
metric.longterm.warmstart = metric.longterm.warmstart */
* metric.longterm.warm_total_request if (metric.shortterm.coldstart != 0)
+ metric.shortterm.warmstart metric.longterm.coldstart = (metric.longterm.coldstart != 0)? metric.longterm.coldstart * alpha
metric.longterm.warm_total_request += metric.shortterm.warm_total_request + metric.shortterm.coldstart * (1 - alpha) : metric.shortterm.coldstart
metric.longterm.warmstart /= (metric.longterm.warm_total_request != 0)? if (metric.shortterm.warmstart != 0)
metric.longterm.warm_total_request: 1 metric.longterm.warmstart = (metric.longterm.warmstart != 0)? metric.longterm.warmstart * alpha
+ metric.shortterm.warmstart * (1 - alpha) : metric.shortterm.warmstart
metric.shortterm.coldstart /= (metric.shortterm.coldstart_total_request != 0)?
metric.shortterm.coldstart_total_request: 1
metric.shortterm.warmstart /= (metric.shortterm.warm_total_request != 0)?
metric.shortterm.warm_total_request: 1
metric.timestamp = Date.now() metric.timestamp = Date.now()
} }
......
const constants = require('./constants.json')
const util = require('util')
let kafka = require('kafka-node'),
Producer = kafka.Producer,
client = new kafka.KafkaClient({
kafkaHost: constants.network.external.kafka_host,
autoConnect: true
}),
producer = new Producer(client),
Consumer = kafka.Consumer,
consumer = new Consumer(client,
[
{ topic: constants.topics.log_channel }
])
consumer.on('message', function (message) {
message = JSON.parse(message.value)
console.log(util.inspect(message, false, null, true /* enable colors */))
})
\ No newline at end of file
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