Overview
                                Examples
                       Erlang Supervision




                   Erlang/...
Overview
                                      Examples
                             Erlang Supervision




1   Overview

...
Overview
                                      Examples
                             Erlang Supervision


What is Supervis...
Overview
                                     Examples
                            Erlang Supervision


Why Use Supervisio...
Overview
                                     Examples
                            Erlang Supervision


Real World Example...
Overview
                                     Examples
                            Erlang Supervision


Most Basic Example...
Overview
                                      Examples
                             Erlang Supervision


A Supervision Tr...
Overview
                                      Examples
                             Erlang Supervision


Classic Erlang S...
Overview
                                      Examples
                             Erlang Supervision


Classic Supervis...
Overview
                                     Examples
                            Erlang Supervision


The OTP Supervisor...
Overview
                                     Examples
                            Erlang Supervision


OTP Supervisor Exa...
Overview
                                      Examples
                             Erlang Supervision


Restart Strategi...
Overview
                                      Examples
                             Erlang Supervision


Children Restart...
Overview
                                      Examples
                             Erlang Supervision


One For All




...
Overview
                                     Examples
                            Erlang Supervision


Simple One For One...
Overview
                                      Examples
                             Erlang Supervision


Scenarios




  ...
Overview
                                      Examples
                             Erlang Supervision


Resources



   ...
Upcoming SlideShare
Loading in …5
×

CEUG: Introduction to OTP Behaviors, Part II - supervisors

2,415 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,415
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
33
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

CEUG: Introduction to OTP Behaviors, Part II - supervisors

  1. 1. Overview Examples Erlang Supervision Erlang/OTP Supervision Tristan Sloughter (kungfooguru@gmail.com) June 2, 2010 Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  2. 2. Overview Examples Erlang Supervision 1 Overview 2 Examples 3 Erlang Supervision Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  3. 3. Overview Examples Erlang Supervision What is Supervision? Watches child processes Starts processes (or links to them) and is notified on their exit Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  4. 4. Overview Examples Erlang Supervision Why Use Supervision? On failure a process can immediately be returned to a base state Keeps the system running even on failures Allows you to not rely on defensive coding to keep a system running for a long time Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  5. 5. Overview Examples Erlang Supervision Real World Examples Chat Server : On failure restart with empty list of connected users (the base state) Streaming video : Video streaming in could be corrupted, if this causes a process to crash it can be quickly restarted and continue accepting data Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  6. 6. Overview Examples Erlang Supervision Most Basic Example Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  7. 7. Overview Examples Erlang Supervision A Supervision Tree Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  8. 8. Overview Examples Erlang Supervision Classic Erlang Supervision Link processes A terminating process sends an exit signal to all linked processes Trap exits Sets the process to not exit on receiving exit signal Process instead receives message of the form: {’EXIT’, From, Reason} Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  9. 9. Overview Examples Erlang Supervision Classic Supervisor supervisor_init() -> process_flag(trap_exit, true), Pid = chatserver:start_link(), supervisor(Pid, chatserver, start_link) supervisor(Pid, Module, Function) -> receive {’EXIT’, From, Reason} -> ... end. Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  10. 10. Overview Examples Erlang Supervision The OTP Supervisor Behaviour Standard process for implementing supervision Provides preconfigured supervision strategies Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  11. 11. Overview Examples Erlang Supervision OTP Supervisor Example init([]) -> RestartStrategy = one_for_one, MaxRestarts = 1000, MaxSecondsBetweenRestarts = 3600, SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts}, AChild = {Name, {Module, Function, Args}, Restart, Shutdown, Type, Module}, {ok, {SupFlags, [AChild]}}. Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  12. 12. Overview Examples Erlang Supervision Restart Strategies ... RestartStrategy = one_for_one, MaxRestarts = 1000, MaxSecondsBetweenRestarts = 3600, ... A supervisor has a restart strategy to follow when a child dies, which could effect other children The RestartStrategy variable in our example could be: one for one : Only the one process that dies is restarted one for all : All processes are started and restarted in order if one dies rest for one : Processes started after child that dies are stopped and then all restarted in order Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  13. 13. Overview Examples Erlang Supervision Children Restart Strategies ... AChild = {Name, {Module, Function, Args}, Restart, Shutdown, Type, Module}, ... Each child process (worker) can have 1 of 3 strategies for the supervisor to follow when it exists The Restart variable in our example could be one of these: permanent : On ANY exit, restart transient : On abnormal exit, restart temporary : Never restart Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  14. 14. Overview Examples Erlang Supervision One For All Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  15. 15. Overview Examples Erlang Supervision Simple One For One Dynamic supervision Essentially a process factory Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  16. 16. Overview Examples Erlang Supervision Scenarios Web Server : one for one with temporary children Media Server Encoder : one for one with permanent children Poker Server : one for all with transient children Facebook Session : simple one for one Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision
  17. 17. Overview Examples Erlang Supervision Resources Simple-one-for-one - http://kungfooguru.wordpress.com/2009/08/05/ erlang-simple-one-for-one-supervisor/ Supervisor Design Principles - http://www.erlang.org/ doc/design_principles/sup_princ.html Supervisor Behaviour - http://www.erlang.org/doc/man/supervisor.html Tristan Sloughter (kungfooguru@gmail.com) Erlang/OTP Supervision

×