magic clusters and where to find them 2.0 - eugene pirogov

165

Upload: elixir-meetup

Post on 13-Apr-2017

89 views

Category:

Software


6 download

TRANSCRIPT

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

Clustersand where to find

them

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

Eugene Pirogovgmile

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

DatabasesTools

Theory

Takeaways

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

DatabasesTools

Theory

Takeaways

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

What isa cluster?

Page 7: Magic Clusters and Where to Find Them 2.0 - 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 8: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 9: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 10: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 11: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 12: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

When to usea cluster?

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

1. Fail-overclusters

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

2. Load balancingclusters

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

What typicalErlang clusteris built with?

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

1. A node

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

node()

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

2. An RPC call

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

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

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

3. send call

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

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

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

Example 1:Starting a node

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

iex

Page 24: Magic Clusters and Where to Find Them 2.0 - 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 25: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

iex --name eugene

Page 26: Magic Clusters and Where to Find Them 2.0 - 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 27: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

iex --sname eugene

Page 28: Magic Clusters and Where to Find Them 2.0 - 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 29: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

iex --name eugene@host

Page 30: Magic Clusters and Where to Find Them 2.0 - 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 31: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

Example 2:starting two nodes

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

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

Page 33: Magic Clusters and Where to Find Them 2.0 - 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 34: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

Example 3:sending a message

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

iex --name node1iex --name node2

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

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

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

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

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

Example 4:calling remotely

Page 38: Magic Clusters and Where to Find Them 2.0 - 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 39: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

REST/JSON/XMLBinary protocol

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

REST/JSON/XMLBinary protocol

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

REST/JSON/XMLBinary protocol

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

Bonus track:Magic cookie!

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

cat ~/.erlang.cookie

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

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

Page 45: Magic Clusters and Where to Find Them 2.0 - 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 46: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

DatabasesTools

Theory

Takeaways

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

epmd

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

Erlang PortMapper Daemon

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

runs on system startup

Page 50: Magic Clusters and Where to Find Them 2.0 - 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 51: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

maps portsto node names

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

net_kernel

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

Example 5:starting a

distributed node

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

iex

Page 56: Magic Clusters and Where to Find Them 2.0 - 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 57: Magic Clusters and Where to Find Them 2.0 - 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 58: Magic Clusters and Where to Find Them 2.0 - 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 59: Magic Clusters and Where to Find Them 2.0 - 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 60: Magic Clusters and Where to Find Them 2.0 - 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 61: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

Example 6:monitoring a

node

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

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

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

iex([email protected])1>

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

iex([email protected])1>

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

Page 65: Magic Clusters and Where to Find Them 2.0 - 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 66: Magic Clusters and Where to Find Them 2.0 - 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 67: Magic Clusters and Where to Find Them 2.0 - 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 68: Magic Clusters and Where to Find Them 2.0 - 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 69: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

net_adm

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

Example 7:ping

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

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

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

iex([email protected])1>

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

iex([email protected])1>

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

Page 75: Magic Clusters and Where to Find Them 2.0 - 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 76: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

Example 8:names

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

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

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

iex([email protected])1>

Page 79: Magic Clusters and Where to Find Them 2.0 - 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 80: Magic Clusters and Where to Find Them 2.0 - 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 81: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

Example 9:world

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

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

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

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

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

iex([email protected])1>

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

Bonus track:Connecting

to a node running in production

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

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

Page 89: Magic Clusters and Where to Find Them 2.0 - 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 90: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

$ kubectl get pods -l app=matcher -o template --template="{{range.items}}{{.metadata.name}}{{end}}" | xargs -o -I my_pod kubectl exec my_pod -i -t -- iex --name [email protected] --remsh [email protected] --cookie marketplace

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

$ kubectl get pods -l app=matcher -o template --template="{{range.items}}{{.metadata.name}}{{end}}" | xargs -o -I my_pod kubectl exec my_pod -i -t -- iex --name [email protected] --remsh [email protected] --cookie marketplace

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

$ kubectl get pods -l app=matcher -o template --template="{{range.items}}{{.metadata.name}}{{end}}" | xargs -o -I my_pod kubectl exec my_pod -i -t -- iex --name [email protected] --remsh [email protected] --cookie marketplace

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

slave

Page 94: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 95: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 96: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 97: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

3. Transfer configurationto slave nodes

2. Add code path to slave nodes

4. Ensure appsare started on slave

1. Start slave

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

What else?

Page 99: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 100: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 101: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 102: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 103: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

Node

Page 104: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 105: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

bitwalker/swarm

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

Easy clustering, registration, and distribution of worker processes for

Erlang/Elixir

Page 107: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 108: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 109: Magic Clusters and Where to Find Them 2.0 - 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 110: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

bitwalker/libcluster

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

What next?

Page 113: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 114: Magic Clusters and Where to Find Them 2.0 - 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 115: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

DatabasesTools

Theory

Takeaways

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

mnesia

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

Example 10:initialize mnesia

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

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

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

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

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

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

Page 121: Magic Clusters and Where to Find Them 2.0 - 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 122: Magic Clusters and Where to Find Them 2.0 - 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 123: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

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

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

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

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

Page 125: Magic Clusters and Where to Find Them 2.0 - 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 126: Magic Clusters and Where to Find Them 2.0 - 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 127: Magic Clusters and Where to Find Them 2.0 - 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 128: Magic Clusters and Where to Find Them 2.0 - 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 129: Magic Clusters and Where to Find Them 2.0 - 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 130: Magic Clusters and Where to Find Them 2.0 - 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 131: Magic Clusters and Where to Find Them 2.0 - 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 132: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

Before we proceed…

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

CAP theorem!

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

@b0rk

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

Consistency

Every read receives the most recent write or an error

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

Availability

Every request receives a response, without guarantee that

it contains the most recent version of the information

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

Partition tolerance

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

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

Pick two!AP or AC or CP

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

ACis kind ofpointless

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

Mnesia chooses…

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

AC!

Page 144: Magic Clusters and Where to Find Them 2.0 - 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 145: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 146: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 147: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 148: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

AXD 301switch

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

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

Page 150: Magic Clusters and Where to Find Them 2.0 - 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 151: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Page 152: Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov

DatabasesTools

Theory

Takeaways

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

1. Elixir lowers the barrier of entrance in building clusters

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

…via productivity batteries!

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

And yet it’s allabout Erlang

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

2. “Hello world” for clusters is simple

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

3. Deciding what matters is hard

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

Understahd your values when

building a cluster!

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

4. Releasing & deploying stuffmay get tricky

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

5. Building stateful clusters is really

challanging

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

6. An Erlang app can be your little

universe

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