Skip to content

Commit 4f47dce

Browse files
shishir-a412edMahmood Ali
andcommitted
Add test for memory oversubscription.
Co-authored-by: Mahmood Ali <[email protected]>
1 parent 5945e43 commit 4f47dce

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

example/agent.hcl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ plugin "containerd-driver" {
88
}
99
}
1010

11+
server {
12+
default_scheduler_config {
13+
scheduler_algorithm = "spread"
14+
memory_oversubscription_enabled = true
15+
16+
preemption_config {
17+
batch_scheduler_enabled = true
18+
system_scheduler_enabled = true
19+
service_scheduler_enabled = true
20+
}
21+
}
22+
}
23+
1124
client {
1225
host_volume "s1" {
1326
path = "/tmp/host_volume/s1"

example/redis.nomad

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ job "redis" {
1313
}
1414

1515
resources {
16-
cpu = 500
17-
memory = 256
16+
cpu = 500
17+
memory = 256
18+
memory_max = 512
1819
}
1920
}
2021
}

tests/001-test-redis.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ test_redis_nomad_job() {
4949
exit 1
5050
fi
5151

52+
echo "INFO: Check if memory and memory_max are set correctly in the cgroup filesystem."
53+
task_name=$(sudo CONTAINERD_NAMESPACE=nomad ctr containers ls|awk 'NR!=1'|cut -d' ' -f1)
54+
memory_soft_limit=$(sudo cat /sys/fs/cgroup/memory/nomad/$task_name/memory.soft_limit_in_bytes)
55+
if [ $memory_soft_limit != "$(( 256 * 1024 * 1024 ))" ]; then
56+
echo "ERROR: memory should be 256 MB. Found ${memory_soft_limit}."
57+
exit 1
58+
fi
59+
memory_hard_limit=$(sudo cat /sys/fs/cgroup/memory/nomad/$task_name/memory.limit_in_bytes)
60+
if [ $memory_hard_limit != "$(( 512 * 1024 * 1024 ))" ]; then
61+
echo "ERROR: memory_max should be 512 MB. Found ${memory_hard_limit}."
62+
exit 1
63+
fi
64+
5265
echo "INFO: Stopping nomad redis job."
5366
nomad job stop redis
5467
redis_status=$(nomad job status -short redis|grep Status|awk '{split($0,a,"="); print a[2]}'|tr -d ' ')

0 commit comments

Comments
 (0)