29
MAGICBE.AM

MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

Embed Size (px)

Citation preview

Page 1: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

MAGICBE.AM  

Page 2: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

HISTORICAL  CONTEXT    

Page 3: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

THE  COTWEET  SOCIAL  DATA  STORY  

• How  to  retrieve  users  social  data  ?  

•  First  incarnaBon  was  a  ruby  cronjob  

•  Second  incarnaBon  was  a  non-­‐OTP  Erlang  daemon  

– Nomura  was  born  

•  Current  incarnaBon  is  distributed  (via  RabbitMQ)  and  largely  OTP  

Page 4: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

WHAT  IS  A  NOMURA  

• A  very  large  jellyfish,  the  largest  cnidarian  in  the  world  

•   野村  “Field  Village”  

• A  distributed  plaTorm  for  providing  social  data  streams  throughout  the  ExactTarget  soWware  ecosystem  

•  Integrates  with  TwiXer  /  Facebook  /  Others  coming  soon  

• MulBple  components  including  scheduling,  api  workers  &  data  workers,  command  &  control  

Page 5: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

HOW  IS  WORKER  POOL  FORMED  

•  Three  key  requirements  

– Dynamically  adjust  pool  size  up  /  down  in  response  to  ever-­‐changing  circumstances  

– Faults  isolated  between  individual  requests  and  customers  

– TransacBonal  /  stateless  • All  our  workers  wrap  a  RabbitMQ  consumer  •  Find  a  supervisory  structure  that  fits  

Page 6: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

CHAOS  BEAMS    

Page 7: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

ENTER  THE  THUNDERDOME  

•  Took  a  cue  from  NeTlix  Chaos  Monkeys  

• How  beXer  to  test  supervisory  structures….  

• How  beXer  to  cause  mild  concern  in  the  QA  department….  

Page 8: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

THUNDERBEAM  IN  PRINCIPLE  

• Hey  what  happens  when  we  kill  off  random  Erlang  processes  

– They  are  supervised  right?  

•  Simulates  unexpected  funcBon  calls  and  inbound  messages  

– We  call  these  “typos”  

•  Fine  line  between  not  handling  common  errors  and  matching  all  the  catch  paXerns  

–  try  1  /  0  catch  _:_  -­‐>  ok  end.  

• Who  supervises  the  supervisors  applicaBon  masters  ?  

Page 9: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

THUNDERBEAM  IN  ACTION  

•  Tunable  Bming  of  process  death  

• Blacklist  of  registered  processes  or  OTP  applicaBons  to  not  kill  

– Mnesia  is  easily  upset  

•  gen_server  handle_info  handler  for  bespoke  trap_exit’d  processes  

• Ability  to  force-­‐kill  supervisors  and  non-­‐OTP  processes  

Page 10: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

HOT  LOADED  BEAMS  

Page 11: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

WAITING  IS  BORING  

• No  more  sword  fights  

– No  more  excuses  

• Reload  mod  on  beam  file  change  

– Nothing  new  here  

• Recompile  on  source  file  change  

– Finally  caught  up  to  PHP  

Page 12: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

HOTBEAM  IN  ACTION  

•  Extrapolate  source  locaBon  for  normal  beam  via  compile  aXribute  

•  Control  which  OTP  applicaBons  are  monitored  for  change  

•  SelecBvely  enable  /  disable  automagic  compilaBon  /  reloading  

• Manually  reload  single  module,  OTP  applicaBon  or  everything  

Page 13: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

HOTBEAM  IMPROVEMENTS  

•  Support  addiBonal  source  file  types  

• Monitor  header  files  and  recompile  dependent  source  files  

•  code_change  callbacks  to  support  run-­‐Bme  state  changes    

Page 14: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

REPL  FOR  ALL  

Page 15: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

WHO  DOESN’T  LIKE  RUNTIME  INTROSPECTION  

•  Habitual  implementaBon  of  info/0  funcBons  

