Slide 1

Slide 1 text

@elixirlang / elixir-lang.org

Slide 2

Slide 2 text

Elixir v1.0 • September/2014 • >180 contributors • 3 books out! • First Elixirconf!

Slide 3

Slide 3 text

Extensibility • Web infrastructure • Embedded systems • Financial/Video platforms • Graphical User Interfaces

Slide 4

Slide 4 text

Elixir v1.1

Slide 5

Slide 5 text

Elixir v1.1 • September/2015 • >295 contributors • ~ 1000 packages on hex.pm • > 6.5million downloads

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Application.fetch_env!/2 Keyword.get_and_update/3 Keyword.get_lazy/3 Keyword.pop_lazy/3 Keyword.put_new_lazy/3 Map.get_and_update/3 Map.get_lazy/3 Map.pop_lazy/3 Map.put_new_lazy/3 Enum.dedup/1 Enum.dedup_by/2 Enum.min_max/1 Enum.min_max_by/2 Enum.random/1 Enum.reduce_while/3 Enum.reverse_slice/3 Enum.take_random/2 More functions File.lstat/1 File.lstat!/1 File.rename/2 Integer.digits/2 Integer.undigits/2 GenServer.whereis/1 Process.hibernate/3 Stream.dedup/1 Stream.dedup_by/2 Stream.transform/4 String.jaro_distance/2 String.splitter/3 StringIO.flush/1 Task.yield/2 Task.shutdown/2 Tuple.append/2 URI.to_string/1

Slide 8

Slide 8 text

Enum iex> Enum.dedup([1, 1, 2, 2, 1, 1]) [1, 2, 1] iex> Enum.random 1..100 51 iex> Enum.take_random 1..100, 3 [14, 3, 72]

Slide 9

Slide 9 text

iex> String.jaro_distance "helo", "help" 0.8333333333334 String $ mix helo ** (Mix) The task "helo" could not be found. Did you mean "help"?

Slide 10

Slide 10 text

# v1.0+ iex> task = Task.async(fn -> ... end) %Task{} iex> Task.await(task, 5_000) # v1.1+ iex> Task.yield(task, 5_000) {:ok, result} | nil iex> Task.shutdown(task, :brutal_kill) {:ok, result} | nil Task

Slide 11

Slide 11 text

ExUnit v1.1

Slide 12

Slide 12 text

Capture Log # v1.0+ import ExUnit.CaptureIO capture_io fn -> IO.puts "hello" end # v1.1+ import ExUnit.CaptureLog capture_log fn -> Logger.info "hello" end

Slide 13

Slide 13 text

# Per test @tag :capture_log test "something with logging" do ... end # Per suite ExUnit.configure capture_log: true Capture Log

Slide 14

Slide 14 text

Capture Log 1) test something with logging test/plug/error.exs:59 ** (RuntimeError) oops stacktrace: test/plug/error.exs:59 The following output was logged: 20:27:52.443 [info] log message

Slide 15

Slide 15 text

Not implemented tests # @tag :not_implemented test "eventually will do X" $ mix test --exclude not_implemented $ mix test --only not_implemented

Slide 16

Slide 16 text

• stacktrace depth is now configurable and has been increased to 20 • More detailed errors • Ability to skip tests • Proper line number in doctests failures More improvements

Slide 17

Slide 17 text

Mix v1.1

Slide 18

Slide 18 text

mix profile.fprof # CNT ACC (ms) OWN (ms) Total 200279 1972.188 1964.579 Test.run/0 1 1972.166 0.007 Test.do_something/1 3 1972.131 0.040 Test.bottleneck/0 1 1599.490 0.007 ... $ mix profile.fprof my_script.exs

Slide 19

Slide 19 text

[build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod] Closer to releases

Slide 20

Slide 20 text

Start Permanent (true) • Shuts the node down if your application crashes

Slide 21

Slide 21 text

Build Embedded (false) /_build ├── dev │ └── lib │ ├── cowboy │ │ └── ebin -> ../../../../deps/cowboy/ebin │ ├── cowlib │ │ ├── ebin -> ../../../../deps/cowlib/ebin │ ├── phoenix │ │ ├── ebin │ │ │ ├── Elixir.Access.Phoenix.Socket.beam

Slide 22

Slide 22 text

Build embedded (true) • Packages your whole application into _build (no symlinks) • Enables protocol consolidation • No longer automatically compiles

Slide 23

Slide 23 text

config/config.exs # v1.0: config/config.exs config :my_app, :key, :value # v1.1: this will warn config :unknown_app, :key, :value

Slide 24

Slide 24 text

• "mix compile" tracks only compile-time dependencies for Elixir • "recompile()" inside IEx • Use the safer https protocol instead of git for :github dependencies More improvements

Slide 25

Slide 25 text

Deprecations

Slide 26

Slide 26 text

Elixir v1.1 # v1.1 iex> "Hello \u2661" "Hello ♡" # v1.0 iex> "Hello \x{2661}” "Hello ♡" SOFT DEPRECATED

Slide 27

Slide 27 text

Elixir v1.1 # v1.0 defmodule Calculator do use Behaviour defcallback add(number, number) :: number end SOFT DEPRECATED # v1.1 defmodule Calculator do @callback add(number, number) :: number end

Slide 28

Slide 28 text

Elixir v1.1 defmodule Calculator do @typedoc "A complex number" @opaque complex :: ... @doc "Adds two numbers" @callback add(number, number) :: ... end Code.get_docs(Calculator, :type_docs)

Slide 29

Slide 29 text

Elixir v1.1 DEPRECATED defimpl Access, for: X do ... end

Slide 30

Slide 30 text

Access opts[key] opts[key] opts[key] opts[key] Code Server

Slide 31

Slide 31 text

• opts[key] still works • Access defines a subset of the Dict behaviour • The bottleneck does not exist in prod • Common hot-paths have been inlined Access

Slide 32

Slide 32 text

Community

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Elixir v1.2

Slide 36

Slide 36 text

Migration • Elixir v1.0, v1.1
 Support Erlang 17 & 18+
 • Elixir v1.2
 Supports Erlang 18+

Slide 37

Slide 37 text

Erlang 18+ • Variables in maps: %{key => value} • Official support for large maps

Slide 38

Slide 38 text

Dicts in Elixir v1.1 • Keyword, Map, HashDict • Unified via the Dict API • Too many options. Often confusing.

Slide 39

Slide 39 text

Dicts in Elixir v1.2 • Keyword lists - used as options, allow duplicate keys, user ordered • Maps - pattern matching, fast & scalable, term ordered

Slide 40

Slide 40 text

Dict & Set • HashDict will be soft deprecated
 Use Map • HashSet will be soft deprecated
 Use MapSet • Dict and Set will be soft deprecated

Slide 41

Slide 41 text

Multi-aliases alias MyApp.Foo alias MyApp.Bar alias MyApp.Baz alias MyApp.{Foo, Bar, Baz}

Slide 42

Slide 42 text

December/2015

Slide 43

Slide 43 text

Meanwhile, upgrade to Erlang 18+

Slide 44

Slide 44 text

Elixir v1.3

Slide 45

Slide 45 text

Collections sink (collectable) widgets |> Enum.filter(fn b -> b.color == :red end) |> Enum.map(fn b -> {b.title, b.height} end) |> Enum.into(%{}) source (enumerable)

Slide 46

Slide 46 text

Collections CSV.parse(path) |> Enum.filter(fn b -> b.color == :red end) |> Enum.map(fn b -> {b.title, b.height} end) |> Enum.into(IO.stream(:stdio, :inspect))

Slide 47

Slide 47 text

Collections + Laziness CSV.parse(path) |> Stream.filter(fn b -> b.color == :red end) |> Stream.map(fn b -> {b.title, b.height} end) |> Stream.into(IO.stream(:stdio, :inspect)) |> Stream.run()

Slide 48

Slide 48 text

Pipeline parallelism CSV.parse(path) |> Stream.async() |> Stream.filter(fn b -> b.color == :red end) |> Stream.map(fn b -> {b.title, b.height} end) |> Stream.into(IO.stream(:stdio, :inspect)) |> Stream.run()

Slide 49

Slide 49 text

Pipeline parallelism CSV.parse(path) |> ... |> Stream.async() |> ... |> Stream.async() |> ... |> Stream.async() |> ... |> Stream.run()

Slide 50

Slide 50 text

Pipeline parallelism async CSV async async run

Slide 51

Slide 51 text

Pipeline parallelism • Each async stage is a process • What happens if one of them crash? • How to provide back-pressure?

Slide 52

Slide 52 text

Pipeline parallelism • How to make streams supervised processes? • Pipeline parallelism isn’t even a good strategy

Slide 53

Slide 53 text

How to make supervised processes stream data?

Slide 54

Slide 54 text

GenRouter

Slide 55

Slide 55 text

GenRouter • Connects sources to sinks • Demand-driven

Slide 56

Slide 56 text

GenRouter Router

Slide 57

Slide 57 text

GenRouter Sink

Slide 58

Slide 58 text

GenRouter Source

Slide 59

Slide 59 text

GenRouter in | out

Slide 60

Slide 60 text

GenRouter GenRouter.start_link( InPart, in_args, OutPart, out_args )

Slide 61

Slide 61 text

GenRouter.start_link( GenRouter.SingleIn, [], GenRouter.BroadcastOut, [] ) GenRouter

Slide 62

Slide 62 text

SingleIn - BroadcastOut router

Slide 63

Slide 63 text

SingleIn - BroadcastOut router 1 1 1 1 1

Slide 64

Slide 64 text

SingleIn - BroadcastOut router 1,2 1,2 1,2 1,2 1,2

Slide 65

Slide 65 text

SingleIn - BroadcastOut router 1,2,3 1,2,3 1,2,3 1,2,3 1,2,3

Slide 66

Slide 66 text

DynamicIn - BroadcastOut router 1,2,3 1,2,3 1,2,3 1,2,3 2 1 3

Slide 67

Slide 67 text

DynamicIn - MessageQueueOut router 1 2 3 4 2 1 3

Slide 68

Slide 68 text

Some Use Cases • A GenEvent replacement that is process-based • A way to load-balance jobs across a pool of processes

Slide 69

Slide 69 text

Demand-driven

Slide 70

Slide 70 text

Demand-driven B C A Source | Sink Source | Sink

Slide 71

Slide 71 text

Demand-driven B C A Ask 10 Ask 10 Sends max 10 Sends max 10

Slide 72

Slide 72 text

Demand-driven • It is a message contract • It pushes back-pressure to the boundary • GenRouter is one impl of this contract • Inspired by Akka Streams

Slide 73

Slide 73 text

Supervised TCP Acceptor # Source {:ok, acceptor} = GenRouter.TCPAcceptor.start_link(...) # Sink {:ok, supervisor} = GenRouter.Supervisor.start_link(...) # Source <-> Sink GenRouter.subscribe(supervisor, to: acceptor)

Slide 74

Slide 74 text

The path forward • Define the demand-driven message contract • Implement GenRouter and related abstractions • Integrate with streams

Slide 75

Slide 75 text

consulting and software engineering

Slide 76

Slide 76 text

@elixirlang / elixir-lang.org