SlideShare a Scribd company logo
1 of 5
Using cgroups in docker
container
Introduction
The reason for this exercise is that I want to try out processes isolation functionality in Linux using
‘cgroups’ functionality.
During this learning phase, the intention (as it is always) is to try out cgroups before actually putting
them into production ready mode.This involves installing/uninstalling different cgroup packages,
creating/deleting sample cgroups and testing them.
I had a Ubuntu 14.04 VM installed on my Windows 10 guest OS.
So, there are two options:
1. Use Ubuntu VM to experimentabout cgroups – Easiest choice but I did not chose it due to
following reasons:
a. It might have left some packages or cgroups installed after the experimentis over
which may not be used later on.
b. Effort had be put in to revert my VM to its pre-experimentstate that involved
removing cgroups ,configurations and uninstalling packages etc.
2. Install Dockeron Ubuntu VM and use a Ubuntu Container for experimentwith cgroups – This
choice seemedreasonable because it did not have constraints listed above. So, the rest of
this article explains the steps required to install and play around with cgroups using docker
containers.
Pre-requisites:
Docker
Setupdetails:
Guest OS: Windows 10 Home
VM Player: VM Workstation 12 Player
OS: Ubuntu 14.04
DockerVersion: 1.6.2,build 7c8fca2
2
DockerImage: Mycustom image that was created from ‘ubuntu’image present in docker hub. It
contained several other standard software development packages on top, but standard image
should be fine as well.
Steps:
 Install docker
 Launch a docker container with Ubuntu image
Note: Please do not forget to use options ‘--cap-add=SYS_ADMIN’ and‘--security-opt=
apparmor:unconfined’ while launching the container. Otherwise, you will not be able to
mount cgroups using this version of docker.
Inside the launched container, following steps are performed:
 Install cgroups
This should create following files:
Note: Install ‘htop’ utility as well. It presents a nice colorful cli based visualization over ‘top’
command. This will help to demonstrate the cgroups use as well.
Please note that the directory /sys/fs/cgroup will be empty as cgroup sub-components do not
automatically get mounted in this case.
To mount them, following commands are required. These commands mount cpuset and cpu
sub-components only. Likewise, other cgroup sub-components can also be mounted:
sudo apt-get install cgroup-bin cgroup-lite libcgroup1
sudo docker run -d --cap-add=SYS_ADMIN--security-opt=apparmor:unconfined-it
vne_dev_image1bash
/sys/fs/cgroup
/etc/init/cgroup-lite.conf
/proc/cgroups
sudo apt-get install htop
3
After this, following files should be seen:
Now, cgroup sub-components ‘cpu’ and ‘cpu-set’ are ready. ‘cpu’ is usedto define the relative
priorities to different cgroups. ‘cpu-set’is used to assign cpus to a particular cgroups.
Since,my VM was using only 1 processor with 1 core, ‘cpu’ subcomponent does not offer any benefit
to me.So, I used ‘cpu-set’component for rest of this article:
mount -t tmpfs cgroup_root /sys/fs/cgroup
mkdir /sys/fs/cgroup/cpuset
mount -t cgroup cpuset -o cpuset/sys/fs/cgroup/cpuset/
mkdir /sys/fs/cgroup/cpu
mount -t cgroup cpu -o cpu/sys/fs/cgroup/cpu/
ls /sys/fs/cgroup/cpuset/
cgroup.clone_children cpuset.effective_mems cpuset.memory_spread_page
notify_on_release
cgroup.procs cpuset.mem_exclusive cpuset.memory_spread_slab release_agent
cgroup.sane_behavior cpuset.mem_hardwall cpuset.mems tasks
cpuset.cpu_exclusive cpuset.memory_migrate cpuset.sched_load_balance
cpuset.cpus cpuset.memory_pressure cpuset.sched_relax_domain_level
cpuset.effective_cpus cpuset.memory_pressure_enabled docker/
cat /sys/fs/cgroup/cpu/
cgroup.clone_children cgroup.sane_behavior cpu.cfs_quota_us cpu.stat low/
release_agent
cgroup.procs cpu.cfs_period_us cpu.shares docker/ notify_on_release tasks
cpuset.cpus cpuset.memory_pressure cpuset.sched_relax_domain_level
cpuset.effective_cpus cpuset.memory_pressure_enabled docker/
4
Following picture summarizes the experiment:
I am going to create two cgroups ‘low’ and ‘high’;Assign different CPU weights to them; then start
different processes (they will start using all processing power) in these cgroups to demonstrate the
effectof process isolation.
cgcreate -a root -t vnej cpu:low
cgcreate -a root -t vnej cpu:high
cat /sys/fs/cgroup/cpu/low/
cgroup.clone_children cpu.cfs_period_us cpu.shares notify_on_release
cgroup.procs cpu.cfs_quota_us cpu.stat tasks
cat /sys/fs/cgroup/cpu/high/
cgroup.clone_children cpu.cfs_period_us cpu.shares notify_on_release
cgroup.procs cpu.cfs_quota_us cpu.stat tasks
5
Assign three-fourth(3/4th
) of CPU to cgroup ‘low’
Assign rest one-fourth (1/4th
) of CPU to cgroup ‘high’
start a process with cgroup ‘low’:
Observe CPU usage using htop command
Start another process with cgroup ‘high’
Observe CPU distribution using htop command
Start another process with cgroup ‘low’:
start a process with cgroup ‘high’:
References:
https://www.devinhoward.ca/technology/2015/feb/implementing-cgroups-ubuntu-or-debian
http://stackoverflow.com/questions/27454848/cgroups-sys-fs-cgroup-is-empty-on-ubuntu
http://libcg.sourceforge.net/
https://wiki.archlinux.org/index.php/cgroups
cat /sys/fs/cgroup/cpu/low/cpu.shares
1024
echo768 > /sys/fs/cgroup/cpu/low/cpu.shares
echo256 > /sys/fs/cgroup/cpu/high/cpu.shares
cgexec -gcpu:low md5sum /dev/urandom &
cgexec -gcpu:highmd5sum /dev/urandom &
cgexec -gcpu:low md5sum /dev/urandom &
cgexec -gcpu:highmd5sum /dev/urandom &

