Madhavapeddy University of Cambridge Richard Mortier University of Nottingham Dave Scott Citrix Systems R&D MIRAGE: EXTREME SPECIALISATION OF CLOUD APPLIANCES @avsm @mort___ @mugofsoup http://openmirage.org http://decks.openmirage.org/oscon13/ http://www.youtube.com/watch?v=2Mx8Bd5JYyo
CLOUD THREAT MODEL Type-safety in the application layer defeats several external threats. Type-safety in the kernel will make all external I/O safe, but at what cost?
DESIGN INSIGHTS The hypervisor gifts us a stable hardware interface. Cures the curse of library operating systems! Protocol-level compatibility between special-purpose cloud appliances, e.g. a webserver, a database VM.
The unikernel approach to building single-purpose appliances Library OS + high level programming interface Single-address space layout Evaluation of these techniques using a functional programming language (OCaml) Benefits of type-safety need not damage performance Static typing + modules = high level manipulation Language extensions for systems programming in OCaml
IMAGE SIZE Appliance Standard Build Dead Code Elimination DNS 0.449 MB 0.184 MB Web Server 0.674 MB 0.172 MB Openflow learning switch 0.393 MB 0.164 MB Openflow controller 0.392 MB 0.168 MB All configuration and data compiled into the image by the toolchain. Live migration is easy and fun :-)
DRIVEN CO-THREADS Garbage collected heap management is more efficient in a single address-space environment. Thread latency can be reduced by eliminating multiple levels of scheduling.
SCALING SINGLE INSTANCE Threads are heap allocated values, so benefit from the faster garbage collection cycle in the Mirage Xen version, and the scheduler can be overridden by application-specific needs.
Several implementation techniques give rise to these benefits: Simplified memory management Zero-copy IO buffer management Hypervisor security extension for VM sealing (W^X)
MANAGEMENT SPECIALISED! Compiled native source code and runtime statically linked with random start offset. IO memory is mapped into a reserved area and can be distinguished. OCaml heap is contiguous, with simpler write barriers as a result.
VM SEALING Single address-space and no dynamic loading W^X address space Address offsets are randomized at compile-time Dropping page table privileges: Added freeze hypercall called just before app starts Subsequent page table updates are rejected by Xen Exception for I/O mappings if they are non-exec and do not modify any existing mappings Very easy in unikernels due to focus on compile-time specialisation instead of run-time complexity
We have implemented several larger appliances. We discuss deens, our DNS server in detail here. We also have: a simple webserver, an OpenFlow Switch, and an OpenFlow Controller.
SERVER CODE let main () = lwt zones = read key "zones" "zone.db" in Net.Manager.bind (fun mgr dev -> let src = `any_addr, 53 in Dns.Server.listen dev src zones ) Cooperative threads as functions Statically evaluated configuration Functional callbacks Libraries directly link to network stack
SERVER PERFORMANCE MIRAGE Comparing against Mirage appliance, with and without simple memoisation. This algorithmic optimisation added just 6 lines of code.
SERVER PERFORMANCE C/MINIOS A rudimentary C-based appliance linking NSD directly against MiniOS. Poor user-space library performance vastly outweighs language effects.
VIA PARALLEL INSTANCES Request throughput for serving a simple static page using Apache on Linux vs. a Mirage appliance. Rather than pay the cost of interlocking for thread-level parallelism, we scale by running many instances of the Mirage appliance.
CONTROLLER OpenFlow controller is competitive with NOX (C++), but much higher level. Applications can link directly against the switch to route their data.
OCaml is the baseline language for all new code Our C runtime is small, and getting smaller Is fully event-driven and non-preemptive Rewriting protocols wasn’t that hard Not necessarily the best research strategy though But an extremely useful learning experience Tech transfer is vital Unikernels fit perfectly on the cloud Internet protocol building blocks Seamless interop with legacy code through VMs
ONLINE Website, Code, O'Reilly OCaml book, OPAM package manager Allows constraints to be applied to package installation Very useful for managing assembly of the many small OCaml modules that construct a Mirage appliance http://www.openmirage.org http://github.com/mirage http://realworldocaml.org http://opam.ocamlpro.com
RESEARCH DIRECTIONS Interoperability — with billions of VMs out there A unikernel per-language? Interconnect strategies? Heap sharing? Formal method integration easier or harder? Coordination — planetary scale computers Resources are highly elastic now. How to coordinate a million microkernels? “Warehouse Scale Computing” Library Applications — where are they? Irminsule, a git-like functional distributed database Beanstalk, a self-scaling web server
HIRING! MUST ENJOY OPEN SOURCE! OCamlLabs, Cambridge, UK Real world functional programming with OCaml Need compiler hackers, protocol heads, PL/type theory systems Networks-as-a-Service, University of Nottingham, UK (2 posts, 3 years, deadline Friday August 2nd) Joint with University of Cambridge & Imperial College Network virtualisation for millions of microkernel apps Need Mirage hackers, network protocol experts, graph theorists http://www.cl.cam.ac.uk/projects/ocamllabs http://bit.ly/13sBjjC