Community discussions

MikroTik App
 
dc2
just joined
Topic Author
Posts: 24
Joined: Thu Jun 14, 2018 7:16 pm

Launch container with CPU limit

Mon May 29, 2023 4:59 pm

Hi All,

I know we can launch containers with a limit on RAM use - i.e. a high threshold for the total RAM consumed by all containers (please confirm this is total and not per-container)...

Can we apply a similar CPU limit?

I currently have one container I want to run and limit that to 1 vCPU. In Docker Engine I will typically test with
 docker run --memory="200m" --cpus="1" container-name 
Thank you.
 
optio
Long time Member
Long time Member
Posts: 672
Joined: Mon Dec 26, 2022 2:57 pm

Re: Launch container with CPU limit

Mon May 29, 2023 10:42 pm

I currently have one container I want to run and limit that to 1 vCPU. In Docker Engine I will typically test with
 docker run --memory="200m" --cpus="1" container-name 
That feature is not implemented in ROS afaik, but some services can have parallel threads limit in their configuration, which actually limits cores usage. If you have several containers running you cannot limit like that.
 
User avatar
antonsb
MikroTik Support
MikroTik Support
Posts: 387
Joined: Sun Jul 24, 2016 3:12 pm
Location: Riga, Latvia

Re: Launch container with CPU limit

Tue May 30, 2023 4:29 pm

what would be the use case for such limitation?
 
optio
Long time Member
Long time Member
Posts: 672
Joined: Mon Dec 26, 2022 2:57 pm

Re: Launch container with CPU limit

Tue May 30, 2023 4:43 pm

what would be the use case for such limitation?
Does container processes have lower cpu priority from ROS internal processes? If not, you can with containers cores limitation for eg. reserve at least 1 core to be available for ROS processes if containers can have high cpu usage.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10214
Joined: Mon Jun 08, 2015 12:09 pm

Re: Launch container with CPU limit

Tue May 30, 2023 4:49 pm

In Linux it is not like in some other OSes, that a process demanding CPU at the same (default) priority will automatically starve other processes.
In fact, when a process is demanding a lot of CPU, its priority is automatically decreased a little, so that other processes will go first and it gets the remainder of CPU time available.
 
optio
Long time Member
Long time Member
Posts: 672
Joined: Mon Dec 26, 2022 2:57 pm

Re: Launch container with CPU limit

Tue May 30, 2023 5:26 pm

In Linux it is not like in some other OSes, that a process demanding CPU at the same (default) priority will automatically starve other processes.
In fact, when a process is demanding a lot of CPU, its priority is automatically decreased a little, so that other processes will go first and it gets the remainder of CPU time available.
But if both ROS process and container process demands high cpu at same time then are both in same priority, you cannot prioritize ROS processes or reserve core(s) for eg. to prioritize ROS process performance agains containers. Did not test it, but I will try in one container create high cpu usage on all cores and see how will ROS perform on userspace, we will see...
 
optio
Long time Member
Long time Member
Posts: 672
Joined: Mon Dec 26, 2022 2:57 pm

Re: Launch container with CPU limit

Tue May 30, 2023 6:57 pm

It seems that there is some impact on ROS performance. Tested on some mine heavy script with command:
> :put [/system/clock get time]; /system/script/run sms-read; global smsRead; :local smsList [$smsRead]; set smsRead; :put ("--------\r\nSms count: ".[:len $smsList]."\r\n--------"); :put [/system/clock get time]

ROS on idle:
> /system/resource/monitor                                                                                 
          cpu-used: 1%
  cpu-used-per-cpu: 1%,4%,0%,0%
       free-memory: 69580KiB
-- [Q quit|D dump|C-z pause]
Command result:
17:17:21
--------
Sms count: 4
--------
17:17:27

On high cpu usage when in container running:
# stress-ng --cpu 4 --aggressive
ROS on heavy load:
 > /system/resource/monitor                                                                                 
          cpu-used: 100%
  cpu-used-per-cpu: 100%,100%,100%,100%
       free-memory: 69240KiB
-- [Q quit|D dump|C-z pause]
Command result:
17:17:37
--------
Sms count: 4
--------
17:17:44

Each time I run script on heavy load, script returns 1s slower.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10214
Joined: Mon Jun 08, 2015 12:09 pm

Re: Launch container with CPU limit

Tue May 30, 2023 7:59 pm

I'm sure you can always find scenarios and cook up tests that show a problem.
My only remark is that in normal situations it will not be that much of a problem.
 
dzeiwa
just joined
Posts: 1
Joined: Mon Jun 05, 2023 10:16 pm
Location: Iguazu Falls, Brazil

Re: Launch container with CPU limit

Tue Aug 15, 2023 4:51 am

what would be the use case for such limitation?
Dear antonsb, I have seven containers running on a RouterOs v7.11rc on an x86, I got 2 CCR2116 which will also run these containers, four of these containers are used by Zabbix, and it is devouring cpus, it would be very useful to limit the usage cpus, just like you did with memory usage.
For example:
memory-limit: 8GB // this one already exists
cpus-limit: 0.7 // that would be 70% for containers and the remaining 30% is for RouterOs
....
Resources usually:
cpu-used: 3%
cpu-used-per-cpu: 4%,2%,0%,7%
free-memory: 14033348KiB
Resourses when refreshing Zabbix:
cpu-used: 100%
cpu-used-per-cpu: 100%,100%,100%,100%
free-memory: 13635712KiB
This is harming the operation of RouterOs.

Please consider this request and include cpus limit, it would bring RouterOs containers to a higher level.
SUP ticket number: SUP-125273

Thank you very much.
Last edited by dzeiwa on Sat Aug 19, 2023 7:05 pm, edited 1 time in total.
 
User avatar
dzievamarcos
just joined
Posts: 4
Joined: Tue Jan 30, 2024 10:22 pm
Location: Iguazu Falls, Brazil

Re: Launch container with CPU limit

Wed Jan 31, 2024 12:37 am

what would be the use case for such limitation?
Dear antonsb, I have seven containers running on a RouterOs v7.11rc on an x86, I got 2 CCR2116 which will also run these containers, four of these containers are used by Zabbix, and it is devouring cpus, it would be very useful to limit the usage cpus, just like you did with memory usage.
For example:
memory-limit: 8GB // this one already exists
cpus-limit: 0.7 // that would be 70% for containers and the remaining 30% is for RouterOs
....
Resources usually:
cpu-used: 3%
cpu-used-per-cpu: 4%,2%,0%,7%
free-memory: 14033348KiB
Resourses when refreshing Zabbix:
cpu-used: 100%
cpu-used-per-cpu: 100%,100%,100%,100%
free-memory: 13635712KiB
This is harming the operation of RouterOs.

Please consider this request and include cpus limit, it would bring RouterOs containers to a higher level.
SUP ticket number: SUP-125273

Thank you very much.

I have been using containers since version 7.4, it is scary to see the processing at 100%, but I have noticed that this does not affect the router's performance.
But this feature would be very welcome, and there would be no reason to worry about the cpu anymore.
Last edited by dzievamarcos on Wed Jan 31, 2024 12:38 am, edited 1 time in total.
 
nalafod
Trainer
Trainer
Posts: 6
Joined: Thu Sep 20, 2018 2:44 pm
Contact:

Re: Launch container with CPU limit

Sun Mar 03, 2024 10:39 pm

I think it is really important as Routeros users will start using more and more docker containers to be able to set limits such as CPU but also important memory limits

https://docs.docker.com/config/containe ... nstraints/

Is there plans from MikroTik to expose such options in the docker containers. I totally agree this will protect us from overcapacity in CPU and memory.
 
User avatar
antonsb
MikroTik Support
MikroTik Support
Posts: 387
Joined: Sun Jul 24, 2016 3:12 pm
Location: Riga, Latvia

Re: Launch container with CPU limit

Mon Mar 04, 2024 12:46 pm

we are looking into adding swap and other features, but keep in mind that this is not docker running on RouterOS, not all options can be added that easily.

Who is online

Users browsing this forum: No registered users and 1 guest