More Related Content

What's hot

Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Brendan Gregg
 
Linux kernel tracing
Linux kernel tracingLinux kernel tracing
Linux kernel tracingViller Hsiao
 
Linux Directory Structure
Linux Directory StructureLinux Directory Structure
Linux Directory StructureKevin OBrien
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux KernelAdrian Huang
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBrendan Gregg
 
Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands Ahmed El-Arabawy
 
Introduction 2 linux
Introduction 2 linuxIntroduction 2 linux
Introduction 2 linuxPapu Kumar
 
Kernel Recipes 2017: Using Linux perf at Netflix
Kernel Recipes 2017: Using Linux perf at NetflixKernel Recipes 2017: Using Linux perf at Netflix
Kernel Recipes 2017: Using Linux perf at NetflixBrendan Gregg
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and moreBrendan Gregg
 
Deploy Prometheus - Grafana and EFK stack on Kubic k8s Clusters
Deploy Prometheus - Grafana and EFK stack on Kubic k8s ClustersDeploy Prometheus - Grafana and EFK stack on Kubic k8s Clusters
Deploy Prometheus - Grafana and EFK stack on Kubic k8s ClustersSyah Dwi Prihatmoko
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Red Hat OpenStack 17 저자직강+스터디그룹_2주차
Red Hat OpenStack 17 저자직강+스터디그룹_2주차Red Hat OpenStack 17 저자직강+스터디그룹_2주차
Red Hat OpenStack 17 저자직강+스터디그룹_2주차Nalee Jang
 
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Jérôme Petazzoni
 
Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Ahmed El-Arabawy
 
The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsDivye Kapoor
 
Application Monitoring using Open Source: VictoriaMetrics - ClickHouse
Application Monitoring using Open Source: VictoriaMetrics - ClickHouseApplication Monitoring using Open Source: VictoriaMetrics - ClickHouse
Application Monitoring using Open Source: VictoriaMetrics - ClickHouseVictoriaMetrics
 
Einführung in Domain Name System DNS und Bind
Einführung in Domain Name System DNS und BindEinführung in Domain Name System DNS und Bind
Einführung in Domain Name System DNS und Bindtdeutsch
 
Slug 2009 06 SELinux For Sysadmins
Slug 2009 06 SELinux For SysadminsSlug 2009 06 SELinux For Sysadmins
Slug 2009 06 SELinux For SysadminsPaulWay
 

What's hot (20)

Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)
 
Linux kernel tracing
Linux kernel tracingLinux kernel tracing
Linux kernel tracing
 
Linux Directory Structure
Linux Directory StructureLinux Directory Structure
Linux Directory Structure
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame Graphs
 
Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands
 
Introduction 2 linux
Introduction 2 linuxIntroduction 2 linux
Introduction 2 linux
 
Kernel Recipes 2017: Using Linux perf at Netflix
Kernel Recipes 2017: Using Linux perf at NetflixKernel Recipes 2017: Using Linux perf at Netflix
Kernel Recipes 2017: Using Linux perf at Netflix
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
 
Deploy Prometheus - Grafana and EFK stack on Kubic k8s Clusters
Deploy Prometheus - Grafana and EFK stack on Kubic k8s ClustersDeploy Prometheus - Grafana and EFK stack on Kubic k8s Clusters
Deploy Prometheus - Grafana and EFK stack on Kubic k8s Clusters
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Red Hat OpenStack 17 저자직강+스터디그룹_2주차
Red Hat OpenStack 17 저자직강+스터디그룹_2주차Red Hat OpenStack 17 저자직강+스터디그룹_2주차
Red Hat OpenStack 17 저자직강+스터디그룹_2주차
 
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
 
Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems
 
The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOs
 
Application Monitoring using Open Source: VictoriaMetrics - ClickHouse
Application Monitoring using Open Source: VictoriaMetrics - ClickHouseApplication Monitoring using Open Source: VictoriaMetrics - ClickHouse
Application Monitoring using Open Source: VictoriaMetrics - ClickHouse
 
Einführung in Domain Name System DNS und Bind
Einführung in Domain Name System DNS und BindEinführung in Domain Name System DNS und Bind
Einführung in Domain Name System DNS und Bind
 
Linux networking
Linux networkingLinux networking
Linux networking
 
Deep Dive into the AOSP
Deep Dive into the AOSPDeep Dive into the AOSP
Deep Dive into the AOSP
 
Slug 2009 06 SELinux For Sysadmins
Slug 2009 06 SELinux For SysadminsSlug 2009 06 SELinux For Sysadmins
Slug 2009 06 SELinux For Sysadmins
 

Viewers also liked

Recent advances in the Linux kernel resource management
Recent advances in the Linux kernel resource managementRecent advances in the Linux kernel resource management
Recent advances in the Linux kernel resource managementOpenVZ
 
What's missing from upstream kernel containers? - Kir Kolyshkin, Sergey Bronn...
What's missing from upstream kernel containers? - Kir Kolyshkin, Sergey Bronn...What's missing from upstream kernel containers? - Kir Kolyshkin, Sergey Bronn...
What's missing from upstream kernel containers? - Kir Kolyshkin, Sergey Bronn...OpenVZ
 
Understand and optimize Linux I/O
Understand and optimize Linux I/OUnderstand and optimize Linux I/O
Understand and optimize Linux I/OAndrea Righi
 
Linux cgroups and namespaces
Linux cgroups and namespacesLinux cgroups and namespaces
Linux cgroups and namespacesLocaweb
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsBrendan Gregg
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016Brendan Gregg
 
Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Brendan Gregg
 
Velocity 2015 linux perf tools
Velocity 2015 linux perf toolsVelocity 2015 linux perf tools
Velocity 2015 linux perf toolsBrendan Gregg
 
Overview of recapitalization plan
Overview of recapitalization planOverview of recapitalization plan
Overview of recapitalization planCNOServices
 
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxConAnatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxConJérôme Petazzoni
 
Spectralis oct normal anatomy & systematic interpretation.
Spectralis oct normal anatomy & systematic interpretation.Spectralis oct normal anatomy & systematic interpretation.
Spectralis oct normal anatomy & systematic interpretation.oxfordshireloc
 

Viewers also liked (12)

Recent advances in the Linux kernel resource management
Recent advances in the Linux kernel resource managementRecent advances in the Linux kernel resource management
Recent advances in the Linux kernel resource management
 
What's missing from upstream kernel containers? - Kir Kolyshkin, Sergey Bronn...
What's missing from upstream kernel containers? - Kir Kolyshkin, Sergey Bronn...What's missing from upstream kernel containers? - Kir Kolyshkin, Sergey Bronn...
What's missing from upstream kernel containers? - Kir Kolyshkin, Sergey Bronn...
 
First steps on CentOs7
First steps on CentOs7First steps on CentOs7
First steps on CentOs7
 
Understand and optimize Linux I/O
Understand and optimize Linux I/OUnderstand and optimize Linux I/O
Understand and optimize Linux I/O
 
Linux cgroups and namespaces
Linux cgroups and namespacesLinux cgroups and namespaces
Linux cgroups and namespaces
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old Secrets
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016
 
Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016
 
Velocity 2015 linux perf tools
Velocity 2015 linux perf toolsVelocity 2015 linux perf tools
Velocity 2015 linux perf tools
 
Overview of recapitalization plan
Overview of recapitalization planOverview of recapitalization plan
Overview of recapitalization plan
 
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxConAnatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
 
Spectralis oct normal anatomy & systematic interpretation.
Spectralis oct normal anatomy & systematic interpretation.Spectralis oct normal anatomy & systematic interpretation.
Spectralis oct normal anatomy & systematic interpretation.
 

Similar to Using cgroups in docker containers

Advanced Namespaces and cgroups
Advanced Namespaces and cgroupsAdvanced Namespaces and cgroups
Advanced Namespaces and cgroupsKernel TLV
 
Installing NS2.29 on Ubuntu 10.10
Installing NS2.29 on Ubuntu 10.10Installing NS2.29 on Ubuntu 10.10
Installing NS2.29 on Ubuntu 10.10Tejdeep Gudivada
 
Immutable infrastructure with Docker and containers (GlueCon 2015)
Immutable infrastructure with Docker and containers (GlueCon 2015)Immutable infrastructure with Docker and containers (GlueCon 2015)
Immutable infrastructure with Docker and containers (GlueCon 2015)Jérôme Petazzoni
 
Getting Started with Buildroot - Lab
Getting Started with Buildroot - LabGetting Started with Buildroot - Lab
Getting Started with Buildroot - LabTrevor Woerner
 
How to Install ArchLinux to a USB Flashdrive in 2012
How to Install ArchLinux to a USB Flashdrive in 2012How to Install ArchLinux to a USB Flashdrive in 2012
How to Install ArchLinux to a USB Flashdrive in 2012Chukwuma Onyeije, MD, FACOG
 
How I hack on puppet modules
How I hack on puppet modulesHow I hack on puppet modules
How I hack on puppet modulesKris Buytaert
 
Node.js basics
Node.js basicsNode.js basics
Node.js basicsBen Lin
 
♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instance♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instanceAlireza Kamrani
 
Check the version with fixes. Link in description
Check the version with fixes. Link in descriptionCheck the version with fixes. Link in description
Check the version with fixes. Link in descriptionPrzemyslaw Koltermann
 
101 2.2 install boot manager
101 2.2 install boot manager101 2.2 install boot manager
101 2.2 install boot managerAcácio Oliveira
 
CentOS 6 to CentOS 7 Upgrade Procedure
CentOS 6 to CentOS 7 Upgrade ProcedureCentOS 6 to CentOS 7 Upgrade Procedure
CentOS 6 to CentOS 7 Upgrade ProcedureVEXXHOST Private Cloud
 

Similar to Using cgroups in docker containers (20)

Advanced Namespaces and cgroups
Advanced Namespaces and cgroupsAdvanced Namespaces and cgroups
Advanced Namespaces and cgroups
 
Installing NS2.29 on Ubuntu 10.10
Installing NS2.29 on Ubuntu 10.10Installing NS2.29 on Ubuntu 10.10
Installing NS2.29 on Ubuntu 10.10
 
Zenoss: Buildout
Zenoss: BuildoutZenoss: Buildout
Zenoss: Buildout
 
Kdump
KdumpKdump
Kdump
 
Immutable infrastructure with Docker and containers (GlueCon 2015)
Immutable infrastructure with Docker and containers (GlueCon 2015)Immutable infrastructure with Docker and containers (GlueCon 2015)
Immutable infrastructure with Docker and containers (GlueCon 2015)
 
kubernetes practice
kubernetes practicekubernetes practice
kubernetes practice
 
Getting Started with Buildroot - Lab
Getting Started with Buildroot - LabGetting Started with Buildroot - Lab
Getting Started with Buildroot - Lab
 
Dev ops
Dev opsDev ops
Dev ops
 
Cgroups in android
Cgroups in androidCgroups in android
Cgroups in android
 
How to Install ArchLinux to a USB Flashdrive in 2012
How to Install ArchLinux to a USB Flashdrive in 2012How to Install ArchLinux to a USB Flashdrive in 2012
How to Install ArchLinux to a USB Flashdrive in 2012
 
How I hack on puppet modules
How I hack on puppet modulesHow I hack on puppet modules
How I hack on puppet modules
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
 
2.2 install boot manager
2.2 install boot manager2.2 install boot manager
2.2 install boot manager
 
RPM (LINUX)
RPM (LINUX)RPM (LINUX)
RPM (LINUX)
 
♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instance♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instance
 
Check the version with fixes. Link in description
Check the version with fixes. Link in descriptionCheck the version with fixes. Link in description
Check the version with fixes. Link in description
 
Sun raysetup
Sun raysetupSun raysetup
Sun raysetup
 
101 2.2 install boot manager
101 2.2 install boot manager101 2.2 install boot manager
101 2.2 install boot manager
 
CentOS 6 to CentOS 7 Upgrade Procedure
CentOS 6 to CentOS 7 Upgrade ProcedureCentOS 6 to CentOS 7 Upgrade Procedure
CentOS 6 to CentOS 7 Upgrade Procedure
 
Docker perl build
Docker perl buildDocker perl build
Docker perl build
 

Recently uploaded

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

Using cgroups in docker containers

  • 1. Using cgroups in docker container Introduction The reason for this exercise is that I want to try out processes isolation functionality in Linux using ‘cgroups’ functionality. During this learning phase, the intention (as it is always) is to try out cgroups before actually putting them into production ready mode.This involves installing/uninstalling different cgroup packages, creating/deleting sample cgroups and testing them. I had a Ubuntu 14.04 VM installed on my Windows 10 guest OS. So, there are two options: 1. Use Ubuntu VM to experimentabout cgroups – Easiest choice but I did not chose it due to following reasons: a. It might have left some packages or cgroups installed after the experimentis over which may not be used later on. b. Effort had be put in to revert my VM to its pre-experimentstate that involved removing cgroups ,configurations and uninstalling packages etc. 2. Install Dockeron Ubuntu VM and use a Ubuntu Container for experimentwith cgroups – This choice seemedreasonable because it did not have constraints listed above. So, the rest of this article explains the steps required to install and play around with cgroups using docker containers. Pre-requisites: Docker Setupdetails: Guest OS: Windows 10 Home VM Player: VM Workstation 12 Player OS: Ubuntu 14.04 DockerVersion: 1.6.2,build 7c8fca2
  • 2. 2 DockerImage: Mycustom image that was created from ‘ubuntu’image present in docker hub. It contained several other standard software development packages on top, but standard image should be fine as well. Steps:  Install docker  Launch a docker container with Ubuntu image Note: Please do not forget to use options ‘--cap-add=SYS_ADMIN’ and‘--security-opt= apparmor:unconfined’ while launching the container. Otherwise, you will not be able to mount cgroups using this version of docker. Inside the launched container, following steps are performed:  Install cgroups This should create following files: Note: Install ‘htop’ utility as well. It presents a nice colorful cli based visualization over ‘top’ command. This will help to demonstrate the cgroups use as well. Please note that the directory /sys/fs/cgroup will be empty as cgroup sub-components do not automatically get mounted in this case. To mount them, following commands are required. These commands mount cpuset and cpu sub-components only. Likewise, other cgroup sub-components can also be mounted: sudo apt-get install cgroup-bin cgroup-lite libcgroup1 sudo docker run -d --cap-add=SYS_ADMIN--security-opt=apparmor:unconfined-it vne_dev_image1bash /sys/fs/cgroup /etc/init/cgroup-lite.conf /proc/cgroups sudo apt-get install htop
  • 3. 3 After this, following files should be seen: Now, cgroup sub-components ‘cpu’ and ‘cpu-set’ are ready. ‘cpu’ is usedto define the relative priorities to different cgroups. ‘cpu-set’is used to assign cpus to a particular cgroups. Since,my VM was using only 1 processor with 1 core, ‘cpu’ subcomponent does not offer any benefit to me.So, I used ‘cpu-set’component for rest of this article: mount -t tmpfs cgroup_root /sys/fs/cgroup mkdir /sys/fs/cgroup/cpuset mount -t cgroup cpuset -o cpuset/sys/fs/cgroup/cpuset/ mkdir /sys/fs/cgroup/cpu mount -t cgroup cpu -o cpu/sys/fs/cgroup/cpu/ ls /sys/fs/cgroup/cpuset/ cgroup.clone_children cpuset.effective_mems cpuset.memory_spread_page notify_on_release cgroup.procs cpuset.mem_exclusive cpuset.memory_spread_slab release_agent cgroup.sane_behavior cpuset.mem_hardwall cpuset.mems tasks cpuset.cpu_exclusive cpuset.memory_migrate cpuset.sched_load_balance cpuset.cpus cpuset.memory_pressure cpuset.sched_relax_domain_level cpuset.effective_cpus cpuset.memory_pressure_enabled docker/ cat /sys/fs/cgroup/cpu/ cgroup.clone_children cgroup.sane_behavior cpu.cfs_quota_us cpu.stat low/ release_agent cgroup.procs cpu.cfs_period_us cpu.shares docker/ notify_on_release tasks cpuset.cpus cpuset.memory_pressure cpuset.sched_relax_domain_level cpuset.effective_cpus cpuset.memory_pressure_enabled docker/
  • 4. 4 Following picture summarizes the experiment: I am going to create two cgroups ‘low’ and ‘high’;Assign different CPU weights to them; then start different processes (they will start using all processing power) in these cgroups to demonstrate the effectof process isolation. cgcreate -a root -t vnej cpu:low cgcreate -a root -t vnej cpu:high cat /sys/fs/cgroup/cpu/low/ cgroup.clone_children cpu.cfs_period_us cpu.shares notify_on_release cgroup.procs cpu.cfs_quota_us cpu.stat tasks cat /sys/fs/cgroup/cpu/high/ cgroup.clone_children cpu.cfs_period_us cpu.shares notify_on_release cgroup.procs cpu.cfs_quota_us cpu.stat tasks
  • 5. 5 Assign three-fourth(3/4th ) of CPU to cgroup ‘low’ Assign rest one-fourth (1/4th ) of CPU to cgroup ‘high’ start a process with cgroup ‘low’: Observe CPU usage using htop command Start another process with cgroup ‘high’ Observe CPU distribution using htop command Start another process with cgroup ‘low’: start a process with cgroup ‘high’: References: https://www.devinhoward.ca/technology/2015/feb/implementing-cgroups-ubuntu-or-debian http://stackoverflow.com/questions/27454848/cgroups-sys-fs-cgroup-is-empty-on-ubuntu http://libcg.sourceforge.net/ https://wiki.archlinux.org/index.php/cgroups cat /sys/fs/cgroup/cpu/low/cpu.shares 1024 echo768 > /sys/fs/cgroup/cpu/low/cpu.shares echo256 > /sys/fs/cgroup/cpu/high/cpu.shares cgexec -gcpu:low md5sum /dev/urandom & cgexec -gcpu:highmd5sum /dev/urandom & cgexec -gcpu:low md5sum /dev/urandom & cgexec -gcpu:highmd5sum /dev/urandom &