Autoscaling functions

#1

When autoscaling is on, is there a function that tells me how long it will take for the queue to fully drain?

0 Likes

#2

I wrote a little function that produces the ETA with some degree of accuracy:

// helper function to display human-readable ETAs

function timeConversion(millisec) {

        var seconds = (millisec / 1000).toFixed(1);
        var minutes = (millisec / (1000 * 60)).toFixed(1);
        var hours = (millisec / (1000 * 60 * 60)).toFixed(1);
        var days = (millisec / (1000 * 60 * 60 * 24)).toFixed(1);

        if (seconds < 60) {
            return seconds + " Sec";
        } else if (minutes < 60) {
            return minutes + " Min";
        } else if (hours < 24) {
            return hours + " Hrs";
        } else {
            return days + " Days"
        }
    };


// monitor queues

  var lastMonitorQueuesIntervalId = null;

  function monQ() {
    stopMonitorQueues();
    var queues = [];
    var period = 60000;
    var lastValue = {};
	var lastTime = null;
    for (var i = 0; i < arguments.length; i++)
      if (typeof(arguments[i]) === "number")
        period = arguments[i]*60000;
    else
      queues.push(arguments[i]);
    if (queues.length == 0)
      queues = [MapReduceQueue, BatchQueue, CalcFieldsQueue, NormalizationQueue, PopulateAclQueue, CascadeQueue, HierDenormQueue, ActionQueue, MetricDepsQueue, MetricsQueue, AnalyticsQueue, JmsDataLoadQueue, CronQueue];
    var f = function() {
      // console.log('QUEUES: ' + new Date().toString());
      for (var i = 0; i < queues.length; i++) {
	    var t_start = new Date.now();
        var c = queues[i].count();
        var t_end = new Date.now();
		var duration = t_end - t_start;
        var rate = null;
        var etc = null;
        var compTime = null;
		if (c.pending < lastValue[queues[i]]) {
			rate = lastValue[queues[i]] - c.pending;
			etc = (c.pending / (lastValue[queues[i]] - c.pending)).toFixed(0) * (t_end - lastTime);
			compTime = Date.now().plusMillis(etc).toString("HH:mm");
			lastTime = t_end;
		}
        if (c.pending + c.computingActions + c.failed > 0)
          console.log('? ' + new Date().toString("HH:mm:ss") + " " + queues[i].typeName() + " - ", {pending:c.pending, rate:(rate ? rate : "N/A"), ETC:(etc ? timeConversion(etc) : "N/A"), compTime:(etc ? compTime :"N/A"), computingActions:c.computingActions, failed:c.failed});
        lastValue[queues[i]] = c.pending;
      }
    }
    f();
    lastMonitorQueuesIntervalId = setInterval(f, period);
  };
  function stopMonitorQueues() {
    if (lastMonitorQueuesIntervalId)
      clearInterval(lastMonitorQueuesIntervalId);
    lastMonitorQueuesIntervalId = null;
  };

The way you invoke it is monQ(QueueName, periodInMinutes). On second run, it will start displaying ETAs.

0 Likes