docker online meetup #27: raspberry pi dockercon challenge

31
Docker RPi2 challenge @damienduportal @ndeloof @YoannDubreuil @Quintus23M

Upload: docker-inc

Post on 09-Jan-2017

1.441 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

Docker RPi2 challenge@damienduportal @ndeloof @YoannDubreuil @Quintus23M

Page 2: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

Challenge Introduction

DockerCon 15, June 22-23

Live Demo: starting 100x Docker Containers on a Raspberry Pi 2 B

showed a screen shot with 250x running Containers

and plenty of resources/memory left, let’s improve it

Page 3: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge
Page 4: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

OK, let’s start the Challenge

Challenge: How many Containers could be really started on a Pi 2?

my wish: I’d like to see 1000x Containers

personal record to this time: 613x Containers

--- but honestly, I was not sure, if this is possible at all!

Page 5: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

let’s break the challenge

Page 6: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

First tries to the recordTry, Learn and Share !

Page 7: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

1 - Measure and automate all the things

Measures :

sysstat for post mortem

node-collector from Prometheus.io for “real time”

Provisionning :

Basic shell script published on my Github

Let’s try Ansible later : easier to maintain, need to learn :)

Page 8: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge
Page 9: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

2 - Lower the container footprint

Tried with custom compiled nginx for ARM with few extensions ➢ ~ 80 containers

Footprint too big per container. Reading carefully Hypriot Blog : "rpi-nano-httpd" : 16 Kb footprint, 88 Kb image

➢ ~150 containers

Page 10: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

3 - Docker tuning

Wanted to disable tcp-proxy process : no use here

Docker logs says “iptables” errors

Footprint with iptable + net. namespace : around 1 Mb !

Disable network / port forwarding + --net=host (Client side)

--bridge=none --iptables=false --ipv6=false --ip-forward=false --ip-masq=false -tls=false --userland-proxy=false (Engine side)

Page 11: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

4 - Moaaar Docker tuning

No debug : --debug=true

No filesystem writing : --read-only=true

No logging : --log-driver=none

Following Docker upgrades :

--ipc=host

--utc=hostReached ~ 950 containers

Page 12: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

5 - Linux tuning : start sharing

Tune sysctl : limits ! (MaxOpenFiles, MaxProcs, etc.)

Still stuck, footprint / container still big (~ 750 Kb)

Help from @booya and Hypriot guys + eading the /etc/init.d/docker script : Stack size (8 Mb -> 2 Mb in Hypriot:Jack)

Playing around doing abacus : <32 Kb breaks docker pull, <16Kb breaks docker run

~ 1700 containers

Page 13: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

6 - To the record : Learning and sharing

GOGC to 10

~ 2 200 containers

Docker Hack days + Twitter :KSM : KO (need to recompile Kernel)

Learning the Linux memory management : Freeing caches + disabling OOM

~ 2498 containers !!!

Page 14: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

Share and challenge !Community, discussions, challenge and Whales

Page 15: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

BreizhCamp Hack (night) Party

Page 16: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

Brainstorm for ideas

… then test everything in arbitrary order

help each other

drink some beer

learn a lot

Our Methodology

Page 17: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

where to start?

first naïve tryonly 38 containers :-\ !

but 70 on a RPi1

figure out RPi2 limits without Dockerweb server footprint

network namespace footprint

get some help !let’s collaborate with @DamienDuportal (aka “French mafia”)

Page 18: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

web server

from hypriot/rpi-nano-httpd image

written in ARM assembly code

already highly optimized1 page for code

1 page for data

1 page for stack

1 page for vsdo

=> 16kb memory footprint per process !

launched 27.000 on a RPi2

Page 19: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

network namespace RPi2 limit

launched web server in a dedicated network namespace

ip netns exec <NS_NUMBER> httpd

RPi2 limit is ~ 1.100 network namespace

=> To break the challenge, we needed to run without network isolation

Page 20: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

network configuration

disabled everything we could on Docker daemon

--bridge=none --userland-proxy=false --sig-proxy=false --ipv6=false --ip-masq=false --iptables=false

started containers with --net=host

disabled IPv6 on Linux kernel boot with ipv6.disable=1

Page 21: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

Systemd

Docker daemon run as root

… but still has some limits set by systemd (so the 38 containers...)

LimitSIGPENDING=infinityLimitNOFILE=infinityLimitAS=infinityLimitNPROC=infinityLimitSTACK=?

Page 22: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

stack size

Damien pro-tip : adjust LimitSTACK parameter to your needs

Default stack size is 8Mba stack consume 8Mb of process VM space (8 * 4 * 38 = 1,2 Gb)

=> ~ 1800 / 2000 containers

Page 23: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

process memory layout

RPi2 processor is 32 bits !32 bit process address space

only 3Gb of virtual memory per process

collision between stack and heap memory areas

reduce thread stack sizesmallest working thread stack size: 24kb

reduce Golang memory consumptionlaunched docker with GODEBUG=gctrace=1 GOGC=1

Page 24: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

speed up tests

launching thousands of containers on a RPi2 takes hours if not days!

everything in memory with zram devicesswap (ratio 5:1)

/var/lib/docker on ext4 FS (ratio 10:1)

swap as early as possible to keep free memory (vm.swappiness = 100)

USB external disk vs low perf, I/O limited SD card

more CPU for GO with GOMAXPROCS=4

reduce kernel perf event slowdown kernel.perf_cpu_time_max_percent = 1

Page 25: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

system tuning

limit memory consumptionreduce GPU memory to 16Mb (can’t do less)

blacklisted non required Linux modules

remove some Linux limitsvm.overcommit = 1

kernel.pid_max = 32768

kernel.threads-max = 14812

Page 26: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

Challenge completed!

We started 2499 containers !

RAM on RPi2 was not exhausted but Docker daemon crashed

docker[307]: runtime: program exceeds 10000-thread limit

Page 27: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

Why is there a limit?

4 threads per container

10.000 threads for a Go application => 2500 containers max

Unlocked this with runtime.debug.SetMaxThread(12000)

hack not eligible for RpiDocker challenge, was just to confirm

can run ~2740 webserver containers, before actual OOM

Page 28: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

what did not work

Btrfs

not working properly : strange web server 404 failures after ~20 successful launchs

stick with overlayfs

LXC driver

way sloooooooower

4 threads per container anyway

Go 1.5

compiled Docker with Go 1.5 for “better GC”, had no significant impact

Page 29: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

What’s next

Understand why Docker do need 4 threads per container

(hey, lot’s of Docker core contributors here, time to ask !)

Page 30: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

Collaboration (and beer) were the keys

to break this challenge !

Page 31: Docker Online Meetup #27: Raspberry Pi DockerCon Challenge

links

Nicolas’ blog

http://blog.loof.fr/2015/10/how-to-run-2500-webservers-on-raspberry.html

code

https://github.com/ndeloof/RPiDockerKillerScore