Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Distributed Elixir
Search
Maciej Kaszubowski
July 07, 2018
Programming
0
100
Distributed Elixir
Presentation about some of the tools for distributed programming in Elixir
Maciej Kaszubowski
July 07, 2018
Tweet
Share
More Decks by Maciej Kaszubowski
See All by Maciej Kaszubowski
Error-free Elixir
mkaszubowski
0
260
Modular Design in Elixir (ElixirConf EU 2019)
mkaszubowski
2
560
The Big Ball of Nouns
mkaszubowski
0
86
Modular Design in Elixir
mkaszubowski
1
340
Our three years with Elixir
mkaszubowski
0
190
Concurrency Basics for Elixir
mkaszubowski
0
98
Software Architecture
mkaszubowski
0
110
Let it crash - fault tolerance in Elixir/OTP
mkaszubowski
0
380
CRDTs - The science behind Phoenix Presence
mkaszubowski
2
240
Other Decks in Programming
See All in Programming
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
2
120
testcontainers のススメ
sgash708
1
120
useSyncExternalStoreを使いまくる
ssssota
6
1.2k
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
340
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
103 Early Hints
sugi_0000
1
240
命名をリントする
chiroruxx
1
420
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
430
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
490
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
150
Featured
See All Featured
How GitHub (no longer) Works
holman
311
140k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Facilitating Awesome Meetings
lara
50
6.1k
A Philosophy of Restraint
colly
203
16k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Writing Fast Ruby
sferik
628
61k
Documentation Writing (for coders)
carmenintech
66
4.5k
Transcript
It’s scary out there
Organisational Matters
None
We’re 1 year old!
Summer break (probably)
We’re looking for speakers!
It’s scary out there Distributed Systems in Elixir Poznań Elixir
Meetup #8
None
Pid 1 Pid 2
Pid 1 Pid 2 Node A Node B
The basics
iex --name
[email protected]
--cookie cookie -S mix
Node.connect(:’
[email protected]
')
(DEMO)
#PID<0.94.0>
#PID<0.94.0> node identifier (relative to current node)
#PID<0.94.0> node identifier (relative to current node) 0 =a local
process
#PID<0.94.0> Process id node identifier (relative to current node)
How does it work?
Pid 1 Node A Pid 2 Node B
Pid 1 Node A Pid 2 Node B TCP Connection
send(pid2, msg) Pid 1 Node A Pid 2 Node B
TCP Connection
send(pid2, msg) Pid 1 Node A Pid 2 Node B
destination_node = node(pid) TCP Connection
send(pid2, msg) Pid 1 Node A Pid 2 Node B
destination_node = node(pid) :erlang.term_to_binary(msg) TCP Connection
send(pid2, msg) Pid 1 Node A Pid 2 Node B
destination_node = node(pid) :erlang.term_to_binary(msg) TCP Connection
send(pid2, msg) Pid 1 Node A Pid 2 Node B
destination_node = node(pid) :erlang.term_to_binary(msg) TCP Connection :erlang.binary_to_term(encode)
send(pid2, msg) Pid 1 Node A receive msg Pid 2
Node B destination_node = node(pid) :erlang.term_to_binary(msg) TCP Connection :erlang.binary_to_term(encode)
Distributed Systems?
Distributed Systems? Solved!
Well, not exactly…
Difficulties
Node A Node B
Node A Node B Node C
Node A Node B Node C Node D
None
A lot of messages
us-east-1 us-west-2
8 fallacies of distributed computing
fallacies of distributed computing 1. The network is reliable 2.
Latency is zero 3. Bandwidth is infinite 4. The network is secure 5. Topology doesn’t change 6. The is one administrator 7. Transport cost is zero 8. The network is homogenous
CAP THEOREM
CAP THEOREM us-west-2 us-east-1
CAP THEOREM us-west-2 us-east-1 Set X=5
CAP THEOREM us-west-2 us-east-1 Set X=5 Read X
CAP THEOREM us-west-2 us-east-1 Set X=5 Set X = 7
Consistency or Availability (under network partition)
Consistency or Speed In practice
Guarantees
Pid 1 Pid 2 Pid3 Guarantees m1, m2, m3 m4,
m5, m6 send(pid2, m1) send(pid2, m2) send(pid2, m3) send(pid2, m4) send(pid2, m5) send(pid2, m6)
Pid 1 Pid 2 Pid3 Guarantees m1, m2, m3 m4,
m5, m6 send(pid2, m1) send(pid2, m2) send(pid2, m3) send(pid2, m4) send(pid2, m5) send(pid2, m6) Ordering between two processes is preserved
Pid 1 Pid 2 Pid3 Guarantees m4, m5, m6 send(pid2,
m1) send(pid2, m2) send(pid2, m3) send(pid2, m4) send(pid2, m5) send(pid2, m6) m1, m2, m3 Delivery is not guaranteed
Pid 1 Pid 2 Pid3 Guarantees m1, m2, m3 m4,
m5, m6 send(pid2, m1) send(pid2, m2) send(pid2, m3) send(pid2, m4) send(pid2, m5) send(pid2, m6) Ordering between different processes is not guaranteed
[m1, m2, m3, m4, m5, m6]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6] [m1, m2, m3]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6] [m1, m2, m3] [m1, m3, m5, m6]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6] [m1, m2, m3] [m1, m3, m5, m6] []
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6] [m1, m2, m3] [m1, m3, m5, m6] [] [m1, m3, m2, m4, m5, m6]
[m1, m2, m3, m4, m5, m6] [m4, m5, m6, m1,
m2, m3] [m1, m4, m2, m5, m3, m6] [m1, m2, m3] [m1, m3, m5, m6] [] [m1, m3, m2, m4, m5, m6] [M3, M3]
Phoenix Request A User Logged In
Phoenix Request A Phoenix Request B User Logged In User
Logged OUT
Phoenix Request A Phoenix Request B User Logged In User
Logged OUT This Can arrive first
Unfortunately, things tend to work fine locally
The Tools
:global
Pid 1 Node A Node B Pid 2
Pid 1 Node A Node B Pid 2 :global.register_name(“global”, self())
Pid 1 Node A Node B Pid 2 :global.register_name(“global”, self())
Register PId1 as “global”
Pid 1 Node A Node B Pid 2 :global.register_name(“global”, self())
Register PId1 as “global” Sure
Pid 1 Node A Node B Pid 2 :global.register_name(“global”, self())
Register PId1 as “global” Sure :global.whereis_name(“global”) = pid1
Pid 1 Node A Node B Pid 2 :global.register_name(“global”, self())
:global.register_name(“global”, self()) ?
(DEMO)
:global • single process registration (if everything works OK) •
Favours availability over consistency • Information stored locally (reading is fast) • Registration is blocking (may be slow)
:PG2
Pid1 Pid3 Pid2 [] [] []
Pid1 Pid3 Pid2 :pg2.create(“my_group”) [] [] []
Pid1 Pid3 Pid2 [] [] [] join join :pg2.join(“my_group”, self()
Pid1 Pid3 Pid2 [] [pid1] [] Monitor Monitor :pg2.join(“my_group”, self()
Pid1 Pid3 Pid2 [pid1] [pid1] [pid1] Monitor Monitor :pg2.join(“my_group”, self()
Pid1 Pid3 Pid2 [pid1] [pid1] [pid1]
Pid1 Pid3 Pid2 :pg2.join(“my_group”, self() [pid1] [pid1, pid2] [pid1]
Pid1 Pid3 Pid2 join :pg2.join(“my_group”, self() join [pid1, pid2] [pid1,
pid2] [pid1, pid2]
Pid1 Pid3 Pid2 [pid1] [pid2] [pid1]
Pid1 Pid3 Pid2 [pid1] [pid2] [pid1]
Pid1 Pid3 Pid2 [pid1] [pid2] [pid1]
Pid1 Pid3 Pid2 [pid1, pid2] [pid1, pid2] [pid1, pid2]
It will heal, but the state in inconsistent for some
time
What does it matter?
Node A Pg2 Pg2 Pg2 Node B Node C
Node A Pg2 Pg2 Pg2 Node B Node C Phoenix
Channels
Node A Pg2 Pg2 Pg2 Node B Node C Phoenix
Presence
Node A Pg2 Pg2 Pg2 Node B Node C Phoenix
Channels
:pg2 • Process groups • Favours availability over consistency •
Information stored locally (reading is fast) • Registration is blocking (may be slow)
Strongly consistent Solutions
Strongly consistent Solutions • Consensus - Raft, Paxos, ZAB •
Two-phase commit/THree-phase commit (2PC/3PC) • Read/Write quorums • Single database as a source of truth
Summary
Distributed Systems
Well, not exactly…
Asynchronous messages Distributed systems are all about
Really, there’s no magic
Just asynchronous messages between nodes
Just asynchronous messages between nodes & node failures
Just asynchronous messages between nodes & node failures & Communication
failures
Just asynchronous messages between nodes & node failures & Communication
failures & Network partitions
Tradeoffs Distributed systems are all about
Where to go next
Worth looking at • Riak_core • RAFT • Two-Phase Commit
(2PC) / Three-Phase Commit (3PC) • CRDTs • LASP and Partisan
Free online (click!) Elixir / Erlang
Free PDF (Click!) Distributed Systems
Theory (The hard stuff)
• https://raft.github.io/ (Raft Consensus) • http://learnyousomeerlang.com/distribunomicon • https://www.rgoarchitects.com/Files/fallacies.pdf (Fallacies of
distributed computing) • https://dzone.com/articles/better-explaining-cap-theorem (CAP Theorem) • https://medium.com/learn-elixir/message-order-and-delivery-guarantees-in-elixir- erlang-9350a3ea7541 (Elixir message delivery guarantees) • https://lasp-lang.readme.io/ (LASP) • https://arxiv.org/pdf/1802.02652.pdf (Partisan Paper) • https://bravenewgeek.com/tag/three-phase-commit/ (3PC)
We’re looking for speakers!
Thank You! Poznań Elixir Meetup #8