Skip to content

Instantly share code, notes, and snippets.

@leecardona
Last active September 5, 2016 00:46
Show Gist options
  • Save leecardona/10058f72d9efae8ee76a74add7547fa6 to your computer and use it in GitHub Desktop.
Save leecardona/10058f72d9efae8ee76a74add7547fa6 to your computer and use it in GitHub Desktop.
/* ====================================================================
* File: scale.js
* Authors: Lee Cardona
* Copyright (c) 2016 Nuvem Newtworks Inc. All rights reserved.
* ====================================================================
*/
var scale = {
init : function () {
scale.setValues()
scale.bindEvents()
scale.log('[ OK ] scale module loading completed...')
},
setValues : function () {
scale.common = require('./common')
scale.workers = require('./workers')
scale.requests = require('./requests')
scale.version = scale.common.version
scale.id = scale.common.id
scale.log = scale.common.log
},
bindEvents : function () {
exports._id = scale.id
exports.version = scale.version
exports.main = scale.main
},
main : function () {
//REQUEST STATES = queued | processing | processed
//WORKERS STATES = idle | working
if ( scale.requests.queued.count > scale.workers.idle.count ) {
//MORE REQUESTS THAN AVAILABLE WORKERS SCALE UP
scale.workers.up( scale.requests.queued.count - scale.workers.idle.count )
scale.workers.process(scale.requests.queued)
} else if ( scale.requests.queued.count < scale.workers.idle.count ) {
//MORE WORKERS THAN NEEDED SCALE DOWN
scale.workers.down( scale.workers.idle.count - scale.requests.queued.count )
scale.workers.process(scale.requests.queued)
} else {
//REQUESTS MATCH AVAILABLE WORKERS - NO SCALING NEEDED
scale.workers.process(scale.requests.queued)
}
}
}
scale.init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment