167

Magic Clusters and Where to Find Them - Eugene Pirogov

Embed Size (px)

Citation preview

Page 1: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 2: Magic Clusters and Where to Find Them - Eugene Pirogov

Clustersand where to find

them

Page 3: Magic Clusters and Where to Find Them - Eugene Pirogov

Eugene Pirogovgmile

Page 4: Magic Clusters and Where to Find Them - Eugene Pirogov

Nebo15Were hiring!

Page 5: Magic Clusters and Where to Find Them - Eugene Pirogov

DatabasesTools

Theory

Takeaways

Page 6: Magic Clusters and Where to Find Them - Eugene Pirogov

DatabasesTools

Theory

Takeaways

Page 7: Magic Clusters and Where to Find Them - Eugene Pirogov

What isa cluster?

Page 8: Magic Clusters and Where to Find Them - Eugene Pirogov

set of loosely or tightly connected computers that work

together so that, in many respects, they can be viewed as

a single system

Page 9: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 10: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 11: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 12: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 13: Magic Clusters and Where to Find Them - Eugene Pirogov

When to usea cluster?

Page 14: Magic Clusters and Where to Find Them - Eugene Pirogov

1. Fail-overclusters

Page 15: Magic Clusters and Where to Find Them - Eugene Pirogov

2. Load balancingclusters

Page 16: Magic Clusters and Where to Find Them - Eugene Pirogov

What typicalErlang clusteris built with?

Page 17: Magic Clusters and Where to Find Them - Eugene Pirogov

1. A node

Page 18: Magic Clusters and Where to Find Them - Eugene Pirogov

node()

Page 19: Magic Clusters and Where to Find Them - Eugene Pirogov

2. An RPC call

Page 20: Magic Clusters and Where to Find Them - Eugene Pirogov

:rpc.call(:nodex, M, :f, [“a”])

Page 21: Magic Clusters and Where to Find Them - Eugene Pirogov

3. send call

Page 22: Magic Clusters and Where to Find Them - Eugene Pirogov

send({MyProcess, :mynode}, :msg)

Page 23: Magic Clusters and Where to Find Them - Eugene Pirogov

Example 1:Starting a node

Page 24: Magic Clusters and Where to Find Them - Eugene Pirogov

iex

Page 25: Magic Clusters and Where to Find Them - Eugene Pirogov

~> iexErlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)iex(1)> node():nonode@nohostiex(2)>

Page 26: Magic Clusters and Where to Find Them - Eugene Pirogov

iex --name eugene

Page 27: Magic Clusters and Where to Find Them - Eugene Pirogov

~> iex --name eugeneErlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)iex([email protected])1>

Page 28: Magic Clusters and Where to Find Them - Eugene Pirogov

iex --sname eugene

Page 29: Magic Clusters and Where to Find Them - Eugene Pirogov

~> iex --sname eugeneErlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)iex(eugene@Eugenes-MacBook-Pro-2)1>

Page 30: Magic Clusters and Where to Find Them - Eugene Pirogov

iex --name eugene@host

Page 31: Magic Clusters and Where to Find Them - Eugene Pirogov

~> iex --name eugene@hostErlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)iex(eugene@host)1>

Page 32: Magic Clusters and Where to Find Them - Eugene Pirogov

Example 2:starting two nodes

Page 33: Magic Clusters and Where to Find Them - Eugene Pirogov

iex --name [email protected] --name [email protected]

Page 34: Magic Clusters and Where to Find Them - Eugene Pirogov

~> iex --name [email protected]([email protected])1>

~> iex --name [email protected]([email protected])1>

# On node1iex(1)> :net_adm.ping(:’[email protected]’):pong

Page 35: Magic Clusters and Where to Find Them - Eugene Pirogov

Example 3:sending a message

Page 36: Magic Clusters and Where to Find Them - Eugene Pirogov

iex --name node1iex --name node2

Page 37: Magic Clusters and Where to Find Them - Eugene Pirogov

