SlideShare uma empresa Scribd logo
1 de 108
MASSIVELY SCALEABLE
MASSIVELY FAULT-TOLERANT
         Trotter Cashion
       Philly Lambda, 2011
Erlang
BUT FIRST...
                         AND               OTP
                         IN ACTION
   Buy this Book!
http://bit.ly/otp-book   Martin Logan
                         Eric Merritt
                         Richard Carlsson
                         FOREWORD BY ULF WIGER




                                 MANNING
Erlang
NO SERIOUSLY... IN ACTION
                           AND               OTP
  http://bit.ly/otp-book
                           Martin Logan
                           Eric Merritt
                           Richard Carlsson
                           FOREWORD BY ULF WIGER




                                   MANNING
Erlang
AVAILABLE IN
   PDF...
                         AND               OTP
                         IN ACTION
http://bit.ly/otp-book
                         Martin Logan
                         Eric Merritt
                         Richard Carlsson
                         FOREWORD BY ULF WIGER




                                 MANNING
AND NOW FOR
    ME...
CO-FOUNDER
@CASHION




   http://www.charlesheflin.com/wp-content/uploads/2010/06/fail-whale.jpg
github.com/trotter
CHLOE


• Realtime Web    Server

• Proxies WebSocket    (and fallback) connections to your app

• http://github.com/mashion/chloe

• Written   in Erlang/OTP (plus a lot of JavaScript)
BAI PHILLY!
 Leaving in July...




                      http://www.flickr.com/photos/dennis/156048151/
HAI CALIFORNIA!
  See you in August...




                         http://www.flickr.com/photos/salim/402618628/
AN ERLANG PRIMER




               Yoinked from the Erlang Movie. Go Watch It!!!!
THE BASICS

• Functional

• Single Assignment Variables

• Pattern   Matching is Big Here

• Everything’s   a Process

• One   Module Per File
FUNCTIONAL
say_hello() ->
  io:fwrite("Ohai!n").
ANONYMOUS FUNCTIONS
make_hello() ->
  fun () -> io:fwrite("Ohai!n")
end.

Hello = make_hello().
Hello().
SINGLE ASSIGNMENT VARS
1>   Hello = 3.
3
2>   Hello = 2.
**   exception error: no match of right hand side value 2
3>   f().
ok
4>   Hello = 2.
2
OH NOES! WHAT WENT WRONG?
destructuring_bind() ->
  [{Name, Title}, _] = [{"Trotter", "Speaker"},
                        {"Aaron", "Organizer"}],
  io:fwrite("~pn", [Name]), %% => Trotter
  io:fwrite("~pn", [Title]). %% => Speaker
PATTERN MATCHING
           Erlang                  Ruby
match_me(1) ->         def match_me(val)
  loneliest;             case val
match_me(2) ->           when 1
  next_to_loneliest;       :loneliest
match_me(friend) ->      when 2
  all_ok;                  :next_to_loneliest
match_me(_) ->           when :friend
  what_is_this.            :all_ok
                         else
                           :what_is_this
                         end
                       end
MAKING A PROCESS
                     process.erl

concurrent_stuffs() ->
  spawn(fun () -> timer:sleep(1000),
                  io:fwrite("So slown") end),
  spawn(fun () -> io:fwrite("Super fastn") end).

                    erlang shell
5> process:concurrent_stuffs().
Super fast
<0.39.0>
So slow
RECEIVE LOOPS
food_loop() ->
  receive
    pizza -> io:fwrite("let's eatn"),
             food_loop();
    death -> io:fwrite("all done heren");
    _     -> io:fwrite("Nothing to don"),
             food_loop()
  end.
SENDING MESSAGES
make_process() ->
  spawn(?MODULE, food_loop, []).

pizza_death() ->
  Proc = make_process(),
  Proc ! pizza,
  Proc ! hi,
  Proc ! death,
  %% Goes into the void
  Proc ! huh.
HOW THAT WORKS
  process 1

pizza_death
HOW THAT WORKS
  process 1
              spawn/3
pizza_death
HOW THAT WORKS
  process 1              process 2
              spawn/3
pizza_death             food_loop
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza

                  hi
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza

                  hi

               death
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza

                  hi

               death

                 huh
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza

                  hi

               death

                 huh
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza

                  hi

               death

                 huh
