Skip to content

Releases: schmichael/nomad

v0.11.1-dev+datalog

17 Apr 18:39
Compare
Choose a tag to compare

v0.11.1-dev+scorejs

17 Apr 18:20
Compare
Choose a tag to compare
v0.11.1-dev+scorejs Pre-release
Pre-release

I jammed Javascript into Nomad's scoring fitness algorithm so you can write any algorithm you want!

For example the following jobspec runs 2 task groups with 2 instances ("allocations") each with a WorstFit algorithm instead of the usual BestFit algorithm:

job "redis" {
  datacenters = ["dc1", "dc2"]

  score_func = <<EOF
var freeCPU = 1 - (used.Flattened.Cpu.CpuShares / avail.Flattened.Cpu.CpuShares)
var freeRAM = 1 - (used.Flattened.Memory.MemoryMB / avail.Flattened.Memory.MemoryMB)
var total = Math.pow(10, freeCPU) + Math.pow(10, freeRAM)

// Normalize
var result = (total - 2) / 18
result
EOF

  meta {
   v = "1"
  }

  group "api" {
    count = 2

    task "redis" {
      driver = "docker"

      config {
        image = "redis:3.2"
        command = "/bin/sh"
        args    = ["-c", "while true; do redis-cli -h $h -p $p ping; sleep 1; done"]
      }

      template {
        data = <<EOF
{{ range service "cache|any" }}
h={{ .Address }}
p={{ .Port }}
{{ end }}
EOF
        destination = "local/env"
        env = true
      }

      resources {
        cpu    = 500
        memory = 256
      }
    }
  }

  group "cache" {
    count = 2

    task "redis" {
      driver = "docker"

      config {
        image = "redis:3.2"

        port_map {
          db = 6379
        }
      }

      resources {
        cpu    = 500
        memory = 256

        network {
          mbits = 10
          port  "db"  {}
        }
      }

      service {
        name = "cache"
        port = "db"
      }
    }
  }
}