Elixir: Under the Hood

Elixir: Under the Hood

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

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

4102ada9d9eee5a4a299937da214d051?s=128

Takanori Ishikawa

August 31, 2019
Tweet

Transcript

  1. Elixir を⽀える技術 -「落ちない」システムの秘密に迫る Elixir: Under the Hood Takanori Ishikawa /

    builderscon tokyo 2019
  2. Copyright © ABEJA, Inc. All rights reserved. Elixir: Under the

    Hood Elixir を⽀える技術 -「落ちない」システムの秘密に迫る
  3. 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 愛媛県松⼭市
  4. Copyright © ABEJA, Inc. All rights reserved. Summary • Erlang

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

  6. 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
  7. Copyright © ABEJA, Inc. All rights reserved.

  8. Copyright © ABEJA, Inc. All rights reserved. https://medium.com/elixirlabs/anatomy-of-an-elixir-process-878030c37166

  9. Copyright © ABEJA, Inc. All rights reserved.

  10. Copyright © ABEJA, Inc. All rights reserved. Elixir

  11. Copyright © ABEJA, Inc. All rights reserved. Elixir Design Goals

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

  13. Copyright © ABEJA, Inc. All rights reserved.

  14. Copyright © ABEJA, Inc. All rights reserved.

  15. Copyright © ABEJA, Inc. All rights reserved.

  16. Copyright © ABEJA, Inc. All rights reserved.

  17. Copyright © ABEJA, Inc. All rights reserved. https://blog.stenmans.org/theBeamBook/#ERTS

  18. Copyright © ABEJA, Inc. All rights reserved. 「落ちないシステム」

  19. Copyright © ABEJA, Inc. All rights reserved. 「100% バグがないシステムを 作れば落ちない!」

  20. Copyright © ABEJA, Inc. All rights reserved. Systems run forever

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

    Machine: BEAM
  22. Copyright © ABEJA, Inc. All rights reserved.

  23. Copyright © ABEJA, Inc. All rights reserved.

  24. 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
  25. Copyright © ABEJA, Inc. All rights reserved.

  26. Copyright © ABEJA, Inc. All rights reserved.

  27. Copyright © ABEJA, Inc. All rights reserved. Process • Heap

    • Stack • Mailbox • PCB (Process Control Block)
  28. 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 <--+ | | | | | | | +-----------------+-----------------+ | | | +--------------------------------------------------------+
  29. Copyright © ABEJA, Inc. All rights reserved. https://www.erlang-solutions.com/blog/erlang-garbage-collector.html

  30. Copyright © ABEJA, Inc. All rights reserved. Optimization

  31. Copyright © ABEJA, Inc. All rights reserved. HiPE • High

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

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

    Interpreter Overhaul • Instruction size reduced • New IR: SSA based
  34. 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
  35. Copyright © ABEJA, Inc. All rights reserved.

  36. Copyright © ABEJA, Inc. All rights reserved.

  37. Copyright © ABEJA, Inc. All rights reserved. Conclusion

  38. Copyright © ABEJA, Inc. All rights reserved. Summary • Erlang

    & Elixir design and principal • Systems that run forever • BEAM internal • Optimizations for BEAM
  39. Copyright © ABEJA, Inc. All rights reserved. Thanks!