Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elixir: Under the Hood

Elixir: Under the Hood

サブタイトル: Elixir を支える技術 -「落ちない」システムの秘密に迫る。

スライドと台本はこちらのブログで解説しています。
https://qiita.com/ishikawa@github/items/3d054f3d29920107687f

Takanori Ishikawa

August 31, 2019
Tweet

More Decks by Takanori Ishikawa

Other Decks in Programming

Transcript

  1. Copyright © ABEJA, Inc. All rights reserved. Elixir: Under the

    Hood Elixir を⽀える技術 -「落ちない」システムの秘密に迫る
  2. Copyright © ABEJA, Inc. All rights reserved. • @takanori_is •

    Takanori Ishikawa • ABEJA, inc. • Ex) mixi, Drecom • Developer in ABEJA Platform • ❤ Elixir and • https://github.com/ishikawa • Born in 愛媛県松⼭市
  3. Copyright © ABEJA, Inc. All rights reserved. Summary • Erlang

    & Elixir design and principal • Systems that run forever • BEAM internal • Optimizations for BEAM
  4. Copyright © ABEJA, Inc. All rights reserved. History of Erlang

    • 1982 - 1985: Experiments using > 20 different languages • 1985 - 86: Experiments with Lisp,Prolog, Parlog • 1987: Erlang • 1993: Distribution • 1998: Open Sourced
  5. Copyright © ABEJA, Inc. All rights reserved. Elixir Design Goals

    • Compatibility • the Erlang VM is Elixir’s strongest asset • Productivity • Extensibility
  6. Copyright © ABEJA, Inc. All rights reserved. Systems run forever

    • Process Isolation • Fault tolerance • Self healing
  7. Copyright © ABEJA, Inc. All rights reserved. The Erlang Virtual

    Machine: BEAM • BEAM (Bogumil’s/Björn’s Abstract Machine) • garbage collecting • reduction counting • non-preemptive • Interpreter loop: directly threaded • register machine
  8. Copyright © ABEJA, Inc. All rights reserved. Process • Heap

    • Stack • Mailbox • PCB (Process Control Block)
  9. Copyright © ABEJA, Inc. All rights reserved. https://hamidreza-s.github.io/erlang/scheduling/real-time/preemptive/migration/2016/02/09/erlang-scheduler- details.html Erlang

    VM +--------------------------------------------------------+ | | | +-----------------+-----------------+ | | | | | | | | Scheduler # 1 | Run Queue # 1 <--+ | | | | | | | | +-----------------+-----------------+ | | | | | | +-----------------+-----------------+ | | | | | | | | | | Scheduler # 2 | Run Queue # 2 <----> Migration | | | | | | Logic | | +-----------------+-----------------+ | | | | | | +-----------------+-----------------+ | | | | | | | | | | Scheduler # N | Run Queue # N <--+ | | | | | | | +-----------------+-----------------+ | | | +--------------------------------------------------------+
  10. Copyright © ABEJA, Inc. All rights reserved. HiPE • High

    Performance Erlang • Native code compiler for Erlang • Including LLVM backend • Compiles individual Erlang functions
  11. Copyright © ABEJA, Inc. All rights reserved. BEAMJIT • Since

    2014 • Tracing JIT • LLVM backend • Future: • BEAM registers to machine registers • Cross trace optimizations
  12. Copyright © ABEJA, Inc. All rights reserved. BEAM improvements •

    Interpreter Overhaul • Instruction size reduced • New IR: SSA based
  13. Copyright © ABEJA, Inc. All rights reserved. SSA • SSA

    (Static Single Assignment) • Each variable is assigned exactly once, • and every variable is defined before it is used. • @variable:5 • Simplifies compiler optimizations
  14. Copyright © ABEJA, Inc. All rights reserved. Summary • Erlang

    & Elixir design and principal • Systems that run forever • BEAM internal • Optimizations for BEAM