SlideShare uma empresa Scribd logo
1 de 76
Polyglot Parallelism
  A Case Study in Using Erlang
    and Ruby at Rackspace
The Problem
    Part 1
20,000
network devices
9 Datacenters,
 3 Continents
devices not designed for
    high-throughput
      management
we need a high
throughput solution
the time spent in I/O
   is the primary
      bottleneck
if you want to speed
things up you have to
talk to more devices
       in parallel
The Problem
    Part II
huge blobs of data
lots of backups
equals big database
ad-hoc searching
 is difficult but
   important
customer SLA means
need to restore from
   backup quickly
an event must be
generated for each
device interaction
migrations are
problematic with
 that much data
rigid schema made
  adapting to new
  devices difficult
each device type has
different properties
“backup” means
different things for
 each device type
need to grow with
   the business
Previous
Solution
multiple Ruby apps
difficult to scale
vendor device
  managers
New Solution
the simplest thing
that could possibly
       work
most db writes
  come from
scheduled jobs
Other Clients

Rails            ReST API

                 Erlang


   MongoDB           Network
                     Devices
Joe Armstrong
AXD301
ATM Switch
99.9999999%
Functional
Dynamically Typed
Single Assignment
A = 1. %=> 1
A = 2. %=> badmatch
[B, 2, C] = [1, 2, 3].
B = 1. %=> 1
C = 3. %=> 3
Immutable
   Data
Structures
D = dict:new().
D1 = dict:store(foo, 1, D).
D2 = dict:store(bar, 2, D1).
Concurrency
 Oriented
-module(fact).
-export([fac/1]).

fac(0) -> 1;
fac(N) -> N * fac(N-1).
-module(quicksort).
-export([quicksort/1]).

quicksort([]) -> [];
quicksort([Pivot|Rest]) ->
  quicksort([Front || Front <- Rest, Front < Pivot])
  ++ [Pivot] ++
  quicksort([Back || Back <- Rest, Back >= Pivot]).
Details
jobs framework
Runner


             Callback
   Workers   Module
Callback
  Runner           Worker        Module
           start
           ready
item
       process
                       process
        ready
           .
           .
           .
         stop
“behaviour” is interface
behaviour_info(callbacks) -> [
    {init, 1},
    {process_item, 3},
    {worker_died, 5},
    {job_stopping, 1},
    {job_complete, 2}
].
running({worker_ready, WorkerPid, ok}, S) ->
  case queue:out(S#state.items) of
    {empty, I2} ->
      stop_worker(WorkerPid, S),
      {next_state, complete, S#state{items = I2}};

    {{value, Item}, I2} ->
      job_worker:process(WorkerPid, Item, now(),
                         S#state.job_state),

      {next_state, running, S#state{items = I2}}
  end;
handle_info({'DOWN', _, process, WorkerPid, Info},
            StateName, S) ->
  {Item, StartTime} = clear_worker(WorkerPid, S),

  Callback = S#state.callback,
  spawn(Callback, worker_died,
        [Item, WorkerPid, StartTime,
         Info, S#state.job_state]),

  %% Start a replacement worker
  start_workers(1, Callback),
  {next_state, StateName, S};
handle_cast({process, Item, StartTime, JS}, S) ->
  Callback = S#state.callback,
  Continue =
    try
      Callback:process_item(Item, StartTime, JS)
    catch
      throw: Error ->
         error_logger:error_report(Error),
         ok
    end,

  job_runner:worker_ready(S#state.runner, self(),
                          Continue),

  {noreply, S}.
story time
ReSTful API
     with Webmachine
The Convention Over Configuration Webserver
http://webmachine.basho.com




HTTP Request Lifecycle Diagram
If you know HTTP
Webmachine Is Simple
As Proven by the “Number of Types of Things”
        Measurement of Complexity
The 3 Most Important Types of
    Things In Webmachine
1. Dispatch Rules (pure data--barely a thing!)
2. Resources (composed of simple functions!)
3. Requests (simple get/set interface!)
Dispatch Rules
      { ["devices", server], device_resource, [] }


                 GET /devices/12345

 Webmachine inspects the device_resource module for
defined callbacks, and sets the Request record’s “server”
                    value to 12345.
Resources
• POEM (Plain Old Erlang Module)
• Composed of referentially transparent functions*
• Functions are callbacks into the request lifecycle
• Approximately 30 possible callback functions, e.g.:
   • resource_exists → 404 Not Found
   • is_authorized → 401 Not Authorized



                         * mostly
Resource Functions
               Perma-404
resource_exists(Request, Context) ->
   {false, Request, Context}.

               Lucky Auth
is_authorized(Request, Context) ->
   S = calendar:time_to_seconds(now()),
   case S rem 2 of
      0 -> {true, Request, Context};
      1 -> {“Basic realm=lucky”, Request, Context}
   end.
Requests
• The first argument to each resource function
• Set and read request & response data

        RemoteIP = wrq:peer(Request).



wrq:set_resp_header(“X-Answer”, “42”, Request).
Retrieving a JSON Firewall Representation

content_types_provided(Request, Context) ->
    Types = [{"application/json", to_json}],
    {Types, Request, Context}.

to_json(Request, Context) ->
    Device = proplists:get_value(device, Context),
    UserId = get_user_id(Request),

   case fe_api_firewall:get_config(Device, UserId) of

       {ok, Config} ->
           success_response(Config, Request, Context);

       {error, Reason} ->
           error_response(502, Reason, Request, Context)
   end.
Gotchas
primitive obsession
string-ish
        “hi how are you”

        <<“hello there”>>

[<<"easy as ">>, [$a, $b, $c], "
            ☺n"].
hashes vs records
to loop is human,
 to recur divine
Erlang conditionals
always return a value
design for testability
don’t
 spawn,
use OTP
Downsides
Erlang changes very
       slowly
3rd party libraries
standard library
can be inconsistent
package
management
Questions
http://spkr8.com/t/7806
Phil: @philtoland
http://github.com/toland
http://philtoland.com

Mike: @lifeinzembla
http://github.com/msassak

Mais conteúdo relacionado

Mais procurados

Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
Deependra Ariyadewa
 
Advanced Hibernate Notes
Advanced Hibernate NotesAdvanced Hibernate Notes
Advanced Hibernate Notes
Kaniska Mandal
 
Building Smart Async Functions For Mobile
Building Smart Async Functions For MobileBuilding Smart Async Functions For Mobile
Building Smart Async Functions For Mobile
Glan Thomas
 

Mais procurados (20)

Python database interfaces
Python database  interfacesPython database  interfaces
Python database interfaces
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
 
Administering and Monitoring SolrCloud Clusters
Administering and Monitoring SolrCloud ClustersAdministering and Monitoring SolrCloud Clusters
Administering and Monitoring SolrCloud Clusters
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
12c db upgrade from 11.2.0.4
12c db upgrade from 11.2.0.412c db upgrade from 11.2.0.4
12c db upgrade from 11.2.0.4
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
 
Droidjam 2019 flutter isolates pdf
Droidjam 2019 flutter isolates pdfDroidjam 2019 flutter isolates pdf
Droidjam 2019 flutter isolates pdf
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
 
Advanced Hibernate Notes
Advanced Hibernate NotesAdvanced Hibernate Notes
Advanced Hibernate Notes
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
Query planner
Query plannerQuery planner
Query planner
 
An Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL TriggersAn Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL Triggers
 
Selectors and normalizing state shape
Selectors and normalizing state shapeSelectors and normalizing state shape
Selectors and normalizing state shape
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1
 
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
 
Clustering your Application with Hazelcast
Clustering your Application with HazelcastClustering your Application with Hazelcast
Clustering your Application with Hazelcast
 
Create & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxCreate & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptx
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
 
Building Smart Async Functions For Mobile
Building Smart Async Functions For MobileBuilding Smart Async Functions For Mobile
Building Smart Async Functions For Mobile
 

Destaque

International Institute For Franchise Education (Iife) Profile
International Institute For Franchise Education (Iife) ProfileInternational Institute For Franchise Education (Iife) Profile
International Institute For Franchise Education (Iife) Profile
guest719079
 

Destaque (7)

International Institute For Franchise Education (Iife) Profile
International Institute For Franchise Education (Iife) ProfileInternational Institute For Franchise Education (Iife) Profile
International Institute For Franchise Education (Iife) Profile
 
Digital Trends Among Digital Natives - Part II
Digital Trends Among Digital Natives - Part IIDigital Trends Among Digital Natives - Part II
Digital Trends Among Digital Natives - Part II
 
Ooops
OoopsOoops
Ooops
 
Blogs, Wikis And Mashups - Oh, My!
Blogs, Wikis And Mashups - Oh, My!Blogs, Wikis And Mashups - Oh, My!
Blogs, Wikis And Mashups - Oh, My!
 
Digital Trends: First Quarter 2011
Digital Trends: First Quarter 2011Digital Trends: First Quarter 2011
Digital Trends: First Quarter 2011
 
Onderwijsadviseurs; Jongleren met competenties
Onderwijsadviseurs; Jongleren met competentiesOnderwijsadviseurs; Jongleren met competenties
Onderwijsadviseurs; Jongleren met competenties
 
Growing up Digital
Growing up DigitalGrowing up Digital
Growing up Digital
 

Semelhante a Polyglot parallelism

Scale 16x: Terraform all the Things
Scale 16x: Terraform all the ThingsScale 16x: Terraform all the Things
Scale 16x: Terraform all the Things
Nathan Handler
 
Parallel programming patterns - Олександр Павлишак
Parallel programming patterns - Олександр ПавлишакParallel programming patterns - Олександр Павлишак
Parallel programming patterns - Олександр Павлишак
Igor Bronovskyy
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
Vaclav Pech
 

Semelhante a Polyglot parallelism (20)

PyCon 2010 SQLAlchemy tutorial
PyCon 2010 SQLAlchemy tutorialPyCon 2010 SQLAlchemy tutorial
PyCon 2010 SQLAlchemy tutorial
 
Scale 16x: Terraform all the Things
Scale 16x: Terraform all the ThingsScale 16x: Terraform all the Things
Scale 16x: Terraform all the Things
 
Tools for Making Machine Learning more Reactive
Tools for Making Machine Learning more ReactiveTools for Making Machine Learning more Reactive
Tools for Making Machine Learning more Reactive
 
ADF Gold Nuggets (Oracle Open World 2011)
ADF Gold Nuggets (Oracle Open World 2011)ADF Gold Nuggets (Oracle Open World 2011)
ADF Gold Nuggets (Oracle Open World 2011)
 
Parallel programming patterns (UA)
Parallel programming patterns (UA)Parallel programming patterns (UA)
Parallel programming patterns (UA)
 
Parallel programming patterns - Олександр Павлишак
Parallel programming patterns - Олександр ПавлишакParallel programming patterns - Олександр Павлишак
Parallel programming patterns - Олександр Павлишак
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Akka with Scala
Akka with ScalaAkka with Scala
Akka with Scala
 
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, EverAltitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
 
GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0
 
Let your DBAs get some REST(api)
Let your DBAs get some REST(api)Let your DBAs get some REST(api)
Let your DBAs get some REST(api)
 
Celery with python
Celery with pythonCelery with python
Celery with python
 
Event Sourcing - what could go wrong - Devoxx BE
Event Sourcing - what could go wrong - Devoxx BEEvent Sourcing - what could go wrong - Devoxx BE
Event Sourcing - what could go wrong - Devoxx BE
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)
 
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
 
Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Polyglot parallelism

Notas do Editor

  1. * Not an Erlang tutorial (but you will see some code)\n* Giving our experiences with Erlang + Ruby\n
  2. \n
  3. * Firewalls, load balancers\n\n
  4. * North America, Europe and Hong Kong\n* Everything runs from DC in Virginia\n* High latency to LON and HKG\n* ~5K devices in LON\n
  5. * Pass traffic like a pro\n* Individual devices won&amp;#x2019;t get faster\n\n\n
  6. * Backup all devices every 24 hours\n* Update devices during off hours\n\n
  7. * Newer devices have real management interfaces (give examples Junos, BigIP) but...\n* Majority of management happens via screen-scraping an SSH session\n* Pixen are slow and we have a lot of them\n\n
  8. \n
  9. \n
  10. * Lots of devices == lots of data\n
  11. * 260 GB of backups in old DB\n* We diff the backups to see if they have changed\n* We don&amp;#x2019;t want to be too clever\n * Err on the side of keeping too much rather than too little\n
  12. * Impossible to predict what combination of factors will lead to a need to search\n* Certain lb vendor had a vulnerability in SSH daemon\n* Had to search all firewall configs to find affected devices with SSH access allowed\n
  13. \n
  14. * Every event has different information that needs to be stored\n* Lots of events per device\n
  15. \n
  16. \n
  17. * Serial #, OS version, chassis details\n* Information is parsed from device output\n* We want to expose information useful to the business in one place\n\n
  18. * No accepted cross-vendor backup standard\n* We abstract information as &amp;#x201C;files&amp;#x201D;\n\n
  19. * 17K devices in 2009, ~21K now\n
  20. * What was in place in 2009\n
  21. * Rails and Ruby scripts\n* Overlapping responsibilities\n* Information silos\n* Difficult to change\n
  22. * concurrency with Ruby 1.8 threads\n * It is an I/O bound problem\n * Threads block on I/O\n* expect.rb has performance issues\n * Matching input one character at a time\n
  23. * Only one type of device\n* Small number of devices per manager\n* Expensive\n
  24. \n
  25. * Fully Buzzword-compliant!\n
  26. * No message queue\n* Poll MongoDB for some jobs\n* Schedule others in code\n* Very few writers to the database\n
  27. * Backend updates generally use MongoDB atomic updates\n* Need transactions for cross-collection modifications, but in-document can use atomic updates\n
  28. \n
  29. * You guys know Rails and have probably heard of mongodb\n* Take a minute to talk about Erlang\n
  30. * Ericsson Computer Science Laboratory\n* 1986: Joe Armstrong creates Erlang\n* 1988: Erlang escapes the lab\n* 1998: Erlang Released as Open Source\n\n
  31. * Developed for BT\n* 1.5 Million Lines of Erlang Code\n* 2 year evaluation\n* 9 9s of uptime\n
  32. * Erlang doesn&amp;#x2019;t guarantee 9 9s\n* Gives you the tools to make high uptime possible\n
  33. * Some core concepts are different than imperative/OO languages\n
  34. * Just like Ruby\n
  35. * Only assign to variables once\n* Allows flexible pattern matching and runtime assertions\n* &amp;#x201C;=&amp;#x201D; is the pattern match operator, not assignment\n
  36. * Variables are function-scoped, so single assignment is really a non-issue\n
  37. \n
  38. * Changing a data structure creates a new one\n* Purely Functional Data Structures - Okasaki\n
  39. \n
  40. * Concurrency built into the language, not an add-on\n
  41. \n
  42. \n
  43. * Two areas of interest: jobs framework and ReSTful API\n
  44. \n
  45. * Runner spins up multiple workers\n* Runner and workers are generic\n* Interesting work for each job is in callback module\n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. Example of how this solution made it easier to solve our problems\n\n* App running on two VMs and one developed problems\n* Moved all functionality to other node and rebuilt problematic VM\n* Doubled the workers on second VM with no detectable performance degradation\n\n
  53. * Occupies approximately the same position in your architecture as Rails controllers, but thoroughly exposes you to the details of the HTTP request/response\n* When you develop apps with Webmachine, you are basically writing a custom webserver for your API\n* And what are those details... &lt;transition to next slide&gt;\n\n
  54. * As seen through the eyes of Webmachine\n* Express API in terms of HTTP\n* Use HTTP as your domain language\n
  55. \n
  56. \n
  57. * A bit like Rails routing\n* First element (the &amp;#x201C;pathspec&amp;#x201D;) is a list that matches the request URL\n* Second element is the name of an Erlang module that exports the overridden callbacks\n* Third element is the args to the init function on the callback module\n
  58. * POEM - So far as I know, I coined this by accident\n* Why is the purity of functions important? predictability, testability, repeatability\n* You&amp;#x2019;ll usually override 4 or 5\n
  59. * Override only the parts of the request cycle that interest you, and Webmachine will do something reasonable for the other cases\n
  60. * Request parameter data is analogous to that contained in Rack::Request\n
  61. * Putting it all together\n* Previous callbacks stash data in the context (in this case a device record)\n\n
  62. \n
  63. * You can get far with Ruby&amp;#x2019;s &amp;#x201C;Big 3&amp;#x201D; datatypes: String, Array and Hash\n\n
  64. * Strings in Erlang are different\n* iolists are your friend\n
  65. * Proplists/records vs hashes\n\n
  66. * Erlang has internal iterators for lists (like each, etc)\n* No for loops, use recursion instead\n
  67. * if statements must always have an else\n* case statements raise an error if no branches match\n* pattern matching can replace some conditions\n\n
  68. * Erlang does not tolerate design mistakes as easily as Ruby\n* Pure vs impure functions\n* Pure is easy to test, IO is not your friend\n* Referential transparency\n* Dependency injection\n* Mocking is possible but not a panacea\n
  69. * You must understand the concurrency primitives\n* In general you should be using the OTP behaviors\n* If you use ORM you must understand SQL\n
  70. \n
  71. * Emphasis on stability over new features\n* New useful features in Erlang for years that community frowns upon\n * Undocumented with uncertain future\n
  72. * Standard library is very rich\n* 3rd party libraries tend to be immature\n
  73. * lists, proplists, binary and string\n* string has duplicate functionality\n * made from merging two older modules\n* lists and proplists have duplicated, overlapping functionality\n
  74. * agner, faxien, sinan, etc.\n
  75. * how did we get this adopted?\n* how do you find Erlang programmers?\n* why not Node.js, EventMachine or Ruby + sockets?\n
  76. \n