SlideShare a Scribd company logo
AT	
  SCALE	
  WITH	
  STYLE
                      Erlang	
  <3	
  <3	
  <3	
  Ruby




Mar$n	
  Rehfeld,	
  @klickmich
At	
  Scale	
  With	
  Style

 How	
  we	
  roll

 Server	
  architectures

 How	
  to	
  innovate

 Mind	
  the	
  limits
At Scale With Style (Erlang User Conference 2012)
Typical	
  game	
  architecture

         Client         HTTP      Backend
                         API
Typical	
  game	
  architecture

                                  Backend




     State	
  Changes
       ValidaHon
      Persistence
The	
  scale	
  is	
  interesHng


              14	
  billion	
  requests	
  /	
  month



          >100,000	
  DB	
  operaHons	
  /	
  second



             >50,000	
  DB	
  updates	
  /	
  second
Wooga’s	
  approach	
  to	
  development

Small	
  independent	
  teams	
  for	
  each	
  game

Team	
  gets	
  to	
  choose	
  tools	
  and	
  technologies
  Same	
  team	
  also	
  does	
  ops	
  a,er	
  going	
  live

Culture	
  of	
  sharing
  Look	
  around	
  what	
  is	
  there,	
  pick/adapt	
  exis;ng	
  
   solu;ons,	
  but	
  take	
  ownership	
  for	
  what	
  you	
  
   include
ExisHng	
  backends	
  –	
  Technology	
  landscape
At	
  Scale	
  With	
  Style

 How	
  we	
  roll

 Server	
  architectures

 How	
  to	
  innovate

 Mind	
  the	
  limits
Most	
  games	
  use	
  stateless	
  applicaHon	
  servers

         Server                          Database
And	
  then	
  there’s	
  sharding

                                  lb




        app   app   app   app     app    app    app   app   app




                          My            My
                          SQL           SQL


                          slave         slave
More	
  app	
  servers,	
  more	
  sharding

                                              lb




            app         app     app   app     app   app     app      app         app


            app     app         app   app     app   app     app      app         app




    My            My          My      My            My       My            My          My
    SQL           SQL         SQL     SQL           SQL      SQL           SQL         SQL


    slave     slave           slave   slave         slave    slave     slave           slave
Wait,	
  seriously?!

                                               lb         lb


app     app      app     app     app   app          app        app     app      app   app     app   app


app     app      app     app     app   app          app        app     app      app   app     app   app


app     app      app     app     app   app          app        app     app      app   app     app   app


My       My            My      My      My
                                                               redis    redis     redis     redis   redis
SQL      SQL           SQL     SQL     SQL


slave    slave     slave       slave   slave                   slave    slave     slave     slave   slave
Find	
  the	
  flaw

 “Stateless	
  applicaHon	
  servers	
  
      guarantee	
  one	
  thing:
       The	
  data	
  is	
  never
      where	
  you	
  need	
  it!”
          Paolo	
  Negri,	
  Developer	
  @	
  Wooga
Strong	
  session	
  pa`ern


   User	
  starts	
  playing

     many	
  transformaHons
     of	
  the	
  same	
  set	
  of	
  data


   User	
  stops	
  playing
Stateful	
  servers	
  and	
  DBs

          Server                              Database




                     One	
  Game	
  Session
Stateful	
  game	
  server

One	
  process	
  per	
  acHve	
  user	
  gaming	
  session

    ...	
  holds	
  the	
  current	
  state	
  and	
  is	
  the	
  only	
  one	
  that	
  can	
  
         modify	
  it	
  (strong	
  encapsulaHon)

    ...	
  handles	
  all	
  API	
  calls	
  for	
  the	
  given	
  user	
  one	
  a,er	
  the	
  other	
  
         (concurrency	
  control	
  through	
  actor	
  model)

    ...	
  loads	
  the	
  game	
  state	
  from	
  storage	
  and	
  writes	
  it	
  back	
  
         periodically	
  and	
  on	
  process	
  termina;on
         (;meout	
  =	
  user	
  stopped	
  playing)
The	
  DB	
  is	
  no	
  longer	
  the	
  bo`leneck


                     Stateless                     Stateful

  30.000
  22.500
  15.000
                                                   700
   7.500
        0
                      DB	
  operations	
  /	
  second
Magic	
  Land	
  uses	
  Erlang

Details:
Awesome	
  presentaHon	
  on
the	
  Magic	
  Land	
  game	
  server
by	
  @knuHn	
  &	
  @hungryblank


h`p://www.slideshare.net/wooga/from-­‐0-­‐to-­‐1000000-­‐daily-­‐users-­‐with-­‐erlang
At	
  Scale	
  With	
  Style

 How	
  we	
  roll

 Server	
  architectures

 How	
  to	
  innovate

 Mind	
  the	
  limits
At Scale With Style (Erlang User Conference 2012)
Erlang	
  &	
  Ruby

Erlang	
  is	
  great
   Concurrent,	
  robust
   Great	
  for	
  opera;on

Ruby	
  is	
  great
  Concise,	
  expressive,	
  flexible
  Great	
  for	
  development
At Scale With Style (Erlang User Conference 2012)
Bringing	
  two	
  worlds	
  together




                 Server                 Worker

       session
                          sender        Worker

       session
                                        Worker

         ...
                                        Worker
                          receiver
       session
                                        Worker
Do	
  you	
  know	
  Mongrel2?

                          Web	
  Server	
  that	
  hooks
                          up	
  applicaHons	
  via


➡ We	
  chose	
  the	
  same	
  queue	
  setup	
  &	
  
  message	
  format
                                            Server              Worker

                                  session

                                                     sender
                                                                Worker

                                  session
                                                                Worker

                                    ...
                                                                Worker
                                                     receiver


                                  session
                                                                Worker
At Scale With Style (Erlang User Conference 2012)
ConnecHng	
  the	
  dots

Mongrel2	
  h`p://mongrel2.org/	
  protocol	
  &	
  ZeroMQ	
  setup
Erlang:	
  h`ps://github.com/hungryblank/emongrel2
Ruby
    rack-­‐mongrel2	
  fork	
  hKps://github.com/khiltd/khi-­‐rack-­‐mongrel2
    rack	
  protocol	
  hKp://rack.rubyforge.org
    Sinatra	
  hKp://www.sinatrarb.com/


➡      essenHally	
  we	
  are	
  speaking	
  HTTP	
  over	
  ZeroMQ
       and	
  can	
  hook	
  up	
  any	
  Rack-­‐based	
  Ruby	
  web	
  
       framework
Example	
  controller	
  in	
  Ruby
  app.game_action '/:actor/fruit_tree/self/shake',
                  :observable => true,
                  :affects => [:fruit_trees, :user],
                  :params => [:x, :y] do

    x, y = params[:x], params[:y]
    fruit_trees[x, y].shake

 end




DSL-­‐like	
  definiHon	
  of	
  game	
  acHon
Skinny	
  as	
  controllers	
  should	
  be
Example	
  model	
  in	
  Ruby
  class FruitTree < Tree

    property :last_shake_time,         :type => Integer, :default => 0
    property :collectable_fruit_count, :type => Integer, :default => 0

    def shake
      raise G8::Error::Validation, "no fruit!" unless carries_fruit?

      session.user.xp += 1
      session.user.energy -= 1
      self.last_shake_time = game_time
      self.collectable_fruit_count = config.fruit_count
    end

  end


Easily	
  unit	
  testable
Minimal	
  amount	
  of	
  code
Game	
  state

Game	
  state	
  is	
  split	
  in	
  mulHple	
  parts
  user,	
  map,	
  fruit_trees	
  etc.

Erlang	
  does	
  not	
  care	
  about	
  content
   Serialized	
  Ruby	
  objects

Erlang	
  does	
  know	
  mapping	
  of	
  state	
  parts	
  to	
  URLs
Looking	
  back	
  at	
  the	
  game	
  acHon
app.game_action '/:actor/fruit_tree/self/shake',
                :observable => true,
                :affects => [:fruit_trees, :user],
                :params => [:x, :y] do

  x, y = params[:x], params[:y]
  fruit_trees[x, y].shake
end



Mapping	
  of	
  state	
  parts	
  to	
  game	
  acHons
  Worker	
  knows	
  mapping
  Worker	
  pushes	
  mapping	
  to	
  Erlang	
  on	
  startup
  Erlang	
  can	
  query	
  mapping	
  if	
  needed
NICE!
        http://www.flickr.com/photos/aigle_dore/
At	
  Scale	
  With	
  Style

 How	
  we	
  roll

 Server	
  architectures

 How	
  to	
  innovate

 Mind	
  the	
  limits
Performance	
  impact	
  for	
  large	
  payloads
                                200	
  kB	
  payload
                     6000

                     5000
Requests	
  /	
  s




                     4000
                                                            Pure
                     3000                                  Erlang
                     2000
                                                            Ruby
                     1000                                   ZMQ
                                                           400	
  rps
                       0
                            1     #	
  of	
  workers   8
NOT	
  CPU	
  bound




25%



         Fixed	
  bandwith	
  limit	
  @	
  300	
  MB/s
This	
  has	
  happened	
  before
2,000,000"




1,500,000"




1,000,000"




 500,000"




        0"
        Apr*10"   Jul*10"   Oct*10"   Jan*11"   Apr*11"   Jul*11"   Oct*11"
At Scale With Style (Erlang User Conference 2012)
Example	
  controller	
  in	
  Erlang

  shake(Args, State) ->
      Coords      = g8_map:coords(Args),
      Map         = g8_game:get_map(State),
      Tree        = g8_map:find(Coords, Map),

      NewTree     = g8_fruit_tree:shake(Tree),
      UserEffects = [incr_xp, decr_energy],
      NewMap      = g8_map:place(Coords, NewTree, Map),

      [observable,
       {state, g8_game:set_map(NewMap,
                 g8_user:apply(UserEffects, State))}].
Example	
  model	
  in	
  Erlang

  shake(Tree) ->
      validate_carries_fruit(Tree),

      FruitCount = g8_fruit_tree_config:fruit_count(Tree),
      Tree#fruit_tree{last_shake_time = g8_game:gametime(),
                      collectable_fruit_count = FruitCount}.
✓ Y ES
QuesHons?

   MarHn	
  Rehfeld
    @klickmich

slideshare.net/wooga
   wooga.com/jobs

More Related Content

PDF
At Scale With Style
PDF
Combining the strength of erlang and Ruby
PDF
A Tale of a Server Architecture (Frozen Rails 2012)
PPTX
Java 7 Whats New(), Whats Next() from Oredev
ODP
Open Source Compiler Construction for the JVM
PDF
Rocket Fuelled Cucumbers
PDF
TorqueBox for Rubyists
PDF
TorqueBox at DC:JBUG - November 2011
At Scale With Style
Combining the strength of erlang and Ruby
A Tale of a Server Architecture (Frozen Rails 2012)
Java 7 Whats New(), Whats Next() from Oredev
Open Source Compiler Construction for the JVM
Rocket Fuelled Cucumbers
TorqueBox for Rubyists
TorqueBox at DC:JBUG - November 2011

What's hot (18)

PDF
DataMapper on Infinispan
PDF
.NET Architects Day - DNAD 2011
PPT
Java, Ruby & Rails
PDF
Smart Client Development
KEY
TorqueBox - Ruby Hoedown 2011
PDF
Complex Made Simple: Sleep Better with TorqueBox
KEY
Devignition 2011
KEY
Jruby synergy-of-ruby-and-java
PPTX
JUDCon London 2011 - Elastic SOA on the Cloud, Steve Millidge
PDF
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
ZIP
Above the clouds: introducing Akka
PDF
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
ODP
Pfm technical-inside
ZIP
My sql replication advanced techniques presentation
PDF
Ruby for C#-ers (ScanDevConf 2010)
KEY
Ruby on Rails Training - Module 1
PDF
A tour of (advanced) Akka features in 40 minutes
KEY
When Two Worlds Collide: Java and Ruby in the Enterprise
DataMapper on Infinispan
.NET Architects Day - DNAD 2011
Java, Ruby & Rails
Smart Client Development
TorqueBox - Ruby Hoedown 2011
Complex Made Simple: Sleep Better with TorqueBox
Devignition 2011
Jruby synergy-of-ruby-and-java
JUDCon London 2011 - Elastic SOA on the Cloud, Steve Millidge
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
Above the clouds: introducing Akka
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
Pfm technical-inside
My sql replication advanced techniques presentation
Ruby for C#-ers (ScanDevConf 2010)
Ruby on Rails Training - Module 1
A tour of (advanced) Akka features in 40 minutes
When Two Worlds Collide: Java and Ruby in the Enterprise
Ad

Similar to At Scale With Style (Erlang User Conference 2012) (20)

PDF
Combining the Strengths or Erlang and Ruby
PDF
Games for the Masses (Jax)
KEY
Polyglot parallelism
PDF
O que tem de novo no Ruby 2.0?
PDF
Erlang as a Cloud Citizen
PDF
Erlang as a cloud citizen, a fractal approach to throughput
PDF
Erlang and the Cloud: A Fractal Approach to Throughput
KEY
Redis, Resque & Friends
PDF
Games for the Masses (QCon London 2012)
PDF
SCALE 10x Build a Cloud Day
PDF
Agile Seaside
PDF
Seaside — Agile Software Development
PPT
Large-scale projects development (scaling LAMP)
PDF
Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)
PDF
BruCON 2010 Lightning Talks - DIY Grid Computing
PDF
Server Tips
PDF
Lindsay distributed geventzmq
PDF
Why Erlang? - Bar Camp Atlanta 2008
PPTX
Usenix lisa 2011
PDF
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Combining the Strengths or Erlang and Ruby
Games for the Masses (Jax)
Polyglot parallelism
O que tem de novo no Ruby 2.0?
Erlang as a Cloud Citizen
Erlang as a cloud citizen, a fractal approach to throughput
Erlang and the Cloud: A Fractal Approach to Throughput
Redis, Resque & Friends
Games for the Masses (QCon London 2012)
SCALE 10x Build a Cloud Day
Agile Seaside
Seaside — Agile Software Development
Large-scale projects development (scaling LAMP)
Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)
BruCON 2010 Lightning Talks - DIY Grid Computing
Server Tips
Lindsay distributed geventzmq
Why Erlang? - Bar Camp Atlanta 2008
Usenix lisa 2011
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Ad

More from Wooga (20)

PPTX
Story of Warlords: Bringing a turn-based strategy game to mobile
PDF
Instagram Celebrities: are they the new cats? - Targetsummit Berlin 2015
PDF
In it for the long haul - How Wooga boosts long-term retention
PDF
Leveling up in localization! - Susan Alma & Dario Quondamstefano
PDF
Evoloution of Ideas
PDF
Entitas System Architecture with Unity - Maxim Zaks and Simon Schmid
PDF
Saying No to the CEO: A Deep Look at Independent Teams - Adam Telfer
PDF
Innovation dank DevOps (DevOpsCon Berlin 2015)
PDF
Big Fish, small pond - strategies for surviving in a maturing market - Ed Biden
PDF
Review mining aps2014 berlin
PDF
Riak & Wooga_Geeek2Geeek Meetup2014 Berlin
PDF
Staying in the Game: Game localization practices for the mobile market
PDF
Startup Weekend_Makers and Games_Philipp Stelzer
PDF
DevOps goes Mobile (daho.am)
PDF
DevOps goes Mobile - Jax 2014 - Jesper Richter-Reichhelm
PDF
CodeFest 2014_Mobile Game Development
PDF
Jelly Splash: Puzzling your way to the top of the App Stores - GDC 2014
PDF
How to hire the best people for your startup-Gitta Blat-Head of People
PDF
Two Ann(e)s and one Julia_Wooga Lady Power from Berlin_SGA2014
PDF
Pocket Gamer Connects 2014_The Experience of Entering the Korean Market
Story of Warlords: Bringing a turn-based strategy game to mobile
Instagram Celebrities: are they the new cats? - Targetsummit Berlin 2015
In it for the long haul - How Wooga boosts long-term retention
Leveling up in localization! - Susan Alma & Dario Quondamstefano
Evoloution of Ideas
Entitas System Architecture with Unity - Maxim Zaks and Simon Schmid
Saying No to the CEO: A Deep Look at Independent Teams - Adam Telfer
Innovation dank DevOps (DevOpsCon Berlin 2015)
Big Fish, small pond - strategies for surviving in a maturing market - Ed Biden
Review mining aps2014 berlin
Riak & Wooga_Geeek2Geeek Meetup2014 Berlin
Staying in the Game: Game localization practices for the mobile market
Startup Weekend_Makers and Games_Philipp Stelzer
DevOps goes Mobile (daho.am)
DevOps goes Mobile - Jax 2014 - Jesper Richter-Reichhelm
CodeFest 2014_Mobile Game Development
Jelly Splash: Puzzling your way to the top of the App Stores - GDC 2014
How to hire the best people for your startup-Gitta Blat-Head of People
Two Ann(e)s and one Julia_Wooga Lady Power from Berlin_SGA2014
Pocket Gamer Connects 2014_The Experience of Entering the Korean Market

Recently uploaded (20)

PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation theory and applications.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Mushroom cultivation and it's methods.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
A Presentation on Artificial Intelligence
Encapsulation theory and applications.pdf
A comparative study of natural language inference in Swahili using monolingua...
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation_ Review paper, used for researhc scholars
Programs and apps: productivity, graphics, security and other tools
Mushroom cultivation and it's methods.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
Accuracy of neural networks in brain wave diagnosis of schizophrenia
SOPHOS-XG Firewall Administrator PPT.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Unlocking AI with Model Context Protocol (MCP)
Univ-Connecticut-ChatGPT-Presentaion.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Agricultural_Statistics_at_a_Glance_2022_0.pdf

At Scale With Style (Erlang User Conference 2012)

  • 1. AT  SCALE  WITH  STYLE Erlang  <3  <3  <3  Ruby Mar$n  Rehfeld,  @klickmich
  • 2. At  Scale  With  Style How  we  roll Server  architectures How  to  innovate Mind  the  limits
  • 4. Typical  game  architecture Client HTTP Backend API
  • 5. Typical  game  architecture Backend State  Changes ValidaHon Persistence
  • 6. The  scale  is  interesHng 14  billion  requests  /  month >100,000  DB  operaHons  /  second >50,000  DB  updates  /  second
  • 7. Wooga’s  approach  to  development Small  independent  teams  for  each  game Team  gets  to  choose  tools  and  technologies Same  team  also  does  ops  a,er  going  live Culture  of  sharing Look  around  what  is  there,  pick/adapt  exis;ng   solu;ons,  but  take  ownership  for  what  you   include
  • 8. ExisHng  backends  –  Technology  landscape
  • 9. At  Scale  With  Style How  we  roll Server  architectures How  to  innovate Mind  the  limits
  • 10. Most  games  use  stateless  applicaHon  servers Server Database
  • 11. And  then  there’s  sharding lb app app app app app app app app app My My SQL SQL slave slave
  • 12. More  app  servers,  more  sharding lb app app app app app app app app app app app app app app app app app app My My My My My My My My SQL SQL SQL SQL SQL SQL SQL SQL slave slave slave slave slave slave slave slave
  • 13. Wait,  seriously?! lb lb app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app My My My My My redis redis redis redis redis SQL SQL SQL SQL SQL slave slave slave slave slave slave slave slave slave slave
  • 14. Find  the  flaw “Stateless  applicaHon  servers   guarantee  one  thing: The  data  is  never where  you  need  it!” Paolo  Negri,  Developer  @  Wooga
  • 15. Strong  session  pa`ern User  starts  playing many  transformaHons of  the  same  set  of  data User  stops  playing
  • 16. Stateful  servers  and  DBs Server Database One  Game  Session
  • 17. Stateful  game  server One  process  per  acHve  user  gaming  session ...  holds  the  current  state  and  is  the  only  one  that  can   modify  it  (strong  encapsulaHon) ...  handles  all  API  calls  for  the  given  user  one  a,er  the  other   (concurrency  control  through  actor  model) ...  loads  the  game  state  from  storage  and  writes  it  back   periodically  and  on  process  termina;on (;meout  =  user  stopped  playing)
  • 18. The  DB  is  no  longer  the  bo`leneck Stateless Stateful 30.000 22.500 15.000 700 7.500 0 DB  operations  /  second
  • 19. Magic  Land  uses  Erlang Details: Awesome  presentaHon  on the  Magic  Land  game  server by  @knuHn  &  @hungryblank h`p://www.slideshare.net/wooga/from-­‐0-­‐to-­‐1000000-­‐daily-­‐users-­‐with-­‐erlang
  • 20. At  Scale  With  Style How  we  roll Server  architectures How  to  innovate Mind  the  limits
  • 22. Erlang  &  Ruby Erlang  is  great Concurrent,  robust Great  for  opera;on Ruby  is  great Concise,  expressive,  flexible Great  for  development
  • 24. Bringing  two  worlds  together Server Worker session sender Worker session Worker ... Worker receiver session Worker
  • 25. Do  you  know  Mongrel2? Web  Server  that  hooks up  applicaHons  via ➡ We  chose  the  same  queue  setup  &   message  format Server Worker session sender Worker session Worker ... Worker receiver session Worker
  • 27. ConnecHng  the  dots Mongrel2  h`p://mongrel2.org/  protocol  &  ZeroMQ  setup Erlang:  h`ps://github.com/hungryblank/emongrel2 Ruby rack-­‐mongrel2  fork  hKps://github.com/khiltd/khi-­‐rack-­‐mongrel2 rack  protocol  hKp://rack.rubyforge.org Sinatra  hKp://www.sinatrarb.com/ ➡ essenHally  we  are  speaking  HTTP  over  ZeroMQ and  can  hook  up  any  Rack-­‐based  Ruby  web   framework
  • 28. Example  controller  in  Ruby app.game_action '/:actor/fruit_tree/self/shake', :observable => true, :affects => [:fruit_trees, :user], :params => [:x, :y] do x, y = params[:x], params[:y] fruit_trees[x, y].shake end DSL-­‐like  definiHon  of  game  acHon Skinny  as  controllers  should  be
  • 29. Example  model  in  Ruby class FruitTree < Tree property :last_shake_time, :type => Integer, :default => 0 property :collectable_fruit_count, :type => Integer, :default => 0 def shake raise G8::Error::Validation, "no fruit!" unless carries_fruit? session.user.xp += 1 session.user.energy -= 1 self.last_shake_time = game_time self.collectable_fruit_count = config.fruit_count end end Easily  unit  testable Minimal  amount  of  code
  • 30. Game  state Game  state  is  split  in  mulHple  parts user,  map,  fruit_trees  etc. Erlang  does  not  care  about  content Serialized  Ruby  objects Erlang  does  know  mapping  of  state  parts  to  URLs
  • 31. Looking  back  at  the  game  acHon app.game_action '/:actor/fruit_tree/self/shake', :observable => true, :affects => [:fruit_trees, :user], :params => [:x, :y] do x, y = params[:x], params[:y] fruit_trees[x, y].shake end Mapping  of  state  parts  to  game  acHons Worker  knows  mapping Worker  pushes  mapping  to  Erlang  on  startup Erlang  can  query  mapping  if  needed
  • 32. NICE! http://www.flickr.com/photos/aigle_dore/
  • 33. At  Scale  With  Style How  we  roll Server  architectures How  to  innovate Mind  the  limits
  • 34. Performance  impact  for  large  payloads 200  kB  payload 6000 5000 Requests  /  s 4000 Pure 3000 Erlang 2000 Ruby 1000 ZMQ 400  rps 0 1 #  of  workers 8
  • 35. NOT  CPU  bound 25% Fixed  bandwith  limit  @  300  MB/s
  • 36. This  has  happened  before 2,000,000" 1,500,000" 1,000,000" 500,000" 0" Apr*10" Jul*10" Oct*10" Jan*11" Apr*11" Jul*11" Oct*11"
  • 38. Example  controller  in  Erlang shake(Args, State) -> Coords = g8_map:coords(Args), Map = g8_game:get_map(State), Tree = g8_map:find(Coords, Map), NewTree = g8_fruit_tree:shake(Tree), UserEffects = [incr_xp, decr_energy], NewMap = g8_map:place(Coords, NewTree, Map), [observable, {state, g8_game:set_map(NewMap, g8_user:apply(UserEffects, State))}].
  • 39. Example  model  in  Erlang shake(Tree) -> validate_carries_fruit(Tree), FruitCount = g8_fruit_tree_config:fruit_count(Tree), Tree#fruit_tree{last_shake_time = g8_game:gametime(), collectable_fruit_count = FruitCount}.
  • 41. QuesHons? MarHn  Rehfeld @klickmich slideshare.net/wooga wooga.com/jobs