docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/lec07.pdf · lxc...

24
Computer Science Lecture 6, page Docker Docker uses Linux containers 1

Upload: hoangnhi

Post on 06-May-2018

231 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

Computer Science Lecture 6, page

Docker• Docker uses Linux containers

1

Page 2: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

Computer Science Lecture 6, page

LXC Virtualization Using Docker

• Portable: docker images run anywhere docker runs • Docker decouples LXC provider from operations

– uses virtual resources (LXC virtualization) • fair share of physical NIC vs use virtual NICs that are fair-

shared

2

Page 3: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

Computer Science Lecture 6, page

Docker Images and Use• Docker uses a union file system (AuFS)

– allows containers to use host FS safely • Essentially a copy-on-write file system

– read-only files shared (e.g., share glibc) – make a copy upon write

• Allows for small efficient container images • Docker Use Cases

– “Run once, deploy anywhere” – Images can be pulled/pushed to repository – Containers can be a single process (useful for

microservices) or a full OS

3

Page 4: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

Computer Science Lecture 6, page

Use of Virtualization Today• Data centers:

– server consolidation: pack multiple virtual servers onto a smaller number of physical server

• saves hardware costs, power and cooling costs • Cloud computing: rent virtual servers

– cloud provider controls physical machines and mapping of virtual servers to physical hosts

– User gets root access on virtual server • Desktop computing:

– Multi-platform software development – Testing machines – Run apps from another platform

4

Page 5: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

Computer Science Lecture 6, page

Case Study: PlanetLab

• Distributed cluster across universities – Used for experimental research by students and faculty in

networking and distributed systems • Uses a virtualized architecture

– Linux Vservers – Node manager per machine – Obtain a “slice” for an experiment: slice creation service

5

Page 6: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

Computer Science Lecture 7, page CS677: Distributed OS

Server Design Issues

• Server Design – Iterative versus concurrent

• How to locate an end-point (port #)? – Well known port # – Directory service (port mapper in Unix) – Super server (inetd in Unix)

6

Page 7: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

Computer Science Lecture 7, page CS677: Distributed OS

Stateful or Stateless?

• Stateful server – Maintain state of connected clients – Sessions in web servers

• Stateless server – No state for clients

• Soft state – Maintain state for a limited time; discarding state does not

impact correctness

7

Page 8: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

Computer Science Lecture 7, page CS677: Distributed OS

Server Clusters

• Web applications use tiered architecture – Each tier may be optionally replicated; uses a dispatcher – Use TCP splicing or handoffs

8

Page 9: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

Computer Science Lecture 7, page CS677: Distributed OS

Server Architecture

• Sequential – Serve one request at a time – Can service multiple requests by employing events and

asynchronous communication • Concurrent

– Server spawns a process or thread to service each request – Can also use a pre-spawned pool of threads/processes (apache)

• Thus servers could be – Pure-sequential, event-based, thread-based, process-based

• Discussion: which architecture is most efficient?

9

Page 10: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

Computer Science Lecture 7, page CS677: Distributed OS

Scalability

• Question:How can you scale the server capacity? • Buy bigger machine! • Replicate • Distribute data and/or algorithms • Ship code instead of data • Cache

10

Page 11: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Code and Process Migration

• Motivation • How does migration occur? • Resource migration • Agent-based system • Details of process migration

11

Page 12: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Motivation

• Key reasons: performance and flexibility • Process migration (aka strong mobility)

– Improved system-wide performance – better utilization of system-wide resources

– Examples: Condor, DQS • Code migration (aka weak mobility)

– Shipment of server code to client – filling forms (reduce communication, no need to pre-link stubs with client)

– Ship parts of client application to server instead of data from server to client (e.g., databases)

– Improve parallelism – agent-based web searches

12

Page 13: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Motivation

• Flexibility – Dynamic configuration of distributed system – Clients don’t need preinstalled software – download on

demand

13

Page 14: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Migration models

• Process = code seg + resource seg + execution seg • Weak versus strong mobility

– Weak => transferred program starts from initial state • Sender-initiated versus receiver-initiated • Sender-initiated

– migration initiated by machine where code resides • Client sending a query to database server

– Client should be pre-registered

• Receiver-initiated – Migration initiated by machine that receives code – Java applets – Receiver can be anonymous

14

Page 15: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Who executes migrated entity?

• Code migration: – Execute in a separate process – [Applets] Execute in target process

• Process migration – Remote cloning – Migrate the process

15

Page 16: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Models for Code Migration

• Alternatives for code migration.

16

Page 17: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Do Resources Migrate?

• Depends on resource to process binding – By identifier: specific web site, ftp server – By value: Java libraries – By type: printers, local devices

• Depends on type of “attachments” – Unattached to any node: data files – Fastened resources (can be moved only at high cost)

• Database, web sites – Fixed resources

• Local devices, communication end points

17

Page 18: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Resource Migration Actions

• Actions to be taken with respect to the references to local resources when migrating code to another machine.

• GR: establish global system-wide reference • MV: move the resources • CP: copy the resource • RB: rebind process to locally available resource

Unattached Fastened Fixed

By identifier By value By type

MV (or GR) CP ( or MV, GR) RB (or GR, CP)

GR (or MV) GR (or CP) RB (or GR, CP)

GR GR RB (or GR)

Resource-to machine binding

Process-to-resource

binding

18

Page 19: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Migration in Heterogeneous Systems• Systems can be heterogeneous (different architecture, OS)

– Support only weak mobility: recompile code, no run time information – Strong mobility: recompile code segment, transfer execution segment

[migration stack] – Virtual machines - interpret source (scripts) or intermediate code [Java]

19

Page 20: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Virtual Machine Migration

• VMs can be migrates from one physical machine to another

• Migration can be live - no application downtime • Iterative copying of memory state • How are network connections handled?

• Inherently migrates the OS and all its processes

20

Page 21: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

Computer Science Lecture 6, page

Pre-Copy VM Migration• 1. Enable dirty page tracking • 2. Copy all memory pages to destination • 3. Copy memory pages dirtied during the

previous copy again • 4. Repeat 3rd step until the rest of memory pages

is small. • 5. Stop VM • 6. Copy the rest of memory pages and • non-memory VM states • 7. Resume VM at destination

21

Figures Courtesy: Isaku Yamahata, LinuxCon Japan 2012

Page 22: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Post-Copy VM Migration

• 1. Stop VM • 2. Copy non-memory VM states to destination • 3. Resume VM at destination • 4. Copy memory pages on-demand/background

– Async page fault can be utilized

22

Page 23: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

VM Migration Time

23

Figu

re C

ourte

sy: I

saku

Yam

ahat

a, L

inux

Con

Jap

an 2

012

Page 24: Docker - lass.cs.umass.edulass.cs.umass.edu/~shenoy/courses/spring17/lectures/Lec07.pdf · LXC Virtualization Using Docker ... • Uses a virtualized architecture ... establish global

CS677: Distributed OSComputer Science Lecture 7, page

Case Study: Viruses and Malware

• Viruses and malware are examples of mobile code – Malicious code spreads from one machine to another

• Sender-initiated: – proactive viruses that look for machines to infect

• Autonomous code • Receiver-initiated

– User (receiver) clicks on infected web URL or opens an infected email attachment

24