Docker memory usage Test

Source: Internet
Author: User
Docker memory usage Test
Objective: To reasonably set memory, swap partition, and memory reservation

Test procedure:
Copy and paste the JDK environment directly.
Cat> outofmemeber. Java <EOF
Package com. ptmind. datadeck;
Import java. Text. decimalformat;
Import java. util. arraylist;
Import java. util. List;
Public class outofmemeber {
Public static void main (string [] ARGs ){
List <Object> List = new arraylist <> ();
Decimalformat df = new decimalformat ("###### 0.00 ");
While (true ){

                 byte b[] = new byte[1024*1024*100];                 list.add(b);                 double total = (Runtime.getRuntime().totalMemory()) / (1024.0 * 1024);                 System.out.println("total:"+total+"M");                 double max = (Runtime.getRuntime().maxMemory()) / (1024.0 * 1024);                 System.out.println("max:"+max+"M");                 double free = (Runtime.getRuntime().freeMemory()) / (1024.0 * 1024);                 System.out.println("free:"+df.format(free)+"M");                 double mayuse=(max - total + free);                 System.out.println("mayuse:"+df.format(mayuse)+"M");                 System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");             }         }

}
EOF
Javac outofmemeber. Java-xlint: unchecked
Java-xmx20g outofmemeber # The memory setting must be greater than the memory limit to apply for all the memory, otherwise the JVM will reserve the memory and cannot occupy all

Test:
1,
The command is as follows:
-M 4G: Memory limit of 4G
-- Memory-swap =-1: The value of swap is-1.
-- Memory-reservation = 4G: Reserved memory is 4G

Docker run -- Rm-M 4G -- memory-swap =-1 -- memory-reservation = 4G-It Java: testmem sh
Memory:
"Memory": 4294967296,
"Cpusetmems ":"",
"Kernelmemory": 0,
"Memoryreservation": 4294967296,
"Memoryswap":-1,
"Memoryswappiness":-1,
Running result:
Total: 4037.0 m
MAX: 5461.5 m
Free: 35.76 m
Mayuse: 1460.26 m

Conclusion: The maximum memory usage is 4 GB.

2,
Docker run -- Rm-M 4G -- memory-swap = 0 -- memory-reservation = 4G-It Java: testmem sh
Memory:
"Memory": 4294967296,
"Cpusetmems ":"",
"Kernelmemory": 0,
"Memoryreservation": 4294967296,
"Memoryswap": 8589934592,
"Memoryswappiness":-1,
Result:
Total: 8157.5 m
MAX: 18204.5 m
Free: 56.26 m
Mayuse: 10103.26 m

Killed when the maximum usage is 8 GB (killed by the System)

3,
Docker run -- Rm-M 4G -- memory-swap = 4G -- memory-reservation = 4G-It Java: testmem sh
Result:
Total: 4037.0 m
MAX: 18204.5 m
Free: 35.76 m
Mayuse: 14203.26 m

Maximum 4G memory used is killed

4,
Docker run -- Rm-M 4G -- memory-swap = 6g -- memory-reservation = 4G-It Java: testmem sh
Result:
Total: 6147.5 m
MAX: 18204.5 m
Free: 46.26 m
Mayuse: 12103.26 m
A maximum of 6 GB of memory is killed, and the swap occupied by the container is the system's swap.
5,
Docker run -- Rm-M 4G -- memory-swap = 8g -- memory-reservation = 4G-It Java: testmem sh
Result:
Total: 8157.5 m
MAX: 14563.5 m
Free: 56.26 m
Mayuse: 6462.26 m
Maximum 8 GB memory = memory + swap

Rancher Platform

1,
Memory limit 4 GB
4 GB memory Reserved
Swap not filled

Memory:
"Memory": 4294967296,
"Cpusetmems ":"",
"Kernelmemory": 0,
"Memoryreservation": 4294967296,
"Memoryswap": 8589934592,
"Memoryswappiness":-1,
Result:
Total: 4455.0 m
MAX: 14563.5 m
Free: 1650.27 m
Mayuse: 11758.77 m

2,
Memory limit 4 GB
4 GB memory Reserved
Swap 0
Memory:
"Memory": 4294967296,
"Cpusetmems ":"",
"Kernelmemory": 0,
"Memoryreservation": 4294967296,
"Memoryswap": 4296015872,
"Memoryswappiness":-1,
Result:
Total: 4448.5 m
MAX: 14563.5 m
Free: 1643.77 m
Mayuse: 11758.77 m

3,
Memory limit 4 GB
4 GB memory Reserved
Swap 4G
Memory:
"Memory": 4294967296,
"Cpusetmems ":"",
"Kernelmemory": 0,
"Memoryreservation": 4294967296,
"Memoryswap": 8589934592,
"Memoryswappiness":-1,
Result:
Total: 4441.5 m
MAX: 14563.5 m
Free: 1636.77 m
Mayuse: 11758.77 m

Docker memory usage Test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.