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

Simplifying systems with Elixir - Belgrade

Simplifying systems with Elixir - Belgrade

Saša Jurić

October 25, 2018
Tweet

More Decks by Saša Jurić

Other Decks in Programming

Transcript

  1. Simplifying systems
    with Elixir
    @sasajuric
    aircloak.com

    View full-size slide

  2. Elixir
    functional
    concurrent

    View full-size slide

  3. process
    ...
    foo(...)
    bar(...)
    ...

    View full-size slide

  4. functional Elixir
    modules and functions
    immutable data
    first-class functions

    View full-size slide

  5. ...
    spawn(fn -> ... end)
    ...

    View full-size slide

  6. process A
    ...
    foo(...)
    bar(...)
    ...
    process B
    ...
    baz(...)
    qux(...)
    ...

    View full-size slide

  7. send(
    process_b,
    some_message
    )
    receive do
    message ->
    handle(message)
    end
    process a process b

    View full-size slide

  8. BEAM (Erlang VM)

    View full-size slide

  9. BEAM (Erlang VM)

    View full-size slide

  10. scheduler scheduler scheduler scheduler
    BEAM (Erlang VM)
    CPU CPU CPU CPU

    View full-size slide

  11. concurrent
    functional

    View full-size slide

  12. activities
    incoming requests
    background jobs
    in-memory state
    load control

    View full-size slide

  13. managing activities
    multiple OS processes
    3rd party products
    service managers

    View full-size slide

  14. uniformity
    simpler development
    simpler testing
    simpler deployment
    simpler maintenance
    improved collaboration

    View full-size slide

  15. theerlangelist.com

    View full-size slide

  16. git clone https://github.com/sasa1977/erlangelist.git
    mix deps.get && pushd assets && npm install && popd
    iex -S mix phx.server

    View full-size slide

  17. serving requests

    View full-size slide

  18. http listener https listener

    View full-size slide

  19. http listener https listener
    handler 1 handler 2 handler n

    View full-size slide

  20. stats collector
    handler
    handler handler

    View full-size slide

  21. stats collector
    disk writer

    View full-size slide

  22. def store(path, data) do
    File.write!(
    path,
    :erlang.term_to_binary(data)
    )
    end

    View full-size slide

  23. def read(path, default) do
    path
    |> File.read!()
    |> :erlang.binary_to_term()
    rescue ArgumentError ->
    default
    end

    View full-size slide

  24. scheduler cleanup job
    periodically starts

    View full-size slide

  25. our system CA server
    certificate request
    challenge info
    challenge

    View full-size slide

  26. certifier
    http server
    usage stats

    View full-size slide

  27. dev CA server

    View full-size slide

  28. service management

    View full-size slide

  29. defmodule StatsCollector do
    def start_link() do
    # ...
    end
    # ...
    end

    View full-size slide

  30. Supervisor.start_link(
    [
    StatsCollector,
    Cleanup
    ],
    # ..
    )

    View full-size slide

  31. supervisor
    stats collector cleanup

    View full-size slide

  32. supervisor
    worker

    View full-size slide

  33. 1
    2 6 9
    7 8
    3 4 5

    View full-size slide

  34. erlangelist
    usage stats web

    View full-size slide

  35. usage stats
    stats collector cleanup

    View full-size slide

  36. web
    ACME server main site certifier

    View full-size slide

  37. technical feature built-in options
    services GenServer, Task
    service manager Supervisor
    service registry Registry
    k-v ets, mnesia
    web server phoenix, plug, cowboy
    periodical jobs :timer, quantum, periodic
    load regulation jobs, safetyvalve, sbroker
    concurrent flows Flow, GenStage

    View full-size slide

  38. Elixir in a nutshell
    start simple
    go far

    View full-size slide

  39. Elixir guides
    Phoenix guides
    Learning resources
    Elixir forum

    View full-size slide

  40. 40% off using code
    ctwelixirbg18 at
    manning.com
    slides available at
    bit.ly/elixirbg102018

    View full-size slide