In production environment (using 10 nodes cluster) nomad "bin packing algorithm" causes big problems regarding system utilization.
The possible solution is to use the following rules/policies:
1. Distinct hosts
Use case: Mainly for multiple tcp/udp listeners behind a LoadBalancer. It works ok and exactly what would you expect.
2. Resource limiting
Via nomad-client conf as follows:
client {
enabled = true
cpu_total_compute = 12000
reserved {
cpu = 3000
memory = 33000
disk = 1
}
network_speed = 10000
servers = ["127.0.0.1:4647"]
options {
"driver.raw_exec.enable" = "1"
}
}
Painful and limiting
3. Spread stanza
Sounds promising but could not get it to work using NOMAD-SDK.
Nomad java SDK 0.9.0-SNAPSHOT doesn't support Spread stanza via API. Instead it is possible to use method "addUnmappedProperty" in order to add custom JSON structures/arrays.
Job jobSpec = nomadContext.getJob();
List<Object> spreads = new ArrayList<>();
Map<String, Object> spreadStanza = new HashMap<>();
spreadStanza.put("Attribute", "${node.unique.id}");
spreadStanza.put("Weight", 100);
// spreadStanza.put("SpreadTarget", null);
spreads.add(spreadStanza);
jobSpec.addUnmappedProperty("Spreads", spreads);
for(TaskGroup taskGroup: jobSpec.getTaskGroups()){
taskGroup.addUnmappedProperty("Spreads", spreads);
}
But unfortunately could not get it to work, allocation-spread is not shown in the verbose job status:
Another example uses simple hcl job specification deployed via command line params:
job "sleep" {
datacenters = ["dc1"]
spread {
attribute = "${node.unique.id}"
weight = 100
}
group "example" {
count=10
spread {
attribute = "${node.unique.id}"
weight = 100
}
task "server" {
driver = "raw_exec"
config {
command = "/bin/sleep"
args = [
"500"
]
}
resources {
network {
mbits = 10
}
}
}
}
}
In this case allocation-spread is shown
nomad alloc status -verbose 1feb7476
Node job-anti-affinity node-reschedule-penalty node-affinity allocation-spread binpack final score
4c4e3bb2-9568-3f5d-3a8c-fd056f258ed0 -0.4 0 0 0.667 0.896 0.387
4b36b048-a24b-e0e9-a789-625764fcfa70 -0.5 0 0 -0.667 0.901 -0.0886
I appreciate any help.
Thank you.