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
160
BEAM: The Perfect Fit for Networks
whatyouhide
1
150
Update from the Elixir team - 2022
whatyouhide
0
350
Testing Asynchronous OTP
whatyouhide
0
470
Elixir Sightseeing Tour
whatyouhide
0
370
Mint - Disrupting HTTP clients
whatyouhide
0
210
BEAM Architecture Handbook
whatyouhide
7
2.7k
The Evolution of a Language
whatyouhide
0
120
Elixir - functional, concurrent, distributed programming for the rest of us
whatyouhide
2
300
Other Decks in Programming
See All in Programming
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
Jakarta EE meets AI
ivargrimstad
0
530
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
910
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Speed Design
sergeychernyshev
24
610
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
What's new in Ruby 2.0
geeforr
343
31k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Why Our Code Smells
bkeepers
PRO
334
57k
How STYLIGHT went responsive
nonsquared
95
5.2k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
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