Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Concurrent and Resilient Connections to Outside...

Concurrent and Resilient Connections to Outside the BEAM

Andrea Leopardi

May 11, 2016
Tweet

More Decks by Andrea Leopardi

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. defmodule Redis do def command(conn, cmd) do sock = checkout(conn)

    # send and recv checkin(conn, sock) end end
  8. defmodule Redis do def command(conn, cmd) do sock = checkout(conn)

    # send and recv checkin(conn, sock) end end
  9. 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
  10. You now allow initializations with fewer guarantees: they went from

    "the connection is available" to "the connection manager is available". Fred Hebert