HOW THAT WORKS
  process 1                   process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza       “let’s eatn”

                  hi

               death

                 huh
HOW THAT WORKS
  process 1                   process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza       “let’s eatn”

                  hi

               death

                 huh
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza

                  hi

               death

                 huh
HOW THAT WORKS
  process 1                      process 2
              spawn/3
pizza_death                    food_loop

              food_loop’s
                Mailbox

                pizza

                  hi        “Nothing to don”

               death

                 huh
HOW THAT WORKS
  process 1                      process 2
              spawn/3
pizza_death                    food_loop

              food_loop’s
                Mailbox

                pizza

                  hi        “Nothing to don”

               death

                 huh
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza

                  hi

               death

                 huh
HOW THAT WORKS
  process 1                      process 2
              spawn/3
pizza_death                    food_loop

              food_loop’s
                Mailbox

                pizza

                  hi

               death        “all done heren”

                 huh
HOW THAT WORKS
  process 1                      process 2
              spawn/3
pizza_death                    food_loop

              food_loop’s
                Mailbox

                pizza

                  hi

               death        “all done heren”

                 huh
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza

                  hi

               death

                 huh
HOW THAT WORKS
  process 1                  process 2
              spawn/3
pizza_death                 food_loop

              food_loop’s
                Mailbox

                pizza

                  hi

               death

                 huh
HOW THAT WORKS
  process 1
              spawn/3
pizza_death

              food_loop’s
                Mailbox

                pizza

                  hi

               death

                 huh
HOW THAT WORKS
  process 1
              spawn/3
pizza_death




               pizza

                hi

               death

                huh
HOW THAT WORKS
  process 1
              spawn/3
pizza_death




               pizza

                hi

               death
BUT DOES IT SCALE?
      Hells yea!




                   http://www.flickr.com/photos/24736216@N07/4808606178/
TWO WAYS TO SCALE

  Name             Implementation



Horizontally    Buy a lot of machines



 Vertically    Buy a really big machine
ERLANG SCALES WELL ON BOTH
WITH NEARLY ZERO CODE CHANGE
BOOM!
VERTICAL SCALING



• Your   processes will take advantage of all cores available

• Yay!   No code changes required
HORIZONTAL SCALING


• New      nodes added to the cluster can be auto-detected

• Code     must know that a service could live on another node

• You’ll   need resource discovery
CONNECTING NODES
$ erl -name b
1> AHost = 'a@awesome-town.local'.
'a@awesome-town.local'

2> io:fwrite("Current nodes: ~p~n", [nodes()]).
Current nodes: []

3> io:fwrite("Ping? ~p~n", [net_adm:ping(AHost)]).
Ping? pong