# On node2iex(1)> Process.register(Terminal, self())

# On node1iex(1)> send({Terminal, :’[email protected]’}, “Hello!”)

# On node2iex(2)> flush()“Hello!”

Page 38: Magic Clusters and Where to Find Them - Eugene Pirogov

Example 4:calling remotely

Page 39: Magic Clusters and Where to Find Them - Eugene Pirogov

# On node1iex([email protected])1> :rpc.call(:'[email protected]', Enum, :reverse, [100..1])[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, …]iex([email protected])2>

Page 40: Magic Clusters and Where to Find Them - Eugene Pirogov

REST/JSON/XMLBinary protocol

Page 41: Magic Clusters and Where to Find Them - Eugene Pirogov

REST/JSON/XMLBinary protocol

Page 42: Magic Clusters and Where to Find Them - Eugene Pirogov

REST/JSON/XMLBinary protocol

Page 43: Magic Clusters and Where to Find Them - Eugene Pirogov

Bonus track:Magic cookie!

Page 44: Magic Clusters and Where to Find Them - Eugene Pirogov

cat ~/.erlang.cookie

Page 45: Magic Clusters and Where to Find Them - Eugene Pirogov

iex --name node1 --cookie abciex --name node2 --cookie xyz

Page 46: Magic Clusters and Where to Find Them - Eugene Pirogov

# On node1iex(1)> :erlang.get_cookie():abc

# On node2iex(1)> :erlang.get_cookie():xyz

# On node1iex(2)> :net_kernel.connect(:'[email protected]')false

# On node1iex(3)> :erlang.set_cookie(:’[email protected]’, :xyz)true

# On node1iex(4)> :net_kernel.connect(:'[email protected]')true

Page 47: Magic Clusters and Where to Find Them - Eugene Pirogov

DatabasesTools

Theory

Takeaways

Page 48: Magic Clusters and Where to Find Them - Eugene Pirogov

epmd

Page 49: Magic Clusters and Where to Find Them - Eugene Pirogov

Erlang PortMapper Daemon

Page 50: Magic Clusters and Where to Find Them - Eugene Pirogov

runs on system startup

Page 51: Magic Clusters and Where to Find Them - Eugene Pirogov

~> ps ax | grep epmd25502 ?? S 0:11.53 /usr/local/Cellar/erlang/19.1/lib/erlang/erts-8.1/bin/epmd -daemon

Page 52: Magic Clusters and Where to Find Them - Eugene Pirogov

maps portsto node names

Page 53: Magic Clusters and Where to Find Them - Eugene Pirogov

net_kernel

Page 54: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 55: Magic Clusters and Where to Find Them - Eugene Pirogov

Example 5:starting a

distributed node

Page 56: Magic Clusters and Where to Find Them - Eugene Pirogov

iex

Page 57: Magic Clusters and Where to Find Them - Eugene Pirogov

~> iexErlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)iex(1)>

Page 58: Magic Clusters and Where to Find Them - Eugene Pirogov

~> iexErlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)iex(1)> node():nonode@nohostiex(2)>

Page 59: Magic Clusters and Where to Find Them - Eugene Pirogov

~> iexErlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)iex(1)> node():nonode@nohostiex(2)> Process.registered() |> Enum.find(&(&1 == :net_kernel))nil

Page 60: Magic Clusters and Where to Find Them - Eugene Pirogov

~> iexErlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)iex(1)> node():nonode@nohostiex(2)> Process.registered() |> Enum.find(&(&1 == :net_kernel))niliex(3)> :net_kernel.start([:’[email protected]’]){:ok, #PID<0.84.0>}iex([email protected])4>

Page 61: Magic Clusters and Where to Find Them - Eugene Pirogov

~> iexErlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)iex(1)> node():nonode@nohostiex(2)> Process.registered() |> Enum.find(&(&1 == :net_kernel))niliex(3)> :net_kernel.start([:’[email protected]’]){:ok, #PID<0.84.0>}iex([email protected])4> Process.registered() |> Enum.find(&(&1 == :net_kernel)):net_kernel

Page 62: Magic Clusters and Where to Find Them - Eugene Pirogov

Example 6:monitoring a

node

Page 63: Magic Clusters and Where to Find Them - Eugene Pirogov

iex --name [email protected] --name [email protected]

Page 64: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

Page 65: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

iex([email protected])2> :net_kernel.monitor_nodes(true):ok

Page 66: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

iex([email protected])2> :net_kernel.monitor_nodes(true):ok

iex([email protected])3> :net_kernel.connect(:'[email protected]')true

Page 67: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

iex([email protected])2> :net_kernel.monitor_nodes(true):ok

iex([email protected])3> :net_kernel.connect(:'[email protected]')true

iex([email protected])4> flush(){:nodeup, :"[email protected]"}:ok

Page 68: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

iex([email protected])2> :net_kernel.monitor_nodes(true):ok

iex([email protected])3> :net_kernel.connect(:'[email protected]')true

iex([email protected])4> flush(){:nodeup, :"[email protected]"}:ok

# Ctrl+C on node2

Page 69: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

iex([email protected])2> :net_kernel.monitor_nodes(true):ok

iex([email protected])3> :net_kernel.connect(:'[email protected]')true

iex([email protected])4> flush(){:nodeup, :"[email protected]"}:ok

# Ctrl+C on node2

iex([email protected])5> flush(){:nodedown, :"[email protected]"}:ok

iex([email protected])5>

Page 70: Magic Clusters and Where to Find Them - Eugene Pirogov

net_adm

Page 71: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 72: Magic Clusters and Where to Find Them - Eugene Pirogov

Example 7:ping

Page 73: Magic Clusters and Where to Find Them - Eugene Pirogov

iex --name [email protected] --name [email protected]

Page 74: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

Page 75: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

iex([email protected])2> :net_adm.ping(:'[email protected]')pang

Page 76: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

iex([email protected])2> :net_adm.ping(:'[email protected]')pang

iex([email protected])2> :net_adm.ping(:'[email protected]')pong

Page 77: Magic Clusters and Where to Find Them - Eugene Pirogov

Example 8:names

Page 78: Magic Clusters and Where to Find Them - Eugene Pirogov

iex --name [email protected] --name [email protected]

Page 79: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

Page 80: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

iex([email protected])2> :net_adm.names(){:ok, [{'rabbit', 25672}, {'node1', 51813}, {'node2', 51815}]}

iex([email protected])3>

Page 81: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

iex([email protected])2> :net_adm.names(){:ok, [{'rabbit', 25672}, {'node1', 51813}, {'node2', 51815}]}

iex([email protected])3> Node.list()[]

iex([email protected])4>

Page 82: Magic Clusters and Where to Find Them - Eugene Pirogov

Example 9:world

Page 83: Magic Clusters and Where to Find Them - Eugene Pirogov

# /etc/hosts127.0.0.1 host1.com127.0.0.1 host2.com127.0.0.1 host3.com

Page 84: Magic Clusters and Where to Find Them - Eugene Pirogov

# /Users/gmile/.hosts.erlanghost1.com.host2.com.host3.com.

Page 86: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1>

Page 88: Magic Clusters and Where to Find Them - Eugene Pirogov

Bonus track:Connecting

to a node running in production

Page 89: Magic Clusters and Where to Find Them - Eugene Pirogov

iex --name [email protected] --cookie abc

Page 90: Magic Clusters and Where to Find Them - Eugene Pirogov

$ iex --remsh [email protected] --cookie abc --name bar@localhostErlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)iex([email protected])1>

Page 91: Magic Clusters and Where to Find Them - Eugene Pirogov

slave

Page 92: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 93: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 94: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 95: Magic Clusters and Where to Find Them - Eugene Pirogov

3. Transfer configurationto slave nodes

2. Add code path to slave nodes

