concurrent multicore ocaml a deep dive
play

Concurrent & Multicore OCaml: A deep dive KC Sivaramakrishnan 1 - PowerPoint PPT Presentation

Concurrent & Multicore OCaml: A deep dive KC Sivaramakrishnan 1 & Stephen Dolan 1 Leo White 2 , Jeremy Yallop 1,3 , Armal Guneau 4 , Anil Madhavapeddy 1,3 1 2 3 4 Concurrency Parallelism Concurrency Programming technique


  1. Concurrent & Multicore OCaml: A deep dive KC Sivaramakrishnan 1 & Stephen Dolan 1 Leo White 2 , Jeremy Yallop 1,3 , Armaël Guéneau 4 , Anil Madhavapeddy 1,3 1 2 3 4

  2. Concurrency ≠ Parallelism • Concurrency • Programming technique • Overlapped execution of processes • Parallelism • ( Extreme ) Performance hack • Simultaneous execution of computations

  3. Concurrency ≠ Parallelism • Concurrency • Programming technique • Overlapped execution of processes • Parallelism • ( Extreme ) Performance hack • Simultaneous execution of computations Concurrency ∩ Parallelism ➔ Scalable Concurrency

  4. Concurrency ≠ Parallelism • Concurrency • Programming technique • Overlapped execution of processes • Parallelism • ( Extreme ) Performance hack • Simultaneous execution of computations Concurrency ∩ Parallelism ➔ Scalable Concurrency ( Fibers ) ( Domains )

  5. Schedulers • Multiplexing fj bers over domain(s) Bake scheduler into the runtime system (GHC) •

  6. Schedulers • Multiplexing fj bers over domain(s) Bake scheduler into the runtime system (GHC) • • Allow programmers to describe schedulers! Parallel search —> LIFO work-stealing • Web-server —> FIFO runqueue • Data parallel —> Gang scheduling •

  7. Schedulers • Multiplexing fj bers over domain(s) Bake scheduler into the runtime system (GHC) • • Allow programmers to describe schedulers! Parallel search —> LIFO work-stealing • Web-server —> FIFO runqueue • Data parallel —> Gang scheduling • • Algebraic E ff ects and Handlers

  8. Algebraic e ff ects & handlers

  9. Algebraic e ff ects & handlers • Programming and reasoning about computational e ff ects in a pure setting. Cf. Monads •

  10. Algebraic e ff ects & handlers • Programming and reasoning about computational e ff ects in a pure setting. Cf. Monads • • E ff — http://www.e ff -lang.org/

  11. Algebraic E ff ects: Example exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1

  12. Algebraic E ff ects: Example exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1

  13. Algebraic E ff ects: Example exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1 val r : int = 4

  14. Algebraic E ff ects: Example effect Foo : int -> int exception Foo of int let f () = 1 + (perform (Foo 3)) let f () = 1 + (raise (Foo 3)) let r = let r = try try f () f () with effect (Foo i) k -> with Foo i -> i + 1 continue k (i + 1) val r : int = 4

  15. Algebraic E ff ects: Example effect Foo : int -> int exception Foo of int let f () = 1 + (perform (Foo 3)) let f () = 1 + (raise (Foo 3)) let r = let r = try try f () f () with effect (Foo i) k -> with Foo i -> i + 1 continue k (i + 1) val r : int = 4

  16. Algebraic E ff ects: Example effect Foo : int -> int exception Foo of int let f () = 1 + (perform (Foo 3)) let f () = 1 + (raise (Foo 3)) let r = let r = try try f () f () with effect (Foo i) k -> with Foo i -> i + 1 continue k (i + 1) val r : int = 4

  17. Algebraic E ff ects: Example effect Foo : int -> int exception Foo of int let f () = 1 + (perform (Foo 3)) 4 let f () = 1 + (raise (Foo 3)) let r = let r = try try f () f () with effect (Foo i) k -> with Foo i -> i + 1 continue k (i + 1) val r : int = 4

  18. Algebraic E ff ects: Example effect Foo : int -> int exception Foo of int let f () = 1 + (perform (Foo 3)) 4 let f () = 1 + (raise (Foo 3)) let r = let r = try try f () f () with effect (Foo i) k -> with Foo i -> i + 1 continue k (i + 1) val r : int = 4 val r : int = 5

  19. Algebraic E ff ects: Example effect Foo : int -> int exception Foo of int let f () = 1 + (perform (Foo 3)) 4 let f () = 1 + (raise (Foo 3)) let r = let r = try try f () f () with effect (Foo i) k -> with Foo i -> i + 1 continue k (i + 1) val r : int = 4 val r : int = 5 fj ber — lightweight stack

  20. Scheduler Demo 1 [1] https://github.com/kayceesrk/ocaml15-e ff /tree/master/chameneos-redux

  21. Implementation • Fibers: Heap allocated, dynamically resized stacks • ~10s of bytes • No unnecessary closure allocation costs unlike CPS

  22. Implementation • Fibers: Heap allocated, dynamically resized stacks • ~10s of bytes • No unnecessary closure allocation costs unlike CPS • One-shot delimited continuations • Simpli fj es reasoning about resources - sockets, locks, etc.

  23. Implementation • Fibers: Heap allocated, dynamically resized stacks • ~10s of bytes • No unnecessary closure allocation costs unlike CPS • One-shot delimited continuations • Simpli fj es reasoning about resources - sockets, locks, etc. • Handlers —> Linked-list of fj bers

  24. Implementation • Fibers: Heap allocated, dynamically resized stacks • ~10s of bytes • No unnecessary closure allocation costs unlike CPS • One-shot delimited continuations • Simpli fj es reasoning about resources - sockets, locks, etc. • Handlers —> Linked-list of fj bers handle / sp continue call chain reference handler

  25. Implementation • Fibers: Heap allocated, dynamically resized stacks • ~10s of bytes • No unnecessary closure allocation costs unlike CPS • One-shot delimited continuations • Simpli fj es reasoning about resources - sockets, locks, etc. • Handlers —> Linked-list of fj bers sp handle / handle / continue continue call chain reference handler

  26. Implementation • Fibers: Heap allocated, dynamically resized stacks • ~10s of bytes • No unnecessary closure allocation costs unlike CPS • One-shot delimited continuations • Simpli fj es reasoning about resources - sockets, locks, etc. • Handlers —> Linked-list of fj bers sp handle / continue call chain perform reference handler

  27. Native-code fj bers — Vanilla C

  28. Native-code fj bers — Vanilla C OCaml start program OCaml

  29. Native-code fj bers — Vanilla C OCaml start program OCaml C call C

  30. Native-code fj bers — Vanilla C OCaml start program OCaml C call C OCaml callback OCaml

  31. Native-code fj bers — Vanilla C OCaml start program OCaml C call C OCaml callback OCaml C call C

  32. Native-code fj bers — Vanilla C OCaml start program OCaml C call C OCaml callback OCaml C call C OCaml callback OCaml

  33. Native-code fj bers — E ff ects system stack C

  34. Native-code fj bers — E ff ects system stack OCaml start program C OCaml heap

  35. Native-code fj bers — E ff ects system stack OCaml start program handle C OCaml heap

  36. Native-code fj bers — E ff ects system stack OCaml start program handle C C C call OCaml heap

  37. Native-code fj bers — E ff ects system stack OCaml start program handle C C C call OCaml callback OCaml heap

  38. Native-code fj bers — E ff ects system stack OCaml start program handle C C C call OCaml callback C OCaml heap C call

  39. Native-code fj bers — E ff ects system stack OCaml start program handle C C C call OCaml callback C OCaml heap C call 1. Stack over fm ow checks for OCaml functions • Simple static analysis eliminates many checks

  40. Native-code fj bers — E ff ects system stack OCaml start program handle C C C call OCaml callback C OCaml heap C call 1. Stack over fm ow checks for OCaml functions • Simple static analysis eliminates many checks 2. FFI calls are more expensive due to stack switching • Specialise for calls which {allocate / pass arguments on stack / do neither}

  41. 0.25 0.75 0.5 0 1 almabench alt-ergo-parameter_smallest_divisor alt-ergo-carte_autorisee_3 alt-ergo-parameter_relabel alt-ergo-OBF__ggjj_2 alt-ergo-parameter_def alt-ergo-parameter_def Performance : Vanilla OCaml alt-ergo-OBF__yyll_1 alt-ergo-bbvv_351 alt-ergo-controler_carte_13 alt-ergo-div2_sub alt-ergo-parameter_def alt-ergo-ccgg_2055 alt-ergo-parameter_def alt-ergo-parameter_inverse_in_place alt-ergo-ccgg_1759 4.02.2+effects Normalised time (lower is better) alt-ergo-parameter_def alt-ergo-induction_step alt-ergo-ccgg_1618 alt-ergo-ccgg_219 alt-ergo-advance_automaton_25 alt-ergo-nsec_sum_higher_than_1s alt-ergo-fill_assert_39_Alt-Ergo bdd chameneos-async chameneos-lwt cohttp-lwt core_micro cpdf-merge cpdf-reformat cpdf-squeeze cpdf-transform frama-c-deflate frama-c-idct js_of_ocaml jsontrip-sample kb kb-no-exc lexifi-g2pp menhir-fancy menhir-sql 4.02.2+vanilla menhir-standard minilight numal-durand-kerner-aberth numal-fft numal-k-means numal-levinson-durbin numal-lu-decomposition numal-naive-multilayer numal-qr-decomposition numal-rnd_access numal-simple_access patdiff sauvola-contrast sequence sequence-cps setrip setrip-smallbuf thread-ring-async-pipe thread-ring-lwt-mvar thread-ring-lwt-stream thread-sleep-async thread-sleep-lwt valet-async valet-lwt ydump-sample

Recommend


More recommend