4> io:fwrite("Current nodes: ~p~n", [nodes()]).
Current nodes: ['a@awesome-town.local'

5> q().
SERVER REFERENCES

        Type                        Definition

        <Pid>            globally unique process identifier

   RegisteredName           locally registered process

                           process locally registered on
{RegisteredName, Node}
                                  another node

 {global, GlobalName}       globally registered process
LISTEN FOR INCOMING MESSAGE
listen() ->
  register(listener, self()),
  listen_loop().

listen_loop() ->
  receive
    {From, pizza} -> From ! "Nom noms", listen_loop();
    {From, _}     -> From ! "Boo!", listen_loop();
    _             -> io:fwrite("Listen is dying!")
  end.
SENDING MESSAGE TO NODES
$ erl -name b
1> AHost = 'a@awesome-town.local'.
'a@awesome-town.local'

2> {listener, AHost} ! {self(), pizza}.
ok

3> receive PizzaResp -> PizzaResp end.
RESOURCE DISCOVERY

          Method                                Purpose


 add_target_resource(Type)      specify a resource type you want to use


add_local_resource(Type, Pid)      specify a resource type you have


   fetch_resources(Type)          fetch all resources of specified type


     trade_resources()                trade resource information

                                      See Chapter 8 of Erlang And OTP In Action
HORIZONTAL CAVEATS


• Passing   large amounts of data between nodes is inefficient

• Too   many nodes will impact performance (Keep it < 100)

• There   are ways around both these problems
OTP BASICS
Cause managing all the processes by hand is dumb




                                                   Thanks, Homer
OTPWTFBBQ?


• Open Telecom      Platform

• Abstracts    common systems behavior (servers, supervisors, ...)

• Easier   than pure Erlang!

• Gives    Erlang its reputation for fault tolerance
BASIC CONSTRUCTS

Construct                Purpose

              Encapsulates a large set of code
Application
                 meant to run as one unit.

Supervisor      Starts and restarts workers.


 Worker             Actually does stuff
HTTP://GITHUB.COM/MASHION/CHLOE

                             Chloe
                          (Application)




                            chloe_sup
                           (Supervisor)




 websocket_sup   session_sup      session_manager
                                                    Other Stuffs
  (Supervisor)   (Supervisor)         (Worker)
WORKERS


• Use   the `gen_server` behaviour (for the most part)

• Contain   your application logic

• You   define a module with callbacks

• OTP   runs a server calls back to module when messages arrive
HOW WORKERS WORK
    client process (your code)

                  gen_server functions



  gen_server code (part of OTP)

                  gen_server callbacks


    worker code (your code)
                           worker process
SENDING MESSAGES TO WORKERS
say_hello_sync(Name) ->
  gen_server:call(?SERVER, {say_hello, Name}).

say_hello_async() ->
  gen_server:cast(?SERVER, say_hello).




                                          gen_server_examples.erl
EXAMPLE CALLBACKS
handle_call({say_hello, Name}, _From, State) ->
  Response = string:concat("Hello, ", Name),
  {reply, {ok, Response}, State}.

handle_cast(say_hello, State) ->
  io:fwrite("Hello world!n"),
  {noreply, State}.




                                          gen_server_examples.erl
WORKER CALLBACKS

            Callback                             Purpose
            init(Args)                 Initialize the server process
handle_call(Request, From, State)       Handle a synchronous call
   handle_cast(Request, State)        Handle an asynchronous cast
     handle_info(Info, State)       For timeouts and random messages
    terminate(Reason, State)        Clean up the process when it dies
code_change(OldVsn, State, Extra)      Called when upgrading code
WORKER FUNCTIONS

            Callback                           Purpose

start_link(Module, Args, Options)      Start a supervised worker

  start(Module, Args, Options)       Start an unsupervised worker

call(ServerRef, Request, Timeout)     Synchronously call a worker

    cast(ServerRef, Request)        Asynchronously cast to a worker




                                                         man gen_server
SUPERVISORS


• Use   the `supervisor` behaviour

• Contain   little to no application logic

• Know   how to start and restart failed workers

• Keep   your application from ever fully dying
CHILD SPECS
{Id, StartFunc, Restart, Shutdown, Type, Modules}




           Unique name used to identify
                  child process.
CHILD SPECS
{session_manager, StartFunc, Restart, Shutdown, Type,
                     Modules}



             Unique name used to identify
                    child process.
CHILD SPECS
{session_manager, StartFunc, Restart, Shutdown, Type,
                     Modules}



              Tuple {M, F, A} used to start
                       the child.
CHILD SPECS
{session_manager, {session_manager, start_link, []},
        Restart, Shutdown, Type, Modules}



             Tuple {M, F, A} used to start
                      the child.
CHILD SPECS
{session_manager, {session_manager, start_link, []},
        Restart, Shutdown, Type, Modules}



                Determines when a
            terminated process should be
                     restarted.
CHILD SPECS
{session_manager, {session_manager, start_link, []},
      permanent, Shutdown, Type, Modules}



                Determines when a
            terminated process should be
                     restarted.
CHILD SPECS
{session_manager, {session_manager, start_link, []},
      permanent, Shutdown, Type, Modules}



             Determines how to kill child
                    processes.
CHILD SPECS
{session_manager, {session_manager, start_link, []},
        permanent, 5000, Type, Modules}



             Determines how to kill child
                    processes.
CHILD SPECS
{session_manager, {session_manager, start_link, []},
        permanent, 5000, Type, Modules}



              Is this child a worker or a
                       supervisor?
CHILD SPECS
{session_manager, {session_manager, start_link, []},
       permanent, 5000, worker, Modules}



              Is this child a worker or a
                       supervisor?
CHILD SPECS
{session_manager, {session_manager, start_link, []},
       permanent, 5000, worker, Modules}



            Used by code reloading. Make
              it the same as the other
                    module name.
CHILD SPECS
{session_manager, {session_manager, start_link, []},
  permanent, 5000, worker, [session_manager]}



            Used by code reloading. Make
              it the same as the other
                    module name.
RESTART STRATEGIES

     Strategy              When a child dies....

   one_for_one                    restart it

    one_for_all             restart all children

                     restart it and all children after it
   rest_for_one
                                 in child list
                       restart it (also allows you to
simple_one_for_one
                        dynamically add children)
ONE_FOR_ONE

             Supervisor




Child 1       Child 2     Child 3
ONE_FOR_ONE

   Supervisor




    Child 2     Child 3
ONE_FOR_ONE

             Supervisor




Child 1       Child 2     Child 3
ONE_FOR_ALL

             Supervisor




Child 1       Child 2     Child 3
ONE_FOR_ALL

   Supervisor




    Child 2     Child 3
ONE_FOR_ALL

   Supervisor




                Child 3
ONE_FOR_ALL

   Supervisor
ONE_FOR_ALL

             Supervisor




Child 1
ONE_FOR_ALL

             Supervisor




Child 1       Child 2
ONE_FOR_ALL

             Supervisor




Child 1       Child 2     Child 3
REST_FOR_ONE

             Supervisor




Child 1       Child 2     Child 3
REST_FOR_ONE

             Supervisor




Child 1                   Child 3
REST_FOR_ONE

             Supervisor




Child 1
REST_FOR_ONE

             Supervisor




Child 1       Child 2
REST_FOR_ONE

             Supervisor




Child 1       Child 2     Child 3
SIMPLE_ONE_FOR_ONE

      Supervisor
SIMPLE_ONE_FOR_ONE

          Supervisor




Child 1
SIMPLE_ONE_FOR_ONE

          Supervisor




Child 1    Child 2
SIMPLE_ONE_FOR_ONE

          Supervisor




Child 1    Child 2     Child 3
SIMPLE_ONE_FOR_ONE

      Supervisor




       Child 2     Child 3
SIMPLE_ONE_FOR_ONE

          Supervisor




Child 1    Child 2     Child 3
STARTING A SUPERVISOR
init([]) ->
  Worker = {gen_server_examples,
            {gen_server_examples, start_link, []},
            permanent, 5000, worker,
            [gen_server_examples]},
  RestartStrategy = {one_for_one, 5, 30},
  {ok, {RestartStrategy, [Worker]}}.
SUPERVISOR CALLBACK

callback                 purpose
             return data structure telling what
init(Args)
                       to supervise
SUPERVISOR FUNCTIONS

          Callback                           Purpose

   start_link(Module, Args)        Start a supervised supervisor

start_child(SupRef, ChildSpec)   Start a child under the supervisor




                                                         man supervisor
FAULT TOLERANCE

• When     you hit an error, let the worker die

• Supervisor    will restart it

• Either   try what killed it again or move on

• Life   is grand
LINKS



• http://bit.ly/erlang-otp-gist

• http://bit.ly/otp-book
THANK YOU!

• Questions?

• http://bit.ly/erlang-otp-gist

• http://bit.ly/otp-book

• http://mashion.net

Mais conteúdo relacionado

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Último (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Massively Scalable, Massively Fault Tolerant

  • 1. MASSIVELY SCALEABLE MASSIVELY FAULT-TOLERANT Trotter Cashion Philly Lambda, 2011
  • 2. Erlang BUT FIRST... AND OTP IN ACTION Buy this Book! http://bit.ly/otp-book Martin Logan Eric Merritt Richard Carlsson FOREWORD BY ULF WIGER MANNING
  • 3. Erlang NO SERIOUSLY... IN ACTION AND OTP http://bit.ly/otp-book Martin Logan Eric Merritt Richard Carlsson FOREWORD BY ULF WIGER MANNING
  • 4. Erlang AVAILABLE IN PDF... AND OTP IN ACTION http://bit.ly/otp-book Martin Logan Eric Merritt Richard Carlsson FOREWORD BY ULF WIGER MANNING
  • 5. AND NOW FOR ME...
  • 7. @CASHION http://www.charlesheflin.com/wp-content/uploads/2010/06/fail-whale.jpg
  • 9. CHLOE • Realtime Web Server • Proxies WebSocket (and fallback) connections to your app • http://github.com/mashion/chloe • Written in Erlang/OTP (plus a lot of JavaScript)
  • 10. BAI PHILLY! Leaving in July... http://www.flickr.com/photos/dennis/156048151/
  • 11. HAI CALIFORNIA! See you in August... http://www.flickr.com/photos/salim/402618628/
  • 12. AN ERLANG PRIMER Yoinked from the Erlang Movie. Go Watch It!!!!
  • 13. THE BASICS • Functional • Single Assignment Variables • Pattern Matching is Big Here • Everything’s a Process • One Module Per File
  • 15. ANONYMOUS FUNCTIONS make_hello() ->   fun () -> io:fwrite("Ohai!n") end. Hello = make_hello(). Hello().
  • 16. SINGLE ASSIGNMENT VARS 1> Hello = 3. 3 2> Hello = 2. ** exception error: no match of right hand side value 2 3> f(). ok 4> Hello = 2. 2
  • 17. OH NOES! WHAT WENT WRONG? destructuring_bind() ->   [{Name, Title}, _] = [{"Trotter", "Speaker"},                         {"Aaron", "Organizer"}],   io:fwrite("~pn", [Name]), %% => Trotter   io:fwrite("~pn", [Title]). %% => Speaker
  • 18. PATTERN MATCHING Erlang Ruby match_me(1) -> def match_me(val)   loneliest;   case val match_me(2) ->   when 1   next_to_loneliest;     :loneliest match_me(friend) ->   when 2   all_ok;     :next_to_loneliest match_me(_) ->   when :friend   what_is_this.     :all_ok   else     :what_is_this   end end
  • 19. MAKING A PROCESS process.erl concurrent_stuffs() ->   spawn(fun () -> timer:sleep(1000),                   io:fwrite("So slown") end),   spawn(fun () -> io:fwrite("Super fastn") end). erlang shell 5> process:concurrent_stuffs(). Super fast <0.39.0> So slow
  • 20. RECEIVE LOOPS food_loop() ->   receive     pizza -> io:fwrite("let's eatn"),              food_loop();     death -> io:fwrite("all done heren");     _ -> io:fwrite("Nothing to don"),              food_loop()   end.
  • 21. SENDING MESSAGES make_process() ->   spawn(?MODULE, food_loop, []). pizza_death() ->   Proc = make_process(),   Proc ! pizza,   Proc ! hi,   Proc ! death,   %% Goes into the void   Proc ! huh.
  • 22. HOW THAT WORKS process 1 pizza_death
  • 23. HOW THAT WORKS process 1 spawn/3 pizza_death
  • 24. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop
  • 25. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox
  • 26. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox
  • 27. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza
  • 28. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi
  • 29. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi death
  • 30. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi death huh
  • 31. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi death huh
  • 32. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi death huh
  • 33. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza “let’s eatn” hi death huh
  • 34. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza “let’s eatn” hi death huh
  • 35. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi death huh
  • 36. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi “Nothing to don” death huh
  • 37. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi “Nothing to don” death huh
  • 38. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi death huh
  • 39. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi death “all done heren” huh
  • 40. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi death “all done heren” huh
  • 41. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi death huh
  • 42. HOW THAT WORKS process 1 process 2 spawn/3 pizza_death food_loop food_loop’s Mailbox pizza hi death huh
  • 43. HOW THAT WORKS process 1 spawn/3 pizza_death food_loop’s Mailbox pizza hi death huh
  • 44. HOW THAT WORKS process 1 spawn/3 pizza_death pizza hi death huh
  • 45. HOW THAT WORKS process 1 spawn/3 pizza_death pizza hi death
  • 46. BUT DOES IT SCALE? Hells yea! http://www.flickr.com/photos/24736216@N07/4808606178/
  • 47. TWO WAYS TO SCALE Name Implementation Horizontally Buy a lot of machines Vertically Buy a really big machine
  • 48. ERLANG SCALES WELL ON BOTH WITH NEARLY ZERO CODE CHANGE
  • 49. BOOM!
  • 50. VERTICAL SCALING • Your processes will take advantage of all cores available • Yay! No code changes required
  • 51. HORIZONTAL SCALING • New nodes added to the cluster can be auto-detected • Code must know that a service could live on another node • You’ll need resource discovery
  • 52. CONNECTING NODES $ erl -name b 1> AHost = 'a@awesome-town.local'. 'a@awesome-town.local' 2> io:fwrite("Current nodes: ~p~n", [nodes()]). Current nodes: [] 3> io:fwrite("Ping? ~p~n", [net_adm:ping(AHost)]). Ping? pong 4> io:fwrite("Current nodes: ~p~n", [nodes()]). Current nodes: ['a@awesome-town.local' 5> q().
  • 53. SERVER REFERENCES Type Definition <Pid> globally unique process identifier RegisteredName locally registered process process locally registered on {RegisteredName, Node} another node {global, GlobalName} globally registered process
  • 54. LISTEN FOR INCOMING MESSAGE listen() ->   register(listener, self()),   listen_loop(). listen_loop() ->   receive     {From, pizza} -> From ! "Nom noms", listen_loop();     {From, _} -> From ! "Boo!", listen_loop();     _ -> io:fwrite("Listen is dying!")   end.
  • 55. SENDING MESSAGE TO NODES $ erl -name b 1> AHost = 'a@awesome-town.local'. 'a@awesome-town.local' 2> {listener, AHost} ! {self(), pizza}. ok 3> receive PizzaResp -> PizzaResp end.
  • 56. RESOURCE DISCOVERY Method Purpose add_target_resource(Type) specify a resource type you want to use add_local_resource(Type, Pid) specify a resource type you have fetch_resources(Type) fetch all resources of specified type trade_resources() trade resource information See Chapter 8 of Erlang And OTP In Action
  • 57. HORIZONTAL CAVEATS • Passing large amounts of data between nodes is inefficient • Too many nodes will impact performance (Keep it < 100) • There are ways around both these problems
  • 58. OTP BASICS Cause managing all the processes by hand is dumb Thanks, Homer
  • 59. OTPWTFBBQ? • Open Telecom Platform • Abstracts common systems behavior (servers, supervisors, ...) • Easier than pure Erlang! • Gives Erlang its reputation for fault tolerance
  • 60. BASIC CONSTRUCTS Construct Purpose Encapsulates a large set of code Application meant to run as one unit. Supervisor Starts and restarts workers. Worker Actually does stuff
  • 61. HTTP://GITHUB.COM/MASHION/CHLOE Chloe (Application) chloe_sup (Supervisor) websocket_sup session_sup session_manager Other Stuffs (Supervisor) (Supervisor) (Worker)
  • 62. WORKERS • Use the `gen_server` behaviour (for the most part) • Contain your application logic • You define a module with callbacks • OTP runs a server calls back to module when messages arrive
  • 63. HOW WORKERS WORK client process (your code) gen_server functions gen_server code (part of OTP) gen_server callbacks worker code (your code) worker process
  • 64. SENDING MESSAGES TO WORKERS say_hello_sync(Name) ->   gen_server:call(?SERVER, {say_hello, Name}). say_hello_async() ->   gen_server:cast(?SERVER, say_hello). gen_server_examples.erl
  • 65. EXAMPLE CALLBACKS handle_call({say_hello, Name}, _From, State) ->   Response = string:concat("Hello, ", Name),   {reply, {ok, Response}, State}. handle_cast(say_hello, State) ->   io:fwrite("Hello world!n"),   {noreply, State}. gen_server_examples.erl
  • 66. WORKER CALLBACKS Callback Purpose init(Args) Initialize the server process handle_call(Request, From, State) Handle a synchronous call handle_cast(Request, State) Handle an asynchronous cast handle_info(Info, State) For timeouts and random messages terminate(Reason, State) Clean up the process when it dies code_change(OldVsn, State, Extra) Called when upgrading code
  • 67. WORKER FUNCTIONS Callback Purpose start_link(Module, Args, Options) Start a supervised worker start(Module, Args, Options) Start an unsupervised worker call(ServerRef, Request, Timeout) Synchronously call a worker cast(ServerRef, Request) Asynchronously cast to a worker man gen_server
  • 68. SUPERVISORS • Use the `supervisor` behaviour • Contain little to no application logic • Know how to start and restart failed workers • Keep your application from ever fully dying
  • 69. CHILD SPECS {Id, StartFunc, Restart, Shutdown, Type, Modules} Unique name used to identify child process.
  • 70. CHILD SPECS {session_manager, StartFunc, Restart, Shutdown, Type, Modules} Unique name used to identify child process.
  • 71. CHILD SPECS {session_manager, StartFunc, Restart, Shutdown, Type, Modules} Tuple {M, F, A} used to start the child.
  • 72. CHILD SPECS {session_manager, {session_manager, start_link, []}, Restart, Shutdown, Type, Modules} Tuple {M, F, A} used to start the child.
  • 73. CHILD SPECS {session_manager, {session_manager, start_link, []}, Restart, Shutdown, Type, Modules} Determines when a terminated process should be restarted.
  • 74. CHILD SPECS {session_manager, {session_manager, start_link, []}, permanent, Shutdown, Type, Modules} Determines when a terminated process should be restarted.
  • 75. CHILD SPECS {session_manager, {session_manager, start_link, []}, permanent, Shutdown, Type, Modules} Determines how to kill child processes.
  • 76. CHILD SPECS {session_manager, {session_manager, start_link, []}, permanent, 5000, Type, Modules} Determines how to kill child processes.
  • 77. CHILD SPECS {session_manager, {session_manager, start_link, []}, permanent, 5000, Type, Modules} Is this child a worker or a supervisor?
  • 78. CHILD SPECS {session_manager, {session_manager, start_link, []}, permanent, 5000, worker, Modules} Is this child a worker or a supervisor?
  • 79. CHILD SPECS {session_manager, {session_manager, start_link, []}, permanent, 5000, worker, Modules} Used by code reloading. Make it the same as the other module name.
  • 80. CHILD SPECS {session_manager, {session_manager, start_link, []}, permanent, 5000, worker, [session_manager]} Used by code reloading. Make it the same as the other module name.
  • 81. RESTART STRATEGIES Strategy When a child dies.... one_for_one restart it one_for_all restart all children restart it and all children after it rest_for_one in child list restart it (also allows you to simple_one_for_one dynamically add children)
  • 82. ONE_FOR_ONE Supervisor Child 1 Child 2 Child 3
  • 83. ONE_FOR_ONE Supervisor Child 2 Child 3
  • 84. ONE_FOR_ONE Supervisor Child 1 Child 2 Child 3
  • 85. ONE_FOR_ALL Supervisor Child 1 Child 2 Child 3
  • 86. ONE_FOR_ALL Supervisor Child 2 Child 3
  • 87. ONE_FOR_ALL Supervisor Child 3
  • 88. ONE_FOR_ALL Supervisor
  • 89. ONE_FOR_ALL Supervisor Child 1
  • 90. ONE_FOR_ALL Supervisor Child 1 Child 2
  • 91. ONE_FOR_ALL Supervisor Child 1 Child 2 Child 3
  • 92. REST_FOR_ONE Supervisor Child 1 Child 2 Child 3
  • 93. REST_FOR_ONE Supervisor Child 1 Child 3
  • 94. REST_FOR_ONE Supervisor Child 1
  • 95. REST_FOR_ONE Supervisor Child 1 Child 2
  • 96. REST_FOR_ONE Supervisor Child 1 Child 2 Child 3
  • 97. SIMPLE_ONE_FOR_ONE Supervisor
  • 98. SIMPLE_ONE_FOR_ONE Supervisor Child 1
  • 99. SIMPLE_ONE_FOR_ONE Supervisor Child 1 Child 2
  • 100. SIMPLE_ONE_FOR_ONE Supervisor Child 1 Child 2 Child 3
  • 101. SIMPLE_ONE_FOR_ONE Supervisor Child 2 Child 3
  • 102. SIMPLE_ONE_FOR_ONE Supervisor Child 1 Child 2 Child 3
  • 103. STARTING A SUPERVISOR init([]) ->   Worker = {gen_server_examples, {gen_server_examples, start_link, []},             permanent, 5000, worker, [gen_server_examples]},   RestartStrategy = {one_for_one, 5, 30},   {ok, {RestartStrategy, [Worker]}}.
  • 104. SUPERVISOR CALLBACK callback purpose return data structure telling what init(Args) to supervise
  • 105. SUPERVISOR FUNCTIONS Callback Purpose start_link(Module, Args) Start a supervised supervisor start_child(SupRef, ChildSpec) Start a child under the supervisor man supervisor
  • 106. FAULT TOLERANCE • When you hit an error, let the worker die • Supervisor will restart it • Either try what killed it again or move on • Life is grand
  • 108. THANK YOU! • Questions? • http://bit.ly/erlang-otp-gist • http://bit.ly/otp-book • http://mashion.net

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n