4. Ensure appsare started on slave

1. Start slave

Page 96: Magic Clusters and Where to Find Them - Eugene Pirogov

What else?

Page 97: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 98: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 99: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 100: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 101: Magic Clusters and Where to Find Them - Eugene Pirogov

Node

Page 102: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 103: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 104: Magic Clusters and Where to Find Them - Eugene Pirogov

phoenixframework/firenest

Page 105: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 106: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 107: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 108: Magic Clusters and Where to Find Them - Eugene Pirogov

bitwalker/swarm

Page 109: Magic Clusters and Where to Find Them - Eugene Pirogov

Easy clustering, registration, and distribution of worker processes for

Erlang/Elixir

Page 110: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 111: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 112: Magic Clusters and Where to Find Them - Eugene Pirogov

…a simple case where workers are dynamically created in response to some events under a supervisor, and

we want them to be distributed across the cluster and be discoverable by name from anywhere in the cluster

Page 113: Magic Clusters and Where to Find Them - Eugene Pirogov

bitwalker/libcluster

Page 114: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 115: Magic Clusters and Where to Find Them - Eugene Pirogov

What next?

Page 116: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 117: Magic Clusters and Where to Find Them - Eugene Pirogov

…I didn’t want to resort to something like Docker,

because I wanted to see how far I could push Elixir and its

tooling.

Page 118: Magic Clusters and Where to Find Them - Eugene Pirogov

DatabasesTools

Theory

Takeaways

Page 119: Magic Clusters and Where to Find Them - Eugene Pirogov

mnesia

Page 120: Magic Clusters and Where to Find Them - Eugene Pirogov

Example 10:initialize mnesia

Page 121: Magic Clusters and Where to Find Them - Eugene Pirogov

iex --name [email protected] --name [email protected] --name [email protected]

Page 122: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1> :mnesia.create_schema([:'[email protected]']):ok

Page 123: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1> :mnesia.create_schema([:'[email protected]']):okiex([email protected])2> :mnesia.start():ok

Page 124: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1> :mnesia.create_schema([:'[email protected]']):okiex([email protected])2> :mnesia.start():okiex([email protected])3> :mnesia.info()---> Processes holding locks <------> Processes waiting for locks <------> Participant transactions <------> Coordinator transactions <------> Uncertain transactions <------> Active tables <---schema : with 1 records occupying 413 words of mem===> System info in version "4.14.1", debug level = none <===opt_disc. Directory "/Users/gmile/[email protected]" is used.use fallback at restart = falserunning db nodes = ['[email protected]']stopped db nodes = []master node tables = []remote = []ram_copies = []disc_copies = [schema]disc_only_copies = [][{'[email protected]',disc_copies}] = [schema]2 transactions committed, 0 aborted, 0 restarted, 0 logged to disc0 held locks, 0 in queue; 0 local transactions, 0 remote0 transactions waits for other nodes: []:okiex([email protected])4>

Page 125: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])1> :mnesia.create_schema([:'[email protected]']):okiex([email protected])2> :mnesia.start():okiex([email protected])3> :mnesia.info()---> Processes holding locks <------> Processes waiting for locks <------> Participant transactions <------> Coordinator transactions <------> Uncertain transactions <------> Active tables <---schema : with 1 records occupying 413 words of mem===> System info in version "4.14.1", debug level = none <===opt_disc. Directory "/Users/gmile/[email protected]" is used.use fallback at restart = falserunning db nodes = ['[email protected]']stopped db nodes = []master node tables = []remote = []ram_copies = []disc_copies = [schema]disc_only_copies = [][{'[email protected]',disc_copies}] = [schema]2 transactions committed, 0 aborted, 0 restarted, 0 logged to disc0 held locks, 0 in queue; 0 local transactions, 0 remote0 transactions waits for other nodes: []:okiex([email protected])4>

“schema” table existsas a disk_copy (RAM + disk)

on [email protected]

