updating startRunners command.
This commit is contained in:
parent
cac789fed3
commit
ce31c7f1d5
27
allocate_runners.sh
Normal file
27
allocate_runners.sh
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
maxMemoryUsage=80;
|
||||||
|
baseName="crunner0";
|
||||||
|
namePrefix="cubs";
|
||||||
|
runners="";
|
||||||
|
|
||||||
|
function usedMemoryPercent () {
|
||||||
|
memoryAvailable=$(head /proc/meminfo|grep MemAvail|grep -Po '\d+');
|
||||||
|
totalMemory=$(head /proc/meminfo|grep MemTotal|grep -Po '\d+');
|
||||||
|
difference=$(expr $totalMemory - $memoryAvailable);
|
||||||
|
difference=$(expr $difference \* 100);
|
||||||
|
memory=$(expr $difference / $totalMemory);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
usedMemoryPercent;
|
||||||
|
until [[ $memory -gt $maxMemoryUsage ]]; do
|
||||||
|
|
||||||
|
runnerName="${namePrefix}${RANDOM}";
|
||||||
|
lxc-start-ephemeral -o $baseName -n $runnerName --union-type overlayfs -d
|
||||||
|
if[[ $? -eq 0 ]]
|
||||||
|
then
|
||||||
|
runners="${runners};${runnerName}";
|
||||||
|
fi
|
||||||
|
usedMemoryPercent;
|
||||||
|
done
|
||||||
|
|
||||||
|
echo $runners
|
19
docs/lxc-world.md
Normal file
19
docs/lxc-world.md
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
##### LXC Commands
|
||||||
|
|
||||||
|
|
||||||
|
`lxc-top`:
|
||||||
|
|
||||||
|
Realtime Meta data about containers(not machine friendly). Monitor container statistics.
|
||||||
|
|
||||||
|
`lxc-ls --fancy`:
|
||||||
|
|
||||||
|
list of existing containers
|
||||||
|
|
||||||
|
`lxc-start-ephemeral`, `lxc-copy`:
|
||||||
|
|
||||||
|
start an ephemeral copy of an existing container
|
||||||
|
|
||||||
|
|
||||||
|
`lxc-attach`:
|
||||||
|
|
||||||
|
start a process inside a running container.(enter the droplet)
|
27
docs/memory-managment.md
Normal file
27
docs/memory-managment.md
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
##### Memory Managment
|
||||||
|
|
||||||
|
|
||||||
|
`free`, `free -h`:
|
||||||
|
|
||||||
|
display amount of free and used memory in the system.
|
||||||
|
* Disclamers:
|
||||||
|
- DO NOT USE IN SCRIPT
|
||||||
|
|
||||||
|
`/proc/`:
|
||||||
|
|
||||||
|
It is actually an kernel application. Looks like a file, but is actually generated on demand by the kernel. All "files" in proc are kernal commands. Interact with these commands as if they were files.
|
||||||
|
|
||||||
|
|
||||||
|
`/proc/meminfo`:
|
||||||
|
|
||||||
|
File containing realtime memory info.
|
||||||
|
|
||||||
|
`/proc/cpuinfo`:
|
||||||
|
|
||||||
|
cpu info
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
`/dev`:
|
||||||
|
|
||||||
|
DANGER This folder contains physical interfaces to hardware on or connected to the machine. Just don't. Read first. Except `/dev/null` it is a blackhole.
|
@ -4,6 +4,7 @@ var jsonfile = require('jsonfile');
|
|||||||
var lxc = require('../lxc');
|
var lxc = require('../lxc');
|
||||||
var doapi = require('../doapi')();
|
var doapi = require('../doapi')();
|
||||||
var settings = require('./workers.json');
|
var settings = require('./workers.json');
|
||||||
|
var fs = require('fs');
|
||||||
settings.tagPrefix = settings.tagPrefix || 'clwV';
|
settings.tagPrefix = settings.tagPrefix || 'clwV';
|
||||||
|
|
||||||
var utils = (function(){
|
var utils = (function(){
|
||||||
@ -42,7 +43,6 @@ var Runner = (function(){
|
|||||||
proto.create = function(config){
|
proto.create = function(config){
|
||||||
var runner = Object.create(proto);
|
var runner = Object.create(proto);
|
||||||
Object.assign(runner, config);
|
Object.assign(runner, config);
|
||||||
runner.cleanUp = __empty;
|
|
||||||
return runner;
|
return runner;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ var Runner = (function(){
|
|||||||
runner.cleanUp();
|
runner.cleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
runner.worker.startRunners();
|
runner.worker.newStartRunners();
|
||||||
};
|
};
|
||||||
|
|
||||||
proto.setTimeout = function(time){
|
proto.setTimeout = function(time){
|
||||||
@ -143,7 +143,7 @@ var Worker = (function(){
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
proto.initialize = function(hooks, config){
|
proto.initialize = function(callback, config){
|
||||||
// Create droplet
|
// Create droplet
|
||||||
// Once active the droplet begins to create runners
|
// Once active the droplet begins to create runners
|
||||||
doapi.dropletToActive({
|
doapi.dropletToActive({
|
||||||
@ -158,10 +158,48 @@ var Worker = (function(){
|
|||||||
},
|
},
|
||||||
onActive: function(data, args){
|
onActive: function(data, args){
|
||||||
var worker = Worker.create(data);
|
var worker = Worker.create(data);
|
||||||
worker.startRunners(hooks);
|
worker.newStartRunners(callback);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
proto.newStartRunners = function(args){
|
||||||
|
// onStart is not necessary
|
||||||
|
var worker = this;
|
||||||
|
args.stopPercent = args.stopPercent || 80;
|
||||||
|
args.callback = args.callback || __empty;
|
||||||
|
|
||||||
|
// dont make runners on out dated workers
|
||||||
|
if(!worker || worker.settings.image > worker.image.id || worker.isBuildingRunners){
|
||||||
|
if(worker) {
|
||||||
|
console.log(`
|
||||||
|
Blocked worker(${worker.image.id}), current image ${worker.settings.image}.
|
||||||
|
Building: ${worker.isBuildingRunners}
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
worker.isBuildingRunners = true;
|
||||||
|
fs.read(__dirname + "../allocate_runners.sh", function(error, data){
|
||||||
|
console.log(data);
|
||||||
|
// lxc.exec(data, function(output){
|
||||||
|
// // output chould be list of runner names
|
||||||
|
// console.log(output);
|
||||||
|
// // for name in output:
|
||||||
|
// // var runner = Runner.create({
|
||||||
|
// // "name": name,
|
||||||
|
// // "worker": worker,
|
||||||
|
// // "label": worker.name + ':' + name
|
||||||
|
// // });
|
||||||
|
|
||||||
|
// // worker.availrunners.push(runner);
|
||||||
|
// // end for
|
||||||
|
// worker.isBuildingRunners = false;
|
||||||
|
// args.callback(worker);
|
||||||
|
// });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
proto.startRunners = function(args){
|
proto.startRunners = function(args){
|
||||||
var worker = this;
|
var worker = this;
|
||||||
@ -179,6 +217,8 @@ var Worker = (function(){
|
|||||||
args.onDone = args.onDone || __empty;
|
args.onDone = args.onDone || __empty;
|
||||||
|
|
||||||
worker.isBuildingRunners = true;
|
worker.isBuildingRunners = true;
|
||||||
|
|
||||||
|
// no longer needed
|
||||||
worker.ramPercentUsed(function(usedMemPercent){
|
worker.ramPercentUsed(function(usedMemPercent){
|
||||||
console.log(arguments);
|
console.log(arguments);
|
||||||
if(usedMemPercent > args.stopPercent ){
|
if(usedMemPercent > args.stopPercent ){
|
||||||
@ -199,6 +239,11 @@ var Worker = (function(){
|
|||||||
var name = 'crunner-' + utils.uuid();
|
var name = 'crunner-' + utils.uuid();
|
||||||
// console.log('Free ram check passed!')
|
// console.log('Free ram check passed!')
|
||||||
lxc.startEphemeral(name, 'crunner0', worker.ip, function(data){
|
lxc.startEphemeral(name, 'crunner0', worker.ip, function(data){
|
||||||
|
setTimeout(function(){
|
||||||
|
worker.isBuildingRunners = false;
|
||||||
|
worker.startRunners(args);
|
||||||
|
}, 0);
|
||||||
|
|
||||||
if(data.ip){
|
if(data.ip){
|
||||||
console.log('started runner on', worker.name);
|
console.log('started runner on', worker.name);
|
||||||
|
|
||||||
@ -214,10 +259,6 @@ var Worker = (function(){
|
|||||||
worker.availrunners.push(runner);
|
worker.availrunners.push(runner);
|
||||||
}
|
}
|
||||||
|
|
||||||
return setTimeout(function(){
|
|
||||||
worker.isBuildingRunners = false;
|
|
||||||
worker.startRunners(args);
|
|
||||||
}, 0);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return setTimeout(function(){
|
return setTimeout(function(){
|
||||||
@ -289,19 +330,12 @@ var WorkerCollection = (function(){
|
|||||||
workers.currentCreating++;
|
workers.currentCreating++;
|
||||||
|
|
||||||
config = config || workers.settings;
|
config = config || workers.settings;
|
||||||
|
Worker.initialize(function(worker){
|
||||||
var args = {
|
console.log("Seeded runners on", worker.name);
|
||||||
onStart: function(worker, args){
|
workers.push(worker);
|
||||||
workers.push(worker);
|
worker.register();
|
||||||
worker.register();
|
workers.currentCreating--;
|
||||||
args.onStart = function(){};
|
}, config);
|
||||||
},
|
|
||||||
onDone: function(worker, args){
|
|
||||||
console.log("Seeded runners on", worker.name);
|
|
||||||
workers.currentCreating--;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Worker.initialize(args, config);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
workers.__workersId = function(argument){
|
workers.__workersId = function(argument){
|
||||||
|
@ -68,4 +68,4 @@ let __do = function(till){
|
|||||||
setTimeout(__do, 1500, --till);
|
setTimeout(__do, 1500, --till);
|
||||||
};
|
};
|
||||||
|
|
||||||
__do(4);
|
__do(1000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user