Combining the strength of erlang and Ruby

Martin Rehfeld
Martin RehfeldIT Consultant en GL Networks
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
1 de 17

Recomendados

At Scale With Style por
At Scale With StyleAt Scale With Style
At Scale With StyleMartin Rehfeld
1.7K vistas41 diapositivas
Open Source Compiler Construction for the JVM por
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMTom Lee
1.2K vistas14 diapositivas
Oow 2009 Towards A Universal Vm por
Oow 2009 Towards A Universal VmOow 2009 Towards A Universal Vm
Oow 2009 Towards A Universal VmJose García
1.4K vistas39 diapositivas
TorqueBox for Rubyists por
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyistsbobmcwhirter
961 vistas84 diapositivas
Java 7 Whats New(), Whats Next() from Oredev por
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
2.2K vistas84 diapositivas
TorqueBox at DC:JBUG - November 2011 por
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011bobmcwhirter
767 vistas98 diapositivas

Más contenido relacionado

La actualidad más candente

Pfm technical-inside por
Pfm technical-insidePfm technical-inside
Pfm technical-insideiyatomi takehiro
889 vistas45 diapositivas
DataMapper on Infinispan por
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on InfinispanLance Ball
2.4K vistas62 diapositivas
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus... por
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
1.6K vistas94 diapositivas
TorqueBox - Ruby Hoedown 2011 por
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011Lance Ball
696 vistas100 diapositivas
Rocket Fuelled Cucumbers por
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled CucumbersJoseph Wilk
6.1K vistas99 diapositivas
A Tale of a Server Architecture (Frozen Rails 2012) por
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
11.3K vistas49 diapositivas

La actualidad más candente(19)

DataMapper on Infinispan por Lance Ball
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on Infinispan
Lance Ball2.4K vistas
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus... por bobmcwhirter
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...
bobmcwhirter1.6K vistas
TorqueBox - Ruby Hoedown 2011 por Lance Ball
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
Lance Ball696 vistas
Rocket Fuelled Cucumbers por Joseph Wilk
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled Cucumbers
Joseph Wilk6.1K vistas
A Tale of a Server Architecture (Frozen Rails 2012) por Flowdock
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 11.3K vistas
TorqueBox - Ultrapassando a fronteira entre Java e Ruby por Bruno Oliveira
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
Bruno Oliveira1.4K vistas
Jruby synergy-of-ruby-and-java por Keith Bennett
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
Keith Bennett1.1K vistas
Java, Ruby & Rails por Peter Lind
Java, Ruby & RailsJava, Ruby & Rails
Java, Ruby & Rails
Peter Lind1.1K vistas
The Enterprise Strikes Back por Burke Libbey
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
Burke Libbey1.2K vistas
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015) por ngotogenome
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)
ngotogenome11.9K vistas
PECL Picks - Extensions to make your life better por ZendCon
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
ZendCon4.1K vistas
Above the clouds: introducing Akka por nartamonov
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
nartamonov3K vistas
When Two Worlds Collide: Java and Ruby in the Enterprise por benbrowning
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
benbrowning1.1K vistas
A tour of (advanced) Akka features in 40 minutes por Johan Janssen
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
Johan Janssen285 vistas
Automatic Reference Counting @ Pragma Night por Giuseppe Arici
Automatic Reference Counting @ Pragma NightAutomatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma Night
Giuseppe Arici1.6K vistas
Ruby 1.9 Fibers por Kevin Ball
Ruby 1.9 FibersRuby 1.9 Fibers
Ruby 1.9 Fibers
Kevin Ball6.1K vistas
When Ruby Meets Java - The Power of Torquebox por rockyjaiswal
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torquebox
rockyjaiswal6.7K vistas

Destacado

How to use BbC por
How to use BbCHow to use BbC
How to use BbCozesteph1992
394 vistas11 diapositivas
Edayz09 Freebie Presentation por
Edayz09 Freebie PresentationEdayz09 Freebie Presentation
Edayz09 Freebie Presentationozesteph1992
628 vistas97 diapositivas
Day 1 Beginner Admin moodle por
Day 1 Beginner Admin moodleDay 1 Beginner Admin moodle
Day 1 Beginner Admin moodleozesteph1992
1.5K vistas29 diapositivas
Creating a precense in Moodle por
Creating a precense in MoodleCreating a precense in Moodle
Creating a precense in Moodleozesteph1992
537 vistas73 diapositivas
Wee @ social media II v2 por
Wee @ social media II v2Wee @ social media II v2
Wee @ social media II v2WEE
1.3K vistas38 diapositivas
V Zine Introductie por
V Zine IntroductieV Zine Introductie
V Zine Introductiediederik bijlsma
185 vistas17 diapositivas

Destacado(10)

Edayz09 Freebie Presentation por ozesteph1992
Edayz09 Freebie PresentationEdayz09 Freebie Presentation
Edayz09 Freebie Presentation
ozesteph1992628 vistas
Day 1 Beginner Admin moodle por ozesteph1992
Day 1 Beginner Admin moodleDay 1 Beginner Admin moodle
Day 1 Beginner Admin moodle
ozesteph19921.5K vistas
Creating a precense in Moodle por ozesteph1992
Creating a precense in MoodleCreating a precense in Moodle
Creating a precense in Moodle
ozesteph1992537 vistas
Wee @ social media II v2 por WEE
Wee @ social media II v2Wee @ social media II v2
Wee @ social media II v2
WEE 1.3K vistas
Interactive pdfs assessing in the field por ozesteph1992
Interactive pdfs assessing in the fieldInteractive pdfs assessing in the field
Interactive pdfs assessing in the field
ozesteph1992640 vistas
潜力无限的编程语言Javascript por jay li
潜力无限的编程语言Javascript潜力无限的编程语言Javascript
潜力无限的编程语言Javascript
jay li9.4K vistas
淘宝前端技术巡礼 por jay li
淘宝前端技术巡礼淘宝前端技术巡礼
淘宝前端技术巡礼
jay li17.1K vistas
了解IO协议栈 por Feng Yu
了解IO协议栈了解IO协议栈
了解IO协议栈
Feng Yu13.3K vistas

Similar a Combining the strength of erlang and Ruby

At Scale With Style (Erlang User Conference 2012) por
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
3.4K vistas41 diapositivas
Introduction to Actor Model and Akka por
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and AkkaYung-Lin Ho
15.2K vistas23 diapositivas
Evented Ruby VS Node.js por
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.jsNitin Gupta
353 vistas54 diapositivas
Large-scaled Deploy Over 100 Servers in 3 Minutes por
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
3.8K vistas89 diapositivas
Erjang - A journey into Erlang-land por
Erjang - A journey into Erlang-landErjang - A journey into Erlang-land
Erjang - A journey into Erlang-landKresten Krab Thorup
1.2K vistas58 diapositivas
mtl_rubykaigi por
mtl_rubykaigimtl_rubykaigi
mtl_rubykaigiHirotomo Oi
1K vistas42 diapositivas

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

At Scale With Style (Erlang User Conference 2012) por Wooga
At Scale With Style (Erlang User Conference 2012)At Scale With Style (Erlang User Conference 2012)
At Scale With Style (Erlang User Conference 2012)
Wooga3.4K vistas
Introduction to Actor Model and Akka por Yung-Lin Ho
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
Yung-Lin Ho15.2K vistas
Evented Ruby VS Node.js por Nitin Gupta
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.js
Nitin Gupta353 vistas
Large-scaled Deploy Over 100 Servers in 3 Minutes por Hiroshi SHIBATA
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
Hiroshi SHIBATA3.8K vistas
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U... por Paolo Negri
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 Negri6.6K vistas
Rails Application Optimization Techniques & Tools por guest05c09d
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Tools
guest05c09d4.9K vistas
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang por Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangPractical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Lyon Yang3.5K vistas
Introduction to ansible por Omid Vahdaty
Introduction to ansibleIntroduction to ansible
Introduction to ansible
Omid Vahdaty1.1K vistas
Ansible presentation por Suresh Kumar
Ansible presentationAnsible presentation
Ansible presentation
Suresh Kumar7.1K vistas
Highly concurrent yet natural programming por Infinit
Highly concurrent yet natural programmingHighly concurrent yet natural programming
Highly concurrent yet natural programming
Infinit1K vistas
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw por Redspin, Inc.
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
Redspin, Inc.1.1K vistas
meetPHP#8 - PHP startups prototypes por Max Małecki
meetPHP#8 - PHP startups prototypesmeetPHP#8 - PHP startups prototypes
meetPHP#8 - PHP startups prototypes
Max Małecki2K vistas
Erlang - Concurrent Language for Concurrent World por Zvi Avraham
Erlang - Concurrent Language for Concurrent WorldErlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent World
Zvi Avraham4.3K vistas
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat) por OpenBlend society
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 society1K vistas
How Yelp does Service Discovery por John Billings
How Yelp does Service DiscoveryHow Yelp does Service Discovery
How Yelp does Service Discovery
John Billings1.9K vistas

Último

The Role of Patterns in the Era of Large Language Models por
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language ModelsYunyao Li
91 vistas65 diapositivas
Why and How CloudStack at weSystems - Stephan Bienek - weSystems por
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsShapeBlue
247 vistas13 diapositivas
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... por
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...ShapeBlue
199 vistas20 diapositivas
The Power of Generative AI in Accelerating No Code Adoption.pdf por
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdfSaeed Al Dhaheri
39 vistas18 diapositivas
Digital Personal Data Protection (DPDP) Practical Approach For CISOs por
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOsPriyanka Aash
162 vistas59 diapositivas
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... por
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...The Digital Insurer
91 vistas52 diapositivas

Último(20)

The Role of Patterns in the Era of Large Language Models por Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li91 vistas
Why and How CloudStack at weSystems - Stephan Bienek - weSystems por ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue247 vistas
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... por ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue199 vistas
The Power of Generative AI in Accelerating No Code Adoption.pdf por Saeed Al Dhaheri
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdf
Saeed Al Dhaheri39 vistas
Digital Personal Data Protection (DPDP) Practical Approach For CISOs por Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash162 vistas
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... por The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue por ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue152 vistas
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... por ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue141 vistas
LLMs in Production: Tooling, Process, and Team Structure por Aggregage
LLMs in Production: Tooling, Process, and Team StructureLLMs in Production: Tooling, Process, and Team Structure
LLMs in Production: Tooling, Process, and Team Structure
Aggregage57 vistas
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online por ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue225 vistas
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue por ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue137 vistas
Business Analyst Series 2023 - Week 4 Session 7 por DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10146 vistas
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue por ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue265 vistas
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... por ShapeBlue
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
ShapeBlue171 vistas
The Power of Heat Decarbonisation Plans in the Built Environment por IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE84 vistas
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue por ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueVNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
ShapeBlue207 vistas
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023 por BookNet Canada
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
BookNet Canada44 vistas

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