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

Elixir @ iMasters Intercon 2016

Elixir @ iMasters Intercon 2016

Elixir: a linguagem, sua concepção e a volta da computação funcional

-- George Guimarães

Plataformatec

October 22, 2016
Tweet

More Decks by Plataformatec

Other Decks in Technology

Transcript

  1. NOSSA GERAÇÃO TEM UM PROBLEMA. Desenvolvedores web tem que lidar

    com concorrência. Não há escapatória.
  2. “what makes multithreaded programming difficult is not that writing it

    is hard, but that testing it is hard. It’s not the pitfalls that you can fall into; it’s the fact that you don’t necessarily know whether you’ve fallen into one of them. ”
  3. — ROBERT VIRDING “Any sufficiently complicated concurrent program in another

    language contains an ad hoc informally-specified bug-ridden slow implementation of half of Erlang.”
  4. defmodule Fibonacci do def calc(0), do: 0 def calc(1), do:

    1 def calc(n), do: calc(n-1) + calc(n-2) end Fibonacci.calc(10) # => 55
  5. defmodule Counter do def start(value) do receive do :increment ->

    start(value + 1) {:get, pid} -> send(pid, value) end end end
  6. defmodule Counter do def start(value) do receive do :increment ->

    start(value + 1) {:get, caller} -> send(caller, value) end end end pid = spawn(fn -> Counter.start(10) end) send(pid, :increment) send(pid, :increment) send(pid, :increment) send(pid, {:get, self}) flush # => 13
  7. defmodule Counter do def start(value) do receive do :increment ->

    start(value + 1) {:get, caller} -> send(caller, value) end end end pid = spawn(fn -> Counter.start(10) end) send(pid, :increment) send(pid, :increment) send(pid, :increment) send(pid, {:get, self}) flush # => 13
  8. ACTOR MODEL. 1. Enviar mensagens para outros atores; 2. Criar

    novos atores; 3. Especificar o comportamento para as próximas mensagens.
  9. defmodule MyApp do use Application def start(_type, _args) do import

    Supervisor.Spec, warn: false children = [ supervisor(Playfair.Repo, []), worker(Playfair.Mailer, []), worker(Playfair.FileWriter, []), ] opts = [strategy: :one_for_one, name: Playfair.Supervisor] Supervisor.start_link(children, opts) end end
  10. Intel Xeon CPU X5675 @ 3.07GHz 24 CPU - 96GB

    Using 40% of CPU and Memory
  11. USO EFICIENTE!. Usa todos os cores da máquina, não só

    pra processar requests web, mas até pra rodar testes