Skip to content

Instantly share code, notes, and snippets.

@tony612
Last active April 27, 2024 03:22
Show Gist options
  • Save tony612/322e212913344c75c144c12493d75f7c to your computer and use it in GitHub Desktop.
Save tony612/322e212913344c75c144c12493d75f7c to your computer and use it in GitHub Desktop.

Erlang honors cgroup CPU quota from Erlang 23. But when less than 1 CPU is used, schedulers_online will be cores number(see below k8s 0-5).

docker

$ docker run --rm -it --cpu-period 100000 --cpu-quota 100000 erlang:23 bash
root@3f793576001a:/# erl
Erlang/OTP 23 [erts-11.0.2] [source] [64-bit] [smp:4:1] [ds:4:1:10] [async-threads:1] [hipe]

Eshell V11.0.2  (abort with ^G)
1> erlang:system_info(schedulers_online).
1

Kubernetes

$ alias k=kubectl
$ k apply -f .

# Erlang 22
$ k exec -it erlang-22-cpu-demo-0-5 -- bash
root@erlang-22-cpu-demo-0-5:/# erl
Erlang/OTP 22 [erts-10.7.2.1] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]

Eshell V10.7.2.1  (abort with ^G)
1> erlang:system_info(schedulers_online).
2

k exec -it erlang-22-cpu-demo-1 -- bash
root@erlang-22-cpu-demo-1:/# erl
Erlang/OTP 22 [erts-10.7.2.1] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]

Eshell V10.7.2.1  (abort with ^G)
1> erlang:system_info(schedulers_online).
2

$ k exec -it erlang-22-cpu-demo-2 -- bash
root@erlang-22-cpu-demo-2:/# erl
Erlang/OTP 22 [erts-10.7.2.1] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]

Eshell V10.7.2.1  (abort with ^G)
1> erlang:system_info(schedulers_online).
2

# Erlang 23

$ k exec -it erlang-23-cpu-demo-0-5 -- bash
root@erlang-23-cpu-demo-0-5:/# erl
Erlang/OTP 23 [erts-11.0.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]

Eshell V11.0.2  (abort with ^G)
1> erlang:system_info(schedulers_online).
2

k exec -it erlang-23-cpu-demo-1 -- bash
root@erlang-23-cpu-demo-1:/# erl
Erlang/OTP 23 [erts-11.0.2] [source] [64-bit] [smp:2:1] [ds:2:1:10] [async-threads:1] [hipe]

Eshell V11.0.2  (abort with ^G)
1> erlang:system_info(schedulers_online).
1

k exec -it erlang-23-cpu-demo-2 -- bash
root@erlang-23-cpu-demo-2:/# erl
Erlang/OTP 23 [erts-11.0.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]

Eshell V11.0.2  (abort with ^G)
1> erlang:system_info(schedulers_online).
2
apiVersion: v1
kind: Pod
metadata:
name: erlang-22-cpu-demo-0-5
spec:
containers:
- name: app
image: erlang:22
resources:
limits:
cpu: 500m
requests:
cpu: 500m
command: ["sleep", "3600"]
apiVersion: v1
kind: Pod
metadata:
name: erlang-22-cpu-demo-1
spec:
containers:
- name: app
image: erlang:22
resources:
limits:
cpu: 1000m
requests:
cpu: 1000m
command: ["sleep", "3600"]
apiVersion: v1
kind: Pod
metadata:
name: erlang-22-cpu-demo-2
spec:
containers:
- name: app
image: erlang:22
resources:
limits:
cpu: 2000m
requests:
cpu: 1000m
command: ["sleep", "3600"]
apiVersion: v1
kind: Pod
metadata:
name: erlang-23-cpu-demo-0-5
spec:
containers:
- name: app
image: erlang:23
resources:
limits:
cpu: 500m
requests:
cpu: 500m
command: ["sleep", "3600"]
apiVersion: v1
kind: Pod
metadata:
name: erlang-23-cpu-demo-1
spec:
containers:
- name: app
image: erlang:23
resources:
limits:
cpu: 1000m
requests:
cpu: 1000m
command: ["sleep", "3600"]
apiVersion: v1
kind: Pod
metadata:
name: erlang-23-cpu-demo-2
spec:
containers:
- name: app
image: erlang:23
resources:
limits:
cpu: 2000m
requests:
cpu: 1000m
command: ["sleep", "3600"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment