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

Introduction to Elixir

Faheem
July 18, 2016

Introduction to Elixir

Why am I excited about it? A Ruby developer's perspective.

This was presented to colleagues at Deliveroo internally.

Faheem

July 18, 2016
Tweet

Other Decks in Technology

Transcript

  1. μs

  2. • Amazon • AOL • Basho • Bet365 • Chef

    • Ericsson • Facebook • GitHub • Goldman Sachs • Huffington Post • Klarna • Rackspace • Rakuten • WhatsApp • Whisper • Yahoo! • …. Companies using Erlang source: Wikipedia entry for Erlang
  3. • Alpha Sights • Bleacher Report • BT • Curadora

    • Discored • DockYard • Discord • Puppet Labs • Pinterest • Thoughtbot • Brightcove • Evercam • Pronto • …. Companies using Elixir source: github.com/doomspork/elixir-companies
  4. Elixir extends Erlang • Call Erlang functions directly • Use

    Erlang libraries • Elixir is a superset of Erlang
  5. – Joe Armstrong “ It's not Erlang and it's not

    Ruby and it has ideas of its own.”
  6. – everyone in the room “That’s all well and good

    but why all the hype about Elixir?”
  7. Mhz 0.1 1 100 100000 4004 8086 i386 P5 Netburst

    Nehalem Haswell Intel CPU clock rate
  8. – Faheem, 2 years ago “Oh I know, I will

    run multiple instances of Ruby VM”
  9. – Faheem (while shamelessly stealing from Rob Pike) “Concurrency is

    the bread and butter of Elixir. Parallelism is just a nice side effect”
  10. “Concurrency is the way to structure things. So (may be)

    you can use parallelism to do a better job” – Rob Pike (creator of golang)
  11. Whatsapp (Erlang VM) • 1 million TCP connections per machine

    in 2011 • 2.8 million TCP connections in Feb 2012 • 571K packets/sec, > 200K distinct messages/sec • Goal was Resilient against disruptions • 450 million active users with only 32 engineers source: blog.whatsapp.com/196/1-million-is-so-2011
  12. Pattern Matching # Elixir defmodule Fib do def fib(n) do

    case n do 0 -> 0 1 -> 1 n -> fib(n-1) + fib(n-2) end end end
  13. Mix # Rake and bundler $ mix new foo $

    cd foo $ mix test # compile and test $ mix hex.publish # Make and publish a package $ mix hex.docs # Publish docs
  14. Hex.pm • 2_400 packages • 11_000 versions • 1.5 Million

    downloads this week • 41+ Million downloads ever
  15. Cut because of time • Phoenix • Channels • Presence

    • Concurrent tests • No lazy loading associations
  16. Case study • API endpoint (proprietary code) • Authentication •

    JSON data • Postgres 9.4 • Hosted on Heroku source: http://sorentwo.com/2016/02/02/caching-what-is-it-good-for.html
  17. Case study • Ruby/Rails • Two performance M dynos •

    Elixir/Phoenix • Single 1x Production dyno source: http://sorentwo.com/2016/02/02/caching-what-is-it-good-for.html
  18. Case study • Ruby 2.3 / Rails 4.2.5.1 with ActiveRecord

    • Fronted by a Redis cache • Tuned to fetch as little data as possible from the database • All associations are preloaded • All data is generic, not customized to the current user • The request is paginated to 100 primary records, without a limit on side loads • The payload is a hefty 160k, un-gzipped source: http://sorentwo.com/2016/02/02/caching-what-is-it-good-for.html
  19. Case study • Elixir 1.2.1 / Phoenix 1.1 • No

    entity cache • All fields are fetched from the database, SELECT * • All JSON responses are serialized on the fly, directly in views • Includes customized data based on the current user • The request isn’t paginated at all, there are 250 primary records • The payload is a massive 724k, un-gzipped source: http://sorentwo.com/2016/02/02/caching-what-is-it-good-for.html
  20. Case study • Serving up 2.5x the records • With

    4.5x the data, • Without any caching • Response times are 1.5x-2.5x faster. source: http://sorentwo.com/2016/02/02/caching-what-is-it-good-for.html