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
Concurrent and Resilient Connections to Outside...
Search
Andrea Leopardi
May 11, 2016
Programming
1
320
Concurrent and Resilient Connections to Outside the BEAM
Andrea Leopardi
May 11, 2016
Tweet
Share
More Decks by Andrea Leopardi
See All by Andrea Leopardi
The World is a Network (and We Are Just Nodes)
whatyouhide
0
190
BEAM: The Perfect Fit for Networks
whatyouhide
1
180
Update from the Elixir team - 2022
whatyouhide
0
380
Testing Asynchronous OTP
whatyouhide
0
500
Elixir Sightseeing Tour
whatyouhide
0
400
Mint - Disrupting HTTP clients
whatyouhide
0
230
BEAM Architecture Handbook
whatyouhide
7
2.8k
The Evolution of a Language
whatyouhide
0
140
Elixir - functional, concurrent, distributed programming for the rest of us
whatyouhide
2
310
Other Decks in Programming
See All in Programming
ソフトウェアエンジニアの成長
masuda220
PRO
12
2.2k
PEPCは何を変えようとしていたのか
ken7253
3
310
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
1.1k
はじめての Go * WASM * OCR
sgash708
1
120
CloudNativePGを布教したい
nnaka2992
0
120
お前もAI鬼にならないか?👹Bolt & Cursor & Supabase & Vercelで人間をやめるぞ、ジョジョー!👺
taishiyade
7
4.2k
良いコードレビューとは
danimal141
9
7.5k
SwiftUI Viewの責務分離
elmetal
PRO
2
280
技術を改善し続ける
gumioji
0
180
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
1.2k
Datadog DBMでなにができる? JDDUG Meetup#7
nealle
0
160
Better Code Design in PHP
afilina
0
180
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Stop Working from a Prison Cell
hatefulcrawdad
268
20k
Designing for humans not robots
tammielis
250
25k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.9k
How to train your dragon (web standard)
notwaldorf
91
5.9k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
Transcript
outside CONCURRENT RESILIENT and CONNECTIONS to the BEAM
ERLANG VM mnesia message passing ets
ERLANG VM key-value store relational db message queue
ERLANG VM key-value store relational db message queue
the outside world is SCARY
ANDREA LEOPARDI @WHATYOUHIDE
Gothenburg, Sweden
FOOTBALL ADDICTS
GENSERVER TCP
SILLY the way
defmodule Redis do def command(cmd) do end end
defmodule Redis do def command(cmd) do {:ok, sock} = :gen_tcp.connect(...)
:gen_tcp.send(sock, encode(cmd)) {:ok, data} = :gen_tcp.recv(sock, 0) :gen_tcp.close(sock) decode(data) end end
defmodule Redis do def command(cmd) do {:ok, sock} = :gen_tcp.connect(...)
:gen_tcp.send(sock, encode(cmd)) {:ok, data} = :gen_tcp.recv(sock, 0) :gen_tcp.close(sock) decode(data) end end
defmodule Redis do def command(cmd) do {:ok, sock} = :gen_tcp.connect(...)
:gen_tcp.send(sock, encode(cmd)) {:ok, data} = :gen_tcp.recv(sock, 0) :gen_tcp.close(sock) decode(data) end end
defmodule Redis do def command(cmd) do {:ok, sock} = :gen_tcp.connect(...)
:gen_tcp.send(sock, encode(cmd)) {:ok, data} = :gen_tcp.recv(sock, 0) :gen_tcp.close(sock) decode(data) end end
defmodule Redis do def command(cmd) do {:ok, sock} = :gen_tcp.connect(...)
:gen_tcp.send(sock, encode(cmd)) {:ok, data} = :gen_tcp.recv(sock, 0) :gen_tcp.close(sock) decode(data) end end
defmodule Redis do def command(cmd) do {:ok, sock} = :gen_tcp.connect(...)
:gen_tcp.send(sock, encode(cmd)) {:ok, data} = :gen_tcp.recv(sock, 0) :gen_tcp.close(sock) decode(data) end end
opening NEW connections is EXPENSIVE
GENSERVER keeping the socket in a
TWO WAYS blocking non-blocking
TWO WAYS blocking
CLIENT GENSERVER socket socket send() recv()
defmodule Redis do def command(conn, cmd) do sock = checkout(conn)
# send and recv checkin(conn, sock) end end
defmodule Redis do def command(conn, cmd) do sock = checkout(conn)
# send and recv checkin(conn, sock) end end
{:error, :checked_out} :queue.in() VS
POOLING :|
TWO WAYS non-blocking
active: true {:noreply, _} + GenServer.reply/2 +
client Redis client client GenServer
tcp is FULL DUPLEX
client Redis client client Sender Receiver
TWO WAYS blocking non-blocking copies less data + needs pooling
- doesn't use full duplex - enc/dec on client + - copies more data + doesn't need pooling + uses full duplex - enc/dec in server
RESIL IENCY
Redis GenServer
Redis GenServer
{:tcp_closed, reason} backoff + reconnect
hex.pm/packages/connection gen_
Connection GenServer
init/1 connect/2 disconnect/2 handle_call/3 handle_cast/2 handle_info/2 terminate/2 code_change/3 {:disconnect, reason,
state} {:backoff, timeout, state}
sync/async CONNECT
SYNC start_link {:ok, pid} init() connect
ASYNC start_link {:ok, pid} init() connect connect()
You now allow initializations with fewer guarantees: they went from
"the connection is available" to "the connection manager is available". Fred Hebert
CONNECTION TALKING CONCURRENCY RESILIENCY
@whatyouhide