Page 126: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])2> :mnesia.start():ok

Page 127: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])2> :mnesia.start():ok

iex([email protected])2> :mnesia.start():ok

Page 128: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])2> :mnesia.start():ok

iex([email protected])2> :mnesia.start():ok

iex([email protected])2> :mnesia.change_config(:extra_db_nodes, [:’[email protected]’]){:ok, [:"[email protected]"]}

Page 129: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])2> :mnesia.start():ok

iex([email protected])2> :mnesia.start():ok

iex([email protected])2> :mnesia.change_config(:extra_db_nodes, [:’[email protected]’]){:ok, [:"[email protected]"]}

iex([email protected])3> :mnesia.change_config(:extra_db_nodes, [:’[email protected]’]){:ok, [:"[email protected]"]}

Page 130: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])2> :mnesia.start():ok

iex([email protected])2> :mnesia.start():ok

iex([email protected])2> :mnesia.change_config(:extra_db_nodes, [:’[email protected]’]){:ok, [:"[email protected]"]}

iex([email protected])3> :mnesia.change_config(:extra_db_nodes, [:’[email protected]’]){:ok, [:"[email protected]"]}

iex([email protected])1> :mnesia.create_table(:books, [disc_copies: [:'[email protected]'], attributes: [:id, :title, :year]]):ok

Page 131: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])2> :mnesia.start():ok

iex([email protected])2> :mnesia.start():ok

iex([email protected])2> :mnesia.change_config(:extra_db_nodes, [:’[email protected]’]){:ok, [:"[email protected]"]}

iex([email protected])3> :mnesia.change_config(:extra_db_nodes, [:’[email protected]’]){:ok, [:"[email protected]"]}

iex([email protected])1> :mnesia.create_table(:books, [disc_copies: [:'[email protected]'], attributes: [:id, :title, :year]]):ok

iex([email protected])4> :mnesia.add_table_copy(:books, :'[email protected]', :ram_copies):ok

Page 132: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])2> :mnesia.start():ok

iex([email protected])2> :mnesia.start():ok

iex([email protected])2> :mnesia.change_config(:extra_db_nodes, [:’[email protected]’]){:ok, [:"[email protected]"]}

iex([email protected])3> :mnesia.change_config(:extra_db_nodes, [:’[email protected]’]){:ok, [:"[email protected]"]}

iex([email protected])1> :mnesia.create_table(:books, [disc_copies: [:'[email protected]'], attributes: [:id, :title, :year]]):ok

iex([email protected])4> :mnesia.add_table_copy(:books, :'[email protected]', :ram_copies):ok

iex([email protected])5> :mnesia.add_table_copy(:books, :'[email protected]', :ram_copies):ok

Page 133: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])6> :mnesia.info()---> Processes holding locks <------> Processes waiting for locks <------> Participant transactions <------> Coordinator transactions <------> Uncertain transactions <------> Active tables <---books : with 0 records occupying 304 words of memschema : with 2 records occupying 566 words of mem===> System info in version "4.14.1", debug level = none <===opt_disc. Directory "/Users/gmile/[email protected]" is used.use fallback at restart = falserunning db nodes = ['[email protected]','[email protected]','[email protected]']stopped db nodes = []master node tables = []remote = []ram_copies = []disc_copies = [books,schema]disc_only_copies = [][{'[email protected]',disc_copies}, {'[email protected]',ram_copies}, {'[email protected]',ram_copies}] = [schema,books]12 transactions committed, 0 aborted, 0 restarted, 10 logged to disc0 held locks, 0 in queue; 0 local transactions, 0 remote0 transactions waits for other nodes: []:ok

iex([email protected])32>

Page 134: Magic Clusters and Where to Find Them - Eugene Pirogov

