Elixir @ iMasters Intercon 2016

Elixir @ iMasters Intercon 2016

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

-- George Guimarães

7c12adb8b5521c060ab4630360a4fa27?s=128

Plataformatec

October 22, 2016
Tweet

Transcript

  1. 4.
  2. 5.
  3. 6.

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

    com concorrência. Não há escapatória.
  4. 10.
  5. 11.
  6. 13.

    “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. ”
  7. 14.
  8. 15.

    — ROBERT VIRDING “Any sufficiently complicated concurrent program in another

    language contains an ad hoc informally-specified bug-ridden slow implementation of half of Erlang.”
  9. 17.
  10. 22.
  11. 24.
  12. 25.
  13. 29.

    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
  14. 30.
  15. 31.

    defmodule Counter do def start(value) do receive do :increment ->

    start(value + 1) {:get, pid} -> send(pid, value) end end end
  16. 32.

    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
  17. 33.
  18. 39.

    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
  19. 40.

    ACTOR MODEL. 1. Enviar mensagens para outros atores; 2. Criar

    novos atores; 3. Especificar o comportamento para as próximas mensagens.
  20. 43.
  21. 44.
  22. 45.
  23. 49.
  24. 50.

    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
  25. 51.
  26. 55.

    Intel Xeon CPU X5675 @ 3.07GHz 24 CPU - 96GB

    Using 40% of CPU and Memory
  27. 56.
  28. 57.

    USO EFICIENTE!. Usa todos os cores da máquina, não só

    pra processar requests web, mas até pra rodar testes
  29. 58.
  30. 59.
  31. 60.
  32. 61.
  33. 62.
  34. 64.
  35. 66.
  36. 67.
  37. 69.
  38. 70.