Concurrent & Multicore OCaml: A deep dive
KC Sivaramakrishnan1 & Stephen Dolan1 Leo White2, Jeremy Yallop1,3, Armaël Guéneau4, Anil Madhavapeddy1,3
1 2 3 4
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
KC Sivaramakrishnan1 & Stephen Dolan1 Leo White2, Jeremy Yallop1,3, Armaël Guéneau4, Anil Madhavapeddy1,3
1 2 3 4
in a pure setting.
in a pure setting.
exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1
exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1
exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1
exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1
effect Foo : int -> int let f () = 1 + (perform (Foo 3)) let r = try f () with effect (Foo i) k -> continue k (i + 1)
exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1
effect Foo : int -> int let f () = 1 + (perform (Foo 3)) let r = try f () with effect (Foo i) k -> continue k (i + 1)
exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1
effect Foo : int -> int let f () = 1 + (perform (Foo 3)) let r = try f () with effect (Foo i) k -> continue k (i + 1)
exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1
effect Foo : int -> int let f () = 1 + (perform (Foo 3)) 4 let r = try f () with effect (Foo i) k -> continue k (i + 1)
exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1
effect Foo : int -> int let f () = 1 + (perform (Foo 3)) 4 let r = try f () with effect (Foo i) k -> continue k (i + 1)
exception Foo of int let f () = 1 + (raise (Foo 3)) let r = try f () with Foo i -> i + 1
effect Foo : int -> int let f () = 1 + (perform (Foo 3)) 4 let r = try f () with effect (Foo i) k -> continue k (i + 1)
fjber — lightweight stack
[1] https://github.com/kayceesrk/ocaml15-eff/tree/master/chameneos-redux
handle / continue
handler sp
call chain reference
handle / continue handle / continue
sp handler
call chain reference
perform
sp
handle / continue
handler
call chain reference
C
OCaml start program
C OCaml
OCaml start program C call
C OCaml C
OCaml start program C call OCaml callback
C OCaml C OCaml
OCaml start program C call OCaml callback C call
C OCaml C OCaml C
OCaml start program C call OCaml callback C call OCaml callback
C OCaml C OCaml C OCaml
C
system stack
C
system stack
OCaml heap
OCaml start program
C
system stack
OCaml heap
OCaml start program handle
C
system stack
OCaml heap
OCaml start program C call handle
C
C
system stack
OCaml heap
OCaml start program C call handle OCaml callback
C
C
system stack
OCaml heap
OCaml start program C call handle OCaml callback C call
C C
C
system stack
OCaml heap
OCaml start program C call handle OCaml callback C call
C C
C
system stack
OCaml heap
OCaml start program C call handle OCaml callback C call
C C
0.25 0.5 0.75 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 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 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 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
4.02.2+effects 4.02.2+vanilla
Normalised time (lower is better)
0.25 0.5 0.75 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 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 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 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
4.02.2+effects 4.02.2+vanilla
Normalised time (lower is better)
Time (S) 0.45 0.9 1.35 1.8 Iterations (X100,000) 1 2 3 4 5 6 7 8 9 10
Lwt Concurrency Monad GHC Fibers
[1] https://github.com/kayceesrk/ocaml15-eff/blob/master/generator.ml
let rec iter f = function | Leaf -> () | Node (l, x, r) -> iter f l; f x; iter f r type 'a t = | Leaf | Node of 'a t * 'a * 'a t
[1] https://github.com/kayceesrk/ocaml15-eff/blob/master/generator.ml
(* val to_gen : 'a t -> (unit -> 'a option) *) let to_gen (type a) (t : a t) = let module M = struct effect Next : a -> unit end in let open M in let step = ref (fun () -> assert false) in let first_step () = try iter (fun x -> perform (Next x)) t; None with effect (Next v) k -> step := continue k; Some v in step := first_step; fun () -> !step () let rec iter f = function | Leaf -> () | Node (l, x, r) -> iter f l; f x; iter f r type 'a t = | Leaf | Node of 'a t * 'a * 'a t
Time (S) 1 2 3 4 Binary tree depth 15 16 17 18 19 20 21 22 23 24 25
Iterator Fiber Generator H/W Generator
[1] https://github.com/kayceesrk/ocaml15-eff/tree/master/async-io
[1] https://github.com/kayceesrk/ocaml15-eff/tree/master/async-io