SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
COMBINING  THE  STRENGTHS  OF  
      ERLANG  AND  RUBY
      erlounge  Berlin  February  2012  –  Mar4n  Rehfeld
Game  Server  for  Upcoming  Wooga  Game

What  is  a  game  server?
• provide  HTTP  API  to  actual  game  („client“)
• validate  API  calls  against  current  state  &  game  logic
  • API  calls  will  modify  the  game  state
• make  game  state  persistent
Game  Server  for  Upcoming  Wooga  Game

It  will  be  a  stateful  game  server
• one  process  per  ac4ve  user  gaming  session
   • the  process  holds  the  current  state  and  is  the  only  one  that  can  modify  it  
       (strong  encapsula:on)
   • the  process  handles  all  API  calls  for  the  given  user  one  a=er  the  other  
       (concurrency  control  through  actor  model)
   • the  process  loads  the  game  state  from  storage  and  writes  it  back  
       periodically  and  on  process  termina:on  (:meout  =  user  stopped  playing)
Game  Server  for  Upcoming  Wooga  Game

Details  on  the  basic  idea:
Awesome  presenta4on  on  the
Magic  Land  game  server  by
@knu4n  &  @hungryblank
hZp://www.slideshare.net/wooga/from-­‐0-­‐to-­‐1000000-­‐daily-­‐users-­‐with-­‐erlang
Our  Goals

• Get  most  of  the  benefits  from  wooga’s  pure-­‐erlang  game  
  server  (Magic  Land)
  • especially  func:onal  approach  for  game  state  
     encapsula:on  and  transforma:on  +  concurrency  control
• But:  Keep  Object-­‐Oriented  approach  for  modelling  the  
  game  logic
Expected  OO-­‐Benefits

• Rapid  development
• concise  &  expressive  syntax
• leverage  exis4ng  know  how
• but:  keep  the  OO  part  stateless  and  side-­‐effect  free
  to  avoid  the  usual  traps  &  pidalls
Target  Architecture
                                                                                             Authority for:
                             Load Balancer
                                                                                  "What app server is responsible for
                                                                                          current session?"




           App Server Node                     App Server Node                              App Server Node


               Erlang VM                         Erlang VM                                    Erlang VM


                                                                            ...



      Ruby     Ruby       Ruby          Ruby      Ruby       Ruby                   Ruby       Ruby       Ruby
                      ...                                ...                                          ...
      Worker   Worker     Worker        Worker    Worker     Worker                 Worker     Worker     Worker




                                                   Shared Storage

                              for game state snapshots and for storing cold game sessions
Example  Game  Ac4on  in  Ruby
       URL

game_action '/:actor/fruit_tree/self/shake',
            :affects => [:fruit_trees, :user] do |response|

  x, y = params[:x], params[:y]
  fruit_trees[x, y].shake                      affected  parts  of
end
                                                the  game  state
• DSL-­‐like  defini4on  of  game  ac4on
• skinny  as  controllers  should  be  8-­‐)
Example  Model  in  Ruby
                                 Inheritance
class FruitTree < Tree
  property :last_shake_time, :type => Integer, :default => 0              DSL-­‐like  defini4on
  property :collectable_fruit_count, :type => Integer, :default => 0
                                                                          of  persistent  state
  def shake
    raise Error::Validation, "FruitTree at (#{x}, #{y}) has 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
erlang  talking  to  Ruby

Some  op4ons
• erlectricity  hZps://github.com/mojombo/erlectricity:
  Can  talk  erlang  binary  protocol  to  Ruby  processes  through  erlang  
  ports
• ernie  hZps://github.com/mojombo/ernie:
  Remote  func4on  call  using  the  BERT-­‐RPC  protocol  to  either  Ruby  or  
  na4ve  erlang  processes
• ZeroMQ  <hZp://www.zeromq.org/>:
  awesome  brokerless  queue  transport  layer,  connects  30+  languages
ZeroMQ

Pro                                    Con
• loose  coupling  of  erlang  and     • yet  another  layer
  Ruby  through  queues
  • easily  deploy  new  Ruby  
      code  without  touching  
      erlang
• allows  flexible  transports,  
  even  accross  machines
Connec4ng  the  Dots

• use  Mongrel2  hZp://mongrel2.org/  protocol  &  ZeroMQ  setup
• erlang:  emongrel2  hZps://github.com/hungryblank/emongrel2
• Ruby
  • rack-­‐mongrel2  fork  hEps://github.com/khiltd/khi-­‐rack-­‐mongrel2
  • rack  protocol  hEp://rack.rubyforge.org
  • Sinatra  hEp://www.sinatrarb.com/

➡ essen4ally  we  are  speaking  HTTP  over  ZeroMQ
  and  can  hook  up  any  Rack-­‐based  Ruby  web  framework
Setup  Overview



                 server                                 worker


       session                                          worker
                          sender     Push/Pull  Queue


                                        1:n             worker

       session
                                                        worker
        ...               receiver    Pub/Sub  Queue


                                        m:n              ...
       session
                                                        worker
How  does  the  game  state  look  like?

• Has  many  parts,  each  part  has  a  name  (e.g.  fruit_trees)  and  some  
   content
   • this  is  a  performance  op:miza:on,  so  that  we  don't  need  to  send  the  
      complete  state  back  and  forth  for  every  call
• erlang  does  not  care  about  the  content  (binary  data)
• actually  the  content  contains  serialized  objects  (e.g.  a  
   MapObjectCollection  containing  FruitTree  members)

• erlang  does  need  to  know,  what  game  ac4on  needs  what  state  parts
Looking  back  at  the  Game  Ac4on
game_action '/:actor/fruit_tree/self/shake',
            :affects => [:fruit_trees, :user] do |response|

  x, y = params[:x], params[:y]
  fruit_trees[x, y].shake                       affected  parts  of
end
                                                 the  game  state


• Ruby  knows  the  mapping  of  game  ac4ons  to  affected  state  parts
• pushes  the  mapping  on  startup  &  makes  it  available  on  request
Aside:  Efficient  Game  State  Access

• considered  different  serializa4on  formats  (e.g.  JSON,  
   MessagePack)
• especially  for  large  collec4ons  of  objects  we  wanted  to  avoid  
   parsing  everything  to  extract  a  single  object
• chose  TNetstrings  hZp://tnetstrings.org/  as  a  serializa4on  
   format  (length  prefix  helps  searching/lazy  parsing)
• built  a  lazy  parser/encoder  for  it    in  C  for  speed  :-­‐)
   hZps://github.com/wooga/lazy_tnetstring
Q  &  A

Mar4n  Rehfeld
 @klickmich

Mais conteúdo relacionado

Mais procurados

DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on InfinispanLance Ball
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011Lance Ball
 
Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled CucumbersJoseph Wilk
 
A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)Flowdock
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyBruno Oliveira
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaKeith Bennett
 
Java, Ruby & Rails
Java, Ruby & RailsJava, Ruby & Rails
Java, Ruby & RailsPeter Lind
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes BackBurke Libbey
 
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)ngotogenome
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterZendCon
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akkanartamonov
 
When Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the EnterpriseWhen Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the Enterprisebenbrowning
 
A tour of (advanced) Akka features in 40 minutes
A tour of (advanced) Akka features in 40 minutesA tour of (advanced) Akka features in 40 minutes
A tour of (advanced) Akka features in 40 minutesJohan Janssen
 
Automatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightAutomatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightGiuseppe Arici
 
Ruby 1.9 Fibers
Ruby 1.9 FibersRuby 1.9 Fibers
Ruby 1.9 FibersKevin Ball
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torqueboxrockyjaiswal
 

Mais procurados (18)

DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on Infinispan
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled Cucumbers
 
A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
 
Java, Ruby & Rails
Java, Ruby & RailsJava, Ruby & Rails
Java, Ruby & Rails
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
 
When Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the EnterpriseWhen Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the Enterprise
 
A tour of (advanced) Akka features in 40 minutes
A tour of (advanced) Akka features in 40 minutesA tour of (advanced) Akka features in 40 minutes
A tour of (advanced) Akka features in 40 minutes
 
Automatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightAutomatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma Night
 
Ruby 1.9 Fibers
Ruby 1.9 FibersRuby 1.9 Fibers
Ruby 1.9 Fibers
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torquebox
 

Destaque

Edayz09 Freebie Presentation
Edayz09 Freebie PresentationEdayz09 Freebie Presentation
Edayz09 Freebie Presentationozesteph1992
 
Day 1 Beginner Admin moodle
Day 1 Beginner Admin moodleDay 1 Beginner Admin moodle
Day 1 Beginner Admin moodleozesteph1992
 
Creating a precense in Moodle
Creating a precense in MoodleCreating a precense in Moodle
Creating a precense in Moodleozesteph1992
 
Wee @ social media II v2
Wee @ social media II v2Wee @ social media II v2
Wee @ social media II v2WEE
 
Interactive pdfs assessing in the field
Interactive pdfs assessing in the fieldInteractive pdfs assessing in the field
Interactive pdfs assessing in the fieldozesteph1992
 
潜力无限的编程语言Javascript
潜力无限的编程语言Javascript潜力无限的编程语言Javascript
潜力无限的编程语言Javascriptjay li
 
淘宝前端技术巡礼
淘宝前端技术巡礼淘宝前端技术巡礼
淘宝前端技术巡礼jay li
 
了解IO协议栈
了解IO协议栈了解IO协议栈
了解IO协议栈Feng Yu
 

Destaque (10)

How to use BbC
How to use BbCHow to use BbC
How to use BbC
 
Edayz09 Freebie Presentation
Edayz09 Freebie PresentationEdayz09 Freebie Presentation
Edayz09 Freebie Presentation
 
Day 1 Beginner Admin moodle
Day 1 Beginner Admin moodleDay 1 Beginner Admin moodle
Day 1 Beginner Admin moodle
 
Creating a precense in Moodle
Creating a precense in MoodleCreating a precense in Moodle
Creating a precense in Moodle
 
Wee @ social media II v2
Wee @ social media II v2Wee @ social media II v2
Wee @ social media II v2
 
V Zine Introductie
V Zine IntroductieV Zine Introductie
V Zine Introductie
 
Interactive pdfs assessing in the field
Interactive pdfs assessing in the fieldInteractive pdfs assessing in the field
Interactive pdfs assessing in the field
 
潜力无限的编程语言Javascript
潜力无限的编程语言Javascript潜力无限的编程语言Javascript
潜力无限的编程语言Javascript
 
淘宝前端技术巡礼
淘宝前端技术巡礼淘宝前端技术巡礼
淘宝前端技术巡礼
 
了解IO协议栈
了解IO协议栈了解IO协议栈
了解IO协议栈
 

Semelhante a Combining the strength of erlang and Ruby

At Scale With Style (Erlang User Conference 2012)
At Scale With Style (Erlang User Conference 2012)At Scale With Style (Erlang User Conference 2012)
At Scale With Style (Erlang User Conference 2012)Wooga
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and AkkaYung-Lin Ho
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.jsNitin Gupta
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesHiroshi SHIBATA
 
Erjang - A journey into Erlang-land
Erjang - A journey into Erlang-landErjang - A journey into Erlang-land
Erjang - A journey into Erlang-landKresten Krab Thorup
 
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...Paolo Negri
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Toolsguest05c09d
 
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangPractical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangLyon Yang
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationSuresh Kumar
 
Highly concurrent yet natural programming
Highly concurrent yet natural programmingHighly concurrent yet natural programming
Highly concurrent yet natural programmingInfinit
 
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David ShawBeginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David ShawRedspin, Inc.
 
meetPHP#8 - PHP startups prototypes
meetPHP#8 - PHP startups prototypesmeetPHP#8 - PHP startups prototypes
meetPHP#8 - PHP startups prototypesMax Małecki
 
Erlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldErlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldZvi Avraham
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)OpenBlend society
 
How Yelp does Service Discovery
How Yelp does Service DiscoveryHow Yelp does Service Discovery
How Yelp does Service DiscoveryJohn Billings
 

Semelhante a Combining the strength of erlang and Ruby (20)

At Scale With Style (Erlang User Conference 2012)
At Scale With Style (Erlang User Conference 2012)At Scale With Style (Erlang User Conference 2012)
At Scale With Style (Erlang User Conference 2012)
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.js
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
 
Erjang - A journey into Erlang-land
Erjang - A journey into Erlang-landErjang - A journey into Erlang-land
Erjang - A journey into Erlang-land
 
mtl_rubykaigi
mtl_rubykaigimtl_rubykaigi
mtl_rubykaigi
 
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
 
Ansible - A 'crowd' introduction
Ansible - A 'crowd' introductionAnsible - A 'crowd' introduction
Ansible - A 'crowd' introduction
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Tools
 
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangPractical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Egearmand: an Erlang Gearman daemon
Egearmand: an Erlang Gearman daemonEgearmand: an Erlang Gearman daemon
Egearmand: an Erlang Gearman daemon
 
Rooster Tech Talk
Rooster Tech TalkRooster Tech Talk
Rooster Tech Talk
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Highly concurrent yet natural programming
Highly concurrent yet natural programmingHighly concurrent yet natural programming
Highly concurrent yet natural programming
 
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David ShawBeginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
 
meetPHP#8 - PHP startups prototypes
meetPHP#8 - PHP startups prototypesmeetPHP#8 - PHP startups prototypes
meetPHP#8 - PHP startups prototypes
 
Erlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldErlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent World
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
 
How Yelp does Service Discovery
How Yelp does Service DiscoveryHow Yelp does Service Discovery
How Yelp does Service Discovery
 

