1 / 36

Tomas Mannerstedt 25/2 - 09

Tomas Mannerstedt 25/2 - 09. Erlang Multicore. Your free lunch will soon be over. What can you do about it? What are you doing about it? Herb Sutter Dr. Dobb’s Journal 30(3), March 2005. Erlang Multicore. Purpose:

amity
Download Presentation

Tomas Mannerstedt 25/2 - 09

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tomas Mannerstedt • 25/2 - 09 Erlang Multicore

  2. Your free lunch will soon be over. What can you do about it? What are you doing about it? Herb Sutter Dr. Dobb’s Journal 30(3), March 2005

  3. Erlang Multicore Purpose: To show why Erlang is a good choice when developing in multicore architecture. Not go deeply into syntax but show some examples.

  4. What is Erlang? Measurement of traffic intensity. ERicsson LANGuage. Run-time environment Operating system

  5. Erlang History 1981: Project began as an extension of Prolog. 1987: First version released 1996: OTP 1998: 1:st AXD301 (1.7 million lines of Erlang code) 1998: Erlang open source 2006: R11B with SMP

  6. Erlang – Crash course Dynamically typed: int float atom list tuple binary

  7. Erlang – Crash course Single assignment: X = foo(). Y = bar(). X = Y. X = X + 1.

  8. Erlang – Crash course Functional, pattern matching: No for(), while() etc. Only functions: fac(0) -> 1; fac(N) when N > 0 -> N * fac(N-1).

  9. Erlang – Crash course -module(shapes). -export([area/1]). area({square, X}) -> X*X; area({triangle, Base, Height}) -> Base * Height / 2; area({circle, Radius}) -> math:pi() * Radius * Radius; area([]) -> 0; area([Shape|Rest]) -> area(Shape) + area(Rest).

  10. Erlang – Crash course Functional, true functional languages have no side effects: Functions have no state. Same answer every time. No shared data.

  11. Erlang – Crash course Functional, no side effects, or?: Output Databases send / receive messages Fairly easy to control though 

  12. COPL – Concurrency Oriented Programming Language Programming paradigm defined by Joe Armstrong. The real world is parallel, nothing is sequential.

  13. Characteristics of a COPL Support processes Have strongly isolated processes. Crash cannot affect other processes. Have Unique PID:s. Message passing via PID. No shared state. Message passing is unreliable. Possible for one process to detect problems in other process.

  14. Erlang is designed for Share nothing concurrency IPC by asynchronous message passing Fault tolerance No mutexes, since no shared memory Telecomunication applications (which contains lots of parallelizable tasks).

  15. Erlang processess Lightweight processes. “Does what it’s supposed to do or crashes” Creating a process is fast! An Erlang application can contain thousands of processes.

  16. Simple example – Server start() -> spawn(fun() -> do_start() end). do_start() -> true = register(?MODULE, self()), loop(). loop() -> receive kill -> io:format("~p: I'm dieing now!~n", [?MODULE]); Message -> io:format("~p: Message: ~p~n", [?MODULE, Message]), loop() end.

  17. Erlang SMP support First release in May 2006 (R11B). ”Make it work” ”Find bottlenecks” ”Remove bottlenecks”

  18. The Erlang Scheduler Erlang VM runs in one OS process. Deafult: Uses one posix-thread per scheduler. One scheduler per core. Up to 1024 schedulers. All schedulers (currently, R12) share one run queue. Erlang VM with SMP support is 10% slower than non SMP VM.

  19. Result of using Erlang SMP support Ericsson TGC: Required to have 99.999% availability. (< 6min/year downtime) Performance increaced by 1.7, by enabling dual core! Minor code changes.

  20. Performance - Big Bang Sun Fire T2000 has UltraSparc T1.

  21. Current bottlenecks One run-queue. Will be changed to one run-queue per scheduler. ETS locks ”per table”: Will be changed to lock ”per row”. Message passing.

  22. Experiment with multiple run-queue

  23. Programming example lists:map/2: lists:map(fun(X) -> X*X end, lists:seq(1,5)). [1,4,9,16,25] plists:map/2: plists:map(fun(X) -> X*X end, lists:seq(1,5)). [1,4,9,16,25]

  24. Programming example map(Fun, List) -> Pids = spawn_workers(self(), Fun, List), collect_answers(Pids). spawn_workers(_Parent, _Fun, []) -> []; spawn_workers(Parent, Fun, [Head|Tail]) -> Pid = spawn(fun() -> Parent ! {self(), Fun(Head)} end), [Pid | spawn_workers(Parent, Fun, Tail)]. collect_answers([]) -> []; collect_answers([Pid|Pids]) -> receive {Pid, Result} -> [Result | collect_answers(Pids)] end.

  25. Benchmark

  26. Benchmark

  27. Nodes An Erlang Node is an instance of the Erlang VM. Two nodes that share a secret (cookie) can: Send RPC to each other. Spawn a process on the other node. Nodes have unique name on the form: my_node@my_computer

  28. Is Erlang fast? Yes: Handling large amount requests. BIF:s are written in C. HiPE No: Many languages are faster.

  29. OTP – Open Telephony Platform Standard library modules: lists set file erlang ets mnesia etc.

  30. OTP – Open Telephony Platform Protocols: TCP UDP RTP IP SSL HTTP SNMP megaco (H.248) etc.

  31. OTP – Open Telephony Platform Tools: common_test edoc debugger dialyzer (static analysis tool) percept (profiler) etc.

  32. OTP – Open Telephony Platform Design Patterns: gen_server gen_fsm gen_event

  33. Erlang users Ericsson - Telecommunication nodes Facebook – Chat service Amazon - SimpleDB Kreditor - Economics Tail-f - Netconf Mochi Media – Ad service

  34. References Making reliable distributed systems in the presence of software errors, Joe Armstrong, 2003 Erlang Multicore, Ulf Wiger Inside the Erlang VM, Kenneth Lundin, 2008 Erlang Reference Manual, Jonas Barklund, Robert Virding http://www.erlang.org

  35. Nice things about Erlang I haven’t told you about… Soft upgrade Platform independent much more…

More Related