–  Simpler  than  sys:get_status/1  

•  Cultural  tendency  towards  live  configuraBon  changes  

– Mea  Maxima  Culpa;  Over-­‐engineered  config  logic  

• Manual  control  of  running  systems  

– Not  every  buXon  gets  a  web  interface  

•  Friendlier  than  the  typical  Erlang  shell  

–  Less  dangerous  as  well  

Page 16: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

SHELLBEAM  IN  PRINCIPLE  

•  Simple  behavio(u)r  for  implemenBng  a  bespoke  and  easy  to  use  REPL  shell  

• AbstracBon  around  logic  with  run-­‐Bme  help  

• Hierarchical  sub-­‐shells  with  shortcut  access  

Page 17: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

SHELLBEAM  IN  ACTION  

• Basic  magicbeam/Erlang  funcBonality  as  default  callback  

• ApplicaBon  Environment  ediBng  subshell  part  of  default  callback    •  Passes  parsed  arguments  into  callback  implementaBon  funcBons  

•  Integrated  SSHD  support.  Handles  generaBon  of  host  keys.  

Page 18: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

SHELLBEAM  MODULE  SAMPLE  (APPENV)  

Page 19: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

SHELLBEAM  USAGE  SAMPLE  (APPENV)  

Page 20: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

MAGICBEAM  4  DEVOPS  

Page 21: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

MAGICBEAM  SUMMARY  

•  Catch-­‐all  project  for  devops-­‐y  bits  which  we’ve  found  useful  

•  Comprised  of  three  key  pieces  of  funcBonality  

–  thunderbeam  – hotbeam  – shellbeam  

• Designed  with  ease  of  integraBon  in  mind  

Page 22: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

MAGICBEAM  INTEGRATION  

• Available  as  rebar  dependency.  May  be  included  in  release  as  permanent,  temporary  or  load-­‐only  applicaBon  

•  Inject  into  already  running  node.  Note  that  this  enables  the  use  of  magicbeam  in  already-­‐deployed  environments  

•  Project-­‐specific  configuraBon  and  event  handling  via  implementaBon  of  magicbeam  behavior  

Page 23: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

USE  CASES  

Page 24: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

DEPLOYMENT  

• Determine  which  applicaBons  you  wish  to  reload  on  the  fly  

– All  bespoke  code    •  Create  an  initscript  hook  for  hotbeam:all()  

– project_ctl  

•  Integrate  into  deployment  pipeline  

– Choice  between  restart  /  hotload  

Page 25: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

EXTREME  PAIR  PROGRAMMING  

•  Two  developers,  one  editor,  one  running  release  

– Hotbeam  reloads  code  on  save  

• RobusBfy  soWware  as  it’s  being  created  

– Thunderbeam  does  it’s  thing  

•  Tweak  runBme  parameters  to  test  all  facets  

– Shellbeam  shortcuts  for  config  and  such  

Page 26: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

OPS  SUPPORT  

• Ops  isn’t  going  to  learn  Erlang  

– Yet  sBll  needs  to  tweak  knobs  and  pull  levers  

•  Shellbeam  implementaBons  for  common  operaBons  

– ConfiguraBon  &  Scaling  &  Metrics  Oh  My  – Distributed  component  control  

• Direct  SSH  access  

– Remove  OS  distracBons  

Page 27: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

ERRATA  

Page 28: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

ERRATA  

•  SSH  access  only  supports  one  private  key  

• Magicbeam  injecBon  requires  compaBble  bytecode  

• Hotbeam  does  not/will  never  support  upgrading  Erlang  VM  

Page 29: MAGICBE.AM) - erlang-factory.com · Erlang)daemon) – Nomurawas)born) ... ERRATA • SSHaccess)only ... MAGICBE.AM) Author: Jonathan Freedman Created Date: 4/24/2012 7:35:40 PM

FIN  JONATHAN  FREEDMAN  

MAGICBE.AM