iex([email protected])6> :mnesia.info()---> Processes holding locks <------> Processes waiting for locks <------> Participant transactions <------> Coordinator transactions <------> Uncertain transactions <------> Active tables <---books : with 0 records occupying 304 words of memschema : with 2 records occupying 566 words of mem===> System info in version "4.14.1", debug level = none <===opt_disc. Directory "/Users/gmile/[email protected]" is used.use fallback at restart = falserunning db nodes = ['[email protected]','[email protected]','[email protected]']stopped db nodes = []master node tables = []remote = []ram_copies = []disc_copies = [books,schema]disc_only_copies = [][{'[email protected]',disc_copies}, {'[email protected]',ram_copies}, {'[email protected]',ram_copies}] = [schema,books]12 transactions committed, 0 aborted, 0 restarted, 10 logged to disc0 held locks, 0 in queue; 0 local transactions, 0 remote0 transactions waits for other nodes: []:ok

iex([email protected])32>

“schema” + “books” tables existon 3 different nodes

3 nodes are running

current node (node1)keeps 2 tables as RAM + disk

Page 135: Magic Clusters and Where to Find Them - Eugene Pirogov

Before we proceed…

Page 136: Magic Clusters and Where to Find Them - Eugene Pirogov

CAP theorem!

Page 137: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 138: Magic Clusters and Where to Find Them - Eugene Pirogov

@b0rk

Page 139: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 140: Magic Clusters and Where to Find Them - Eugene Pirogov

Consistency

Every read receives the most recent write or an error

Page 141: Magic Clusters and Where to Find Them - Eugene Pirogov

Availability

Every request receives a response, without guarantee that

it contains the most recent version of the information

Page 142: Magic Clusters and Where to Find Them - Eugene Pirogov

Partition tolerance

The system continues to operate despite an arbitrary number of messages being dropped by the network between nodes

Page 143: Magic Clusters and Where to Find Them - Eugene Pirogov

Pick two!AP or AC or CP

Page 144: Magic Clusters and Where to Find Them - Eugene Pirogov

ACis kind ofpointless

Page 145: Magic Clusters and Where to Find Them - Eugene Pirogov

Mnesia chooses…

Page 146: Magic Clusters and Where to Find Them - Eugene Pirogov

AC!

Page 147: Magic Clusters and Where to Find Them - Eugene Pirogov

If in your cluster the network connection between two nodes

goes bad, then each one will think that the other node is down,

and continue to write data.

Recovery from this is complicated.

Page 148: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 149: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 150: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 151: Magic Clusters and Where to Find Them - Eugene Pirogov

AXD 301switch

Page 152: Magic Clusters and Where to Find Them - Eugene Pirogov

“…measures are taken such that network reliability is very high”

Page 153: Magic Clusters and Where to Find Them - Eugene Pirogov

“…In such a highly specialized environment, the reliability of the control backplane essentially removes some of

the worries which the CAP theorem introduces.”

Page 154: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 155: Magic Clusters and Where to Find Them - Eugene Pirogov

DatabasesTools

Theory

Takeaways

Page 156: Magic Clusters and Where to Find Them - Eugene Pirogov

1. Elixir doesn’t bring anything new

to the table…

Page 157: Magic Clusters and Where to Find Them - Eugene Pirogov

…apart from productivity!

Page 158: Magic Clusters and Where to Find Them - Eugene Pirogov

It’s allabout Erlang

Page 159: Magic Clusters and Where to Find Them - Eugene Pirogov

2. “Hello world” for clusters is simple

Page 160: Magic Clusters and Where to Find Them - Eugene Pirogov

3. Deciding what matters is hard

Page 161: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 162: Magic Clusters and Where to Find Them - Eugene Pirogov

Understahd your values when

building a cluster!

Page 163: Magic Clusters and Where to Find Them - Eugene Pirogov

4. Releasing & deploying stuff is

tricky

Page 164: Magic Clusters and Where to Find Them - Eugene Pirogov

5. An Erlang app can be your little

universe

Page 165: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 166: Magic Clusters and Where to Find Them - Eugene Pirogov
Page 167: Magic Clusters and Where to Find Them - Eugene Pirogov