Último

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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 AutomationSafe Software
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
[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.pdfhans926745
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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 MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
[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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Combining the strength of erlang and Ruby

  • 1. COMBINING  THE  STRENGTHS  OF   ERLANG  AND  RUBY erlounge  Berlin  February  2012  –  Mar4n  Rehfeld
  • 2. Game  Server  for  Upcoming  Wooga  Game What  is  a  game  server? • provide  HTTP  API  to  actual  game  („client“) • validate  API  calls  against  current  state  &  game  logic • API  calls  will  modify  the  game  state • make  game  state  persistent
  • 3. Game  Server  for  Upcoming  Wooga  Game It  will  be  a  stateful  game  server • one  process  per  ac4ve  user  gaming  session • the  process  holds  the  current  state  and  is  the  only  one  that  can  modify  it   (strong  encapsula:on) • the  process  handles  all  API  calls  for  the  given  user  one  a=er  the  other   (concurrency  control  through  actor  model) • the  process  loads  the  game  state  from  storage  and  writes  it  back   periodically  and  on  process  termina:on  (:meout  =  user  stopped  playing)
  • 4. Game  Server  for  Upcoming  Wooga  Game Details  on  the  basic  idea: Awesome  presenta4on  on  the Magic  Land  game  server  by @knu4n  &  @hungryblank hZp://www.slideshare.net/wooga/from-­‐0-­‐to-­‐1000000-­‐daily-­‐users-­‐with-­‐erlang
  • 5. Our  Goals • Get  most  of  the  benefits  from  wooga’s  pure-­‐erlang  game   server  (Magic  Land) • especially  func:onal  approach  for  game  state   encapsula:on  and  transforma:on  +  concurrency  control • But:  Keep  Object-­‐Oriented  approach  for  modelling  the   game  logic
  • 6. Expected  OO-­‐Benefits • Rapid  development • concise  &  expressive  syntax • leverage  exis4ng  know  how • but:  keep  the  OO  part  stateless  and  side-­‐effect  free to  avoid  the  usual  traps  &  pidalls
  • 7. Target  Architecture Authority for: Load Balancer "What app server is responsible for current session?" App Server Node App Server Node App Server Node Erlang VM Erlang VM Erlang VM ... Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby ... ... ... Worker Worker Worker Worker Worker Worker Worker Worker Worker Shared Storage for game state snapshots and for storing cold game sessions
  • 8. Example  Game  Ac4on  in  Ruby URL game_action '/:actor/fruit_tree/self/shake', :affects => [:fruit_trees, :user] do |response| x, y = params[:x], params[:y] fruit_trees[x, y].shake affected  parts  of end the  game  state • DSL-­‐like  defini4on  of  game  ac4on • skinny  as  controllers  should  be  8-­‐)
  • 9. Example  Model  in  Ruby Inheritance class FruitTree < Tree property :last_shake_time, :type => Integer, :default => 0 DSL-­‐like  defini4on property :collectable_fruit_count, :type => Integer, :default => 0 of  persistent  state def shake raise Error::Validation, "FruitTree at (#{x}, #{y}) has 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
  • 10. erlang  talking  to  Ruby Some  op4ons • erlectricity  hZps://github.com/mojombo/erlectricity: Can  talk  erlang  binary  protocol  to  Ruby  processes  through  erlang   ports • ernie  hZps://github.com/mojombo/ernie: Remote  func4on  call  using  the  BERT-­‐RPC  protocol  to  either  Ruby  or   na4ve  erlang  processes • ZeroMQ  <hZp://www.zeromq.org/>: awesome  brokerless  queue  transport  layer,  connects  30+  languages
  • 11. ZeroMQ Pro Con • loose  coupling  of  erlang  and   • yet  another  layer Ruby  through  queues • easily  deploy  new  Ruby   code  without  touching   erlang • allows  flexible  transports,   even  accross  machines
  • 12. Connec4ng  the  Dots • use  Mongrel2  hZp://mongrel2.org/  protocol  &  ZeroMQ  setup • erlang:  emongrel2  hZps://github.com/hungryblank/emongrel2 • Ruby • rack-­‐mongrel2  fork  hEps://github.com/khiltd/khi-­‐rack-­‐mongrel2 • rack  protocol  hEp://rack.rubyforge.org • Sinatra  hEp://www.sinatrarb.com/ ➡ essen4ally  we  are  speaking  HTTP  over  ZeroMQ and  can  hook  up  any  Rack-­‐based  Ruby  web  framework
  • 13. Setup  Overview server worker session worker sender Push/Pull  Queue 1:n worker session worker ... receiver Pub/Sub  Queue m:n ... session worker
  • 14. How  does  the  game  state  look  like? • Has  many  parts,  each  part  has  a  name  (e.g.  fruit_trees)  and  some   content • this  is  a  performance  op:miza:on,  so  that  we  don't  need  to  send  the   complete  state  back  and  forth  for  every  call • erlang  does  not  care  about  the  content  (binary  data) • actually  the  content  contains  serialized  objects  (e.g.  a   MapObjectCollection  containing  FruitTree  members) • erlang  does  need  to  know,  what  game  ac4on  needs  what  state  parts
  • 15. Looking  back  at  the  Game  Ac4on game_action '/:actor/fruit_tree/self/shake', :affects => [:fruit_trees, :user] do |response| x, y = params[:x], params[:y] fruit_trees[x, y].shake affected  parts  of end the  game  state • Ruby  knows  the  mapping  of  game  ac4ons  to  affected  state  parts • pushes  the  mapping  on  startup  &  makes  it  available  on  request
  • 16. Aside:  Efficient  Game  State  Access • considered  different  serializa4on  formats  (e.g.  JSON,   MessagePack) • especially  for  large  collec4ons  of  objects  we  wanted  to  avoid   parsing  everything  to  extract  a  single  object • chose  TNetstrings  hZp://tnetstrings.org/  as  a  serializa4on   format  (length  prefix  helps  searching/lazy  parsing) • built  a  lazy  parser/encoder  for  it    in  C  for  speed  :-­‐) hZps://github.com/wooga/lazy_tnetstring
  • 17. Q  &  A Mar4n  Rehfeld @klickmich