Tuesday, 30 October 2018

Memory and CPU Usage for All Your Docker Containers on Ubuntu


Running docker stats command will return statistics of your running container. Stats like CPU, memory network and block i/o operations.

How to look stats of specific container?

For example: 

docker stats  ${container Id or container name}.

command: docker stats chat.






above command will continouslly update the stats

How to look stats of all containers?

Command:  docker stats 

above command will display stats of all running containers with continouslly update the stats.



In case if you don't want stats to be updated continously, then add --no-stream

in docker stats command this will display stats only once.


For example:  docker stats -no-stream or docker stats ${container name | id} --no-stream.


Monday, 29 October 2018

Increase ulimit in ubuntu and docker

What is ulimit?

It is a number of open file descriptors per process. They can all refer to the same file, or different files. It prevent single users from using too many system resources.

How can is check ulimit in current shell?

Run ulimit -a command  from terminal. 

Output of the above command:




How to set ulimit in current shell?

ulimit -n {$no of files}

For example ->  If  you want to set no of open files 65535 below is the command you need to run on terminal.    ulimit -n 65535 ; 

How to set ulimit permanent?

For the ulimits to persists across reboots we need to set the ulimit values in the configuration file
  /etc/security/limits.conf.

Format ->
#[domain]   [type]  [item]  [value]


domain  - > a user name or group name
type ->   can have the two values (soft| hard)
item -> the property to set
value -> value of the property.

For example ->                 to add limit of number of files for user root:



to set limit  of number of files valid for all users




How to set ulimit in  Docker?

Due to some security reason. docker currently not extends host ulimit property.

 There are couple of ways to set following are the ways:

  • The latest docker supports setting ulimits through the command line and the API. For instance, docker run takes --ulimit <type>=<soft>:<hard> .
  • set ulimit -n 65535 in the file /etc/init.d/docker



  




Generating Unique Id in Distributed Environment in high Scale:

Recently I was working on a project which requires unique id in a distributed environment which we used as a  primary  key to store in dat...