SlideShare a Scribd company logo
1 of 67
Lua + Erlang + VoltDB
An Erlang Game Stack




           An Erlang Game Stack




                        Erlang User Conference 2012
                                 H. Diedrich

                        http://www.eonblast.com – twitter @hdiedrich

1                                                                      Eonblast
An Erlang Game Stack



                  Henning Diedrich
        • Maintainer Emysql, Erlvolt, Erlualib
        • Eonblast: game + film
        • NewTracks: game + music
        • Bricks and mortar
        • Insurance tariff language

                               Octocat says: try markedoc!


2                                                    Eonblast
An Erlang Game Stack


                       Eonblast




3                                 Eonblast
An Erlang Game Stack


                       This Talk

            • A game server architecture
            • Its components
            • The glue




4                                          Eonblast
An Erlang Game Stack


                       This Talk
                  • Work in progress
                  • Unproven concepts
                  • Lies and conjecture
                             andalso

                  • 3 genius tools
                  • 10,000 lines of glue code

5                                               Eonblast
An Erlang Game Stack


                       Questions


        Please throw them in like Torben
      Mail me at hdiedrich at eonblast.com
               Erlang Mailing List




6                                     Eonblast
An Erlang Game Stack


                       Erlang Game Servers




    Zynga: FarmVille via membase, Activision Blizzard: Call of Duty, Bigpoint: Battle Star Galactica, Wooga: Magic Land




7                                                                                                       Eonblast
An Erlang Game Stack


                   Erlang + MySQL




                           http://eonblast.github.com/Emysql

                       Electronic Arts contributed emysql.


8                                                              Eonblast
An Erlang Game Stack


                       The Hurt
             • Leaks, Deadlocks
             • Bad Productivity
             • Game Design Language Gap

             • Less Features
             • Less Players
             • Lesser Product

9                                    Eonblast
An Erlang Game Stack


                        Target


             „The perfect game server“
                       (makes no sense)




10                                        Eonblast
An Erlang Game Stack


               Generals’ Problem




                                                            State




                       Two generals must agree on a time.



11                                                                  Eonblast
An Erlang Game Stack


               Generals’ Problem




                                           State




                       Send a messenger.



12                                                 Eonblast
An Erlang Game Stack


               Generals’ Problem




                                      State




                       Acknowledge.



13                                            Eonblast
An Erlang Game Stack


               Generals’ Problem




                                           State




                       ACK the ACK. Etc.



14                                                 Eonblast
An Erlang Game Stack


               Generals’ Problem




                                                     State




                       The messenger may get lost.



15                                                           Eonblast
An Erlang Game Stack


               Byzantine Generals




                                            State




                       The generals, too.



16                                                  Eonblast
An Erlang Game Stack


                        The Hunt

                        Server Stack
                       • Language
                       • Database
                       • Protocol
                       • Game Logic


17                                     Eonblast
An Erlang Game Stack


                          Spec
                       “Table Game”

           •   1 million active players
           •   1 million transactions per second
           •   1 second latency
           •   Linear scale
           •   100% data integrity



18                                                 Eonblast
An Erlang Game Stack


               Client Architecture


            • Fat JavaScript Browser Client
            • COMET



                       Not discussed in this talk.



19                                                   Eonblast
An Erlang Game Stack


                       Language

                            Wishlist
                       • Robustness
                       • Deadlock-free
                       • Multi-core
                       • Linear Scale
                                    er?



20                                        Eonblast
An Erlang Game Stack


                                     Database
                                         CAP
                                • Distributed
                                • Consistent
                                • Highly-available
                                • Partition-tolerant
                                       All of it!

     Brewer on CAP 2012: http://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed


21                                                                                             Eonblast
An Erlang Game Stack


                       Database

                             ACID
                       • Atomicity
                       • Consistency
                       • Isolation
                       • Durability
                        For Granted?


22                                     Eonblast
An Erlang Game Stack


                       Database

               Double Bookkeeping
           • Not every game needs it
           • Requires ACID Transactions
           • Neigh impossible to emulate
           • Impossible with BASE /
             Eventual Consistency

23                                         Eonblast
An Erlang Game Stack


                                 Database

                Upcoming Blog Post
        • Looking at 14 databases
        •   Riak, Cassandra, Membase, H-Base, Voldemort, MySQL, MySQL Cluster, Redis, Redis
            Cluster, Tokyo Cabinet, Memcached, CouchDB, Couchbase, VoltDB, MongoDB, Postgres


        • In the light of what games need
        • Unbiased comparison
        • Twitter @hdiedrich


24                                                                                      Eonblast
An Erlang Game Stack


                          Protocol

                              Wishlist
                       • Small footprint
                       • Fast to encode
                       • Human-readable




25                                         Eonblast
An Erlang Game Stack


                            Logic

                              Wishlist
                       • Human Readable
                       • Stable
                       • Fast
                       • Concise
                       • Small Footprint


26                                         Eonblast
An Erlang Game Stack


                            The Answers

                    • Client
                    • Protocol
                    • Server
                    • Logic
                    • Data
              Client: HTML5/JS, Protocol: JSON, Server: Erlang, Logic: Lua, Data: VoltDB.


27                                                                                          Eonblast
An Erlang Game Stack




               “Embeddable scripting language”




28                                               Eonblast
An Erlang Game Stack


                                         Lua


                       ”Lua is strange.“
                                     R. Virding




                       “It has mutable variables, what more need I say.”


29                                                                         Eonblast
An Erlang Game Stack


                       Lua

            a = “Roberto”
            if a ~= nil then
               print “Hello ” .. a .. “!”
            end




30                                   Eonblast
An Erlang Game Stack


                                            Lua
               •   Created 1993
               •   Simple, imperative syntax
               •   Stable syntax, stable VMs
               •   Two main VMs: ISO C, JIT
               •   Game scripting champion
               •   Open Source, 100% dictatorial*
                   *benevolent, of course




                   Site: http://www.lua.org
                   List: lua-l@lists.lua.org
31                                                Eonblast
An Erlang Game Stack


                            Lua

        •   Made for non-programmers - imperative syntax
        •   Powerful for programmers - Scheme semantics
        •   Made for DSLs - extensible semantics
        •   Made to be extended - simple C API
        •   Made to be embedded - small VM footprint

        • Now with a native Erlang VM!



32                                                 Eonblast
An Erlang Game Stack


                       Lua Caveats

            •   Deceiving Looks
            •   Encourages magic
            •   Simple but not for beginners
            •   Syntax forked
            •   Only one collection type



33                                             Eonblast
An Erlang Game Stack


                        Lua VMs
       • PUC Reference VM      pure ISO C
          Lua 5.2              super compatible


       • JIT VM                X86, ARM, PPC, MIPS
          remains at Lua 5.1
                               super fast
          adds extensions


       • Luerl                 native Erlang VM
          Lua 5.2              super stable
          incomplete


34                                                Eonblast
An Erlang Game Stack


                       Architecture




35                                    Eonblast
An Erlang Game Stack




              Perceived reaction to asking about benchmarks on the Erlang mailing list.


36                                                                                        Eonblast
An Erlang Game Stack


                        World State


                                          State




                   Where does the state go? Into the Logic core, for speed.

37                                                                            Eonblast
An Erlang Game Stack


                       World State


            State      State    State   State   State




                               State


38                                                      Eonblast
An Erlang Game Stack


                       World State


            State      State    State   State   State




                               State


39                                                      Eonblast
An Erlang Game Stack


                       World State


            State              State   State   State
                           State




                           State


40                                                     Eonblast
An Erlang Game Stack


                       World State


            State      State    State   State   State




                               State


41                                                      Eonblast
An Erlang Game Stack




                       “High Velocity Database”




42                                                Eonblast
An Erlang Game Stack


                                  VoltDB
     •   Created 2009
     •   Simple SQL syntax
     •   Stable 2.5
     •   Commercial developer, support
     •   High Velocity Secret Tip
     •   Open Source, 100% dictatorial*
         *benevolent, of course



         Site: http://www.voltdb.com
         Help: http://community.voltdb.com/forum

43                                          Eonblast
An Erlang Game Stack


                          VoltDB

     •   ACID transactions – double bookkeeping
     •   SQL – subset of '92
     •   Linear scale - „unlimited“ data (but ...)
     •   Made for OLTP - fast, cheap writes, high throughput
     •   “More SQL than SQL” – invites clean sep. of data
     •   In-memory - 100x faster than MySQL
     •   Replication, Snapshots – 'hot backup built in'



44                                                   Eonblast
An Erlang Game Stack


                  VoltDB Caveats
           •   Less agile than MySQL/NoSQL
           •   Need to understand partitions
           •   Must program SPs in Java
           •   Not elastic (yet)
           •   No online schema change (yet)
           •   There is always a bottleneck
           •   Simple but not for beginners


45                                             Eonblast
An Erlang Game Stack


              Horizonzal Partitions
                       State
                         #




46                                    Eonblast
An Erlang Game Stack


                       Replication
                          State
                            #




47                                   Eonblast
An Erlang Game Stack


                Actual Connections


            State      State    State   State   State




                               State


48                                                      Eonblast
An Erlang Game Stack




                       The Mix




           Erlang + Lua + VoltDB
49                               Eonblast
An Erlang Game Stack




                       How do we connect these components?

50                                                           Eonblast
An Erlang Game Stack




                       Fleece




                       Erlualib



                       Erlvolt




51                                Eonblast
An Erlang Game Stack




                       Fleece



                        Luerl




                       Erlvolt




52                               Eonblast
An Erlang Game Stack


                       The Packages

     • Protocol        Fleece     Lua to JSON

     • Logic           Erlualib   Lua port

     • Logic            Luerl     Lua VM

     • Data             Erlvolt   VoltDB driver




53                                                Eonblast
An Erlang Game Stack


                       Erlualib

           • Lua embedding library for Erlang

           • Lua state in original PUC Lua VM
           • A fast way
           • A not secure way: can crash Erlang




54                                              Eonblast
An Erlang Game Stack


                             Erlualib
              hello() ->
                 % get handle of the Lua engine
                 {ok, L} = lua:new_s tate(),

                 % put " print" global on top of s tack
                 lua:getfield(L, global, " print" ),

                 % put hello on top
                 lua:pus hs tring(L, " Hello from Lua!" ),

                 % exec ute on top 2 values on s tac k
                 lua:c all(L, 1, 0).



55                                                           Eonblast
An Erlang Game Stack


                               Erlualib

             hello() ->

                {ok, L} = lua:new_s tate(),

                lua:getfield(L, global, " print" ),

                lua:pus hs tring(L, " Hello from Lua!" ),

                lua:c all(L, 1, 0).




56                                                          Eonblast
An Erlang Game Stack


                       Luerl

        • New Lua VM programmed in Erlang
        • Perfectly secure way
        • Precompiled Chunks
        • Re-usable State
        • Work in progress


57                                   Eonblast
An Erlang Game Stack


                                    Luerl


             hello() ->

                L = luerl:init(),

                luerl:do(" print('Hello from Lua!')" , L).




58                                                           Eonblast
An Erlang Game Stack


                                 Luerl

     hello() ->

        L = luerl:init(),
       C hunk = luerl:eval(" print('Hello from Lua!')" , L),
       luerl:call(C hunk, L)

     % C hunk and L c an be re-us ed.




59                                                             Eonblast
An Erlang Game Stack


                           Benchmark Luerl vs Erlualib




        Erlualib / PUC                                                     Luerl

        270 µs                           state Init                        250 µs

        10 µs                          parse 1 + 1                         15 µs

        2.5 µs                        execute 1 + 1                        13 µs

        23 µs                         parse formula                        63 µs

        2.5 µs                      execute formula                        35 µs

        2.5 µs                        call a function                      28 µs

                  Formula: a = 7.33; b = 9000; c = (33 * a / b) ^ 15 * a + b

60                                                                             Eonblast
An Erlang Game Stack




                       Fast Lua to JSON encoder




61                                                Eonblast
An Erlang Game Stack


                           Fleece

                •   Fastest Lua JSON encoder
                •   C+ASM or ISO C
                •   Faster than Lua JIT
                •   Faster than concat
                •   10x faster than other fastest




62                                                  Eonblast
An Erlang Game Stack




63                     Eonblast
An Erlang Game Stack


                            Erlvolt

                •   Native Erlang VoltDB driver
                •   Async parallel data shuffling
                •   Coming next quarter
                •   Your help is wanted
                •   Connect over github




64                                                  Eonblast
An Erlang Game Stack


               Server Architecture

                • Erlang   • Luerl
                • Lua      • Erlualib
                • JSON     • Fleece
                • VoltDB   • Erlvolt




65                                      Eonblast
An Erlang Game Stack


                       Invitation

            • All at github
            • All w/samples & docs
            • All maintained by Eonblast
            • Luerl maintained by R. Virding
            • Updates @hdiedrich, @rvirding


66                                        Eonblast
An Erlang Game Stack


                       Questions


           Mail: hdiedrich ∂ eonblast.com
                   Skype: eonblast
                  Twitter: @hdiedrich




67                                          Eonblast

More Related Content

What's hot

GDC2011 - Implementation and Application of the Real-Time Helper-Joint System
GDC2011 - Implementation and Application of the Real-Time Helper-Joint SystemGDC2011 - Implementation and Application of the Real-Time Helper-Joint System
GDC2011 - Implementation and Application of the Real-Time Helper-Joint System
Jubok Kim
 

What's hot (20)

Zabbix, Grafana e os conteineres Docker
Zabbix, Grafana e os conteineres DockerZabbix, Grafana e os conteineres Docker
Zabbix, Grafana e os conteineres Docker
 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
 
선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기
선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기
선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기
 
[NDC16] Effective Git
[NDC16] Effective Git[NDC16] Effective Git
[NDC16] Effective Git
 
Finite State Queries In Lucene
Finite State Queries In LuceneFinite State Queries In Lucene
Finite State Queries In Lucene
 
[D2]pinpoint 개발기
[D2]pinpoint 개발기[D2]pinpoint 개발기
[D2]pinpoint 개발기
 
Splunking the JVM (Java Virtual Machine)
Splunking the JVM (Java Virtual Machine)Splunking the JVM (Java Virtual Machine)
Splunking the JVM (Java Virtual Machine)
 
Introduction to CircleCI
Introduction to CircleCIIntroduction to CircleCI
Introduction to CircleCI
 
Building a PaaS with Docker and AWS
Building a PaaS with Docker and AWSBuilding a PaaS with Docker and AWS
Building a PaaS with Docker and AWS
 
Cortex: Horizontally Scalable, Highly Available Prometheus
Cortex: Horizontally Scalable, Highly Available PrometheusCortex: Horizontally Scalable, Highly Available Prometheus
Cortex: Horizontally Scalable, Highly Available Prometheus
 
Flutter, prazer
Flutter, prazerFlutter, prazer
Flutter, prazer
 
Storage Requirements and Options for Running Spark on Kubernetes
Storage Requirements and Options for Running Spark on KubernetesStorage Requirements and Options for Running Spark on Kubernetes
Storage Requirements and Options for Running Spark on Kubernetes
 
Using Apache Kafka to Analyze Session Windows
Using Apache Kafka to Analyze Session WindowsUsing Apache Kafka to Analyze Session Windows
Using Apache Kafka to Analyze Session Windows
 
Redmineチケットによるプロジェクト火消し戦略!
Redmineチケットによるプロジェクト火消し戦略!Redmineチケットによるプロジェクト火消し戦略!
Redmineチケットによるプロジェクト火消し戦略!
 
KGC 2016: HTTPS 로 모바일 게임 서버 구축한다는 것 - Korea Games Conference
KGC 2016: HTTPS 로 모바일 게임 서버 구축한다는 것 - Korea Games ConferenceKGC 2016: HTTPS 로 모바일 게임 서버 구축한다는 것 - Korea Games Conference
KGC 2016: HTTPS 로 모바일 게임 서버 구축한다는 것 - Korea Games Conference
 
Native mobile application development with Flutter (Dart)
Native mobile application development with Flutter (Dart)Native mobile application development with Flutter (Dart)
Native mobile application development with Flutter (Dart)
 
Building beautiful apps with Google flutter
Building beautiful apps with Google flutterBuilding beautiful apps with Google flutter
Building beautiful apps with Google flutter
 
GDC2011 - Implementation and Application of the Real-Time Helper-Joint System
GDC2011 - Implementation and Application of the Real-Time Helper-Joint SystemGDC2011 - Implementation and Application of the Real-Time Helper-Joint System
GDC2011 - Implementation and Application of the Real-Time Helper-Joint System
 
Utilizing the OpenNTF Domino API
Utilizing the OpenNTF Domino APIUtilizing the OpenNTF Domino API
Utilizing the OpenNTF Domino API
 
What is Game Server ?
What is Game Server ?What is Game Server ?
What is Game Server ?
 

Viewers also liked

High Performance Erlang
High Performance ErlangHigh Performance Erlang
High Performance Erlang
didip
 
1300579454645 livro adm proc operacionais
1300579454645 livro adm proc operacionais1300579454645 livro adm proc operacionais
1300579454645 livro adm proc operacionais
PMP
 
Benchmarks, performance, scalability, and capacity what's behind the numbers
Benchmarks, performance, scalability, and capacity what's behind the numbersBenchmarks, performance, scalability, and capacity what's behind the numbers
Benchmarks, performance, scalability, and capacity what's behind the numbers
Justin Dorfman
 
Comparing Cpp And Erlang For Motorola Telecoms Software
Comparing Cpp And Erlang For Motorola Telecoms SoftwareComparing Cpp And Erlang For Motorola Telecoms Software
Comparing Cpp And Erlang For Motorola Telecoms Software
l xf
 
A Practical Architecture Design for MMO Casual Game
A Practical Architecture Design for MMO Casual GameA Practical Architecture Design for MMO Casual Game
A Practical Architecture Design for MMO Casual Game
action.vn
 
Space Ape's Live Ops Stack: Engineering Mobile Games for Live Ops from Day 1
Space Ape's Live Ops Stack: Engineering Mobile Games for Live Ops from Day 1Space Ape's Live Ops Stack: Engineering Mobile Games for Live Ops from Day 1
Space Ape's Live Ops Stack: Engineering Mobile Games for Live Ops from Day 1
Simon Hade
 
MMO Design Architecture by Andrew
MMO Design Architecture by AndrewMMO Design Architecture by Andrew
MMO Design Architecture by Andrew
Agate Studio
 

Viewers also liked (20)

Erlang, the big switch in social games
Erlang, the big switch in social gamesErlang, the big switch in social games
Erlang, the big switch in social games
 
Intro to Erlang
Intro to ErlangIntro to Erlang
Intro to Erlang
 
Erlang OTP
Erlang OTPErlang OTP
Erlang OTP
 
First encounter with Elixir - Some random things
First encounter with Elixir - Some random thingsFirst encounter with Elixir - Some random things
First encounter with Elixir - Some random things
 
Erlang and Scalability
Erlang and ScalabilityErlang and Scalability
Erlang and Scalability
 
Making multiplayer game with Elixir and Elm
Making multiplayer game with Elixir and ElmMaking multiplayer game with Elixir and Elm
Making multiplayer game with Elixir and Elm
 
DevOps goes Mobile (daho.am)
DevOps goes Mobile (daho.am)DevOps goes Mobile (daho.am)
DevOps goes Mobile (daho.am)
 
The Two Generals Problem
The Two Generals ProblemThe Two Generals Problem
The Two Generals Problem
 
High Performance Erlang
High Performance ErlangHigh Performance Erlang
High Performance Erlang
 
1300579454645 livro adm proc operacionais
1300579454645 livro adm proc operacionais1300579454645 livro adm proc operacionais
1300579454645 livro adm proc operacionais
 
Benchmarks, performance, scalability, and capacity what's behind the numbers
Benchmarks, performance, scalability, and capacity what's behind the numbersBenchmarks, performance, scalability, and capacity what's behind the numbers
Benchmarks, performance, scalability, and capacity what's behind the numbers
 
Comparing Cpp And Erlang For Motorola Telecoms Software
Comparing Cpp And Erlang For Motorola Telecoms SoftwareComparing Cpp And Erlang For Motorola Telecoms Software
Comparing Cpp And Erlang For Motorola Telecoms Software
 
Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...
Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...
Introdução à Computação Aula 05 - Sistemas Operacionais (arquitetura do SO, p...
 
Evoloution of Ideas
Evoloution of IdeasEvoloution of Ideas
Evoloution of Ideas
 
Online games traffic characterization and network support
Online games traffic characterization and network supportOnline games traffic characterization and network support
Online games traffic characterization and network support
 
Brief Intro to Phoenix - Elixir Meetup at BukaLapak
Brief Intro to Phoenix - Elixir Meetup at BukaLapakBrief Intro to Phoenix - Elixir Meetup at BukaLapak
Brief Intro to Phoenix - Elixir Meetup at BukaLapak
 
A Practical Architecture Design for MMO Casual Game
A Practical Architecture Design for MMO Casual GameA Practical Architecture Design for MMO Casual Game
A Practical Architecture Design for MMO Casual Game
 
Space Ape's Live Ops Stack: Engineering Mobile Games for Live Ops from Day 1
Space Ape's Live Ops Stack: Engineering Mobile Games for Live Ops from Day 1Space Ape's Live Ops Stack: Engineering Mobile Games for Live Ops from Day 1
Space Ape's Live Ops Stack: Engineering Mobile Games for Live Ops from Day 1
 
MMO Design Architecture by Andrew
MMO Design Architecture by AndrewMMO Design Architecture by Andrew
MMO Design Architecture by Andrew
 
Instagram Celebrities: are they the new cats? - Targetsummit Berlin 2015
Instagram Celebrities: are they the new cats? - Targetsummit Berlin 2015Instagram Celebrities: are they the new cats? - Targetsummit Berlin 2015
Instagram Celebrities: are they the new cats? - Targetsummit Berlin 2015
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

An Erlang Game Stack

  • 1. Lua + Erlang + VoltDB An Erlang Game Stack An Erlang Game Stack Erlang User Conference 2012 H. Diedrich http://www.eonblast.com – twitter @hdiedrich 1 Eonblast
  • 2. An Erlang Game Stack Henning Diedrich • Maintainer Emysql, Erlvolt, Erlualib • Eonblast: game + film • NewTracks: game + music • Bricks and mortar • Insurance tariff language Octocat says: try markedoc! 2 Eonblast
  • 3. An Erlang Game Stack Eonblast 3 Eonblast
  • 4. An Erlang Game Stack This Talk • A game server architecture • Its components • The glue 4 Eonblast
  • 5. An Erlang Game Stack This Talk • Work in progress • Unproven concepts • Lies and conjecture andalso • 3 genius tools • 10,000 lines of glue code 5 Eonblast
  • 6. An Erlang Game Stack Questions Please throw them in like Torben Mail me at hdiedrich at eonblast.com Erlang Mailing List 6 Eonblast
  • 7. An Erlang Game Stack Erlang Game Servers Zynga: FarmVille via membase, Activision Blizzard: Call of Duty, Bigpoint: Battle Star Galactica, Wooga: Magic Land 7 Eonblast
  • 8. An Erlang Game Stack Erlang + MySQL http://eonblast.github.com/Emysql Electronic Arts contributed emysql. 8 Eonblast
  • 9. An Erlang Game Stack The Hurt • Leaks, Deadlocks • Bad Productivity • Game Design Language Gap • Less Features • Less Players • Lesser Product 9 Eonblast
  • 10. An Erlang Game Stack Target „The perfect game server“ (makes no sense) 10 Eonblast
  • 11. An Erlang Game Stack Generals’ Problem State Two generals must agree on a time. 11 Eonblast
  • 12. An Erlang Game Stack Generals’ Problem State Send a messenger. 12 Eonblast
  • 13. An Erlang Game Stack Generals’ Problem State Acknowledge. 13 Eonblast
  • 14. An Erlang Game Stack Generals’ Problem State ACK the ACK. Etc. 14 Eonblast
  • 15. An Erlang Game Stack Generals’ Problem State The messenger may get lost. 15 Eonblast
  • 16. An Erlang Game Stack Byzantine Generals State The generals, too. 16 Eonblast
  • 17. An Erlang Game Stack The Hunt Server Stack • Language • Database • Protocol • Game Logic 17 Eonblast
  • 18. An Erlang Game Stack Spec “Table Game” • 1 million active players • 1 million transactions per second • 1 second latency • Linear scale • 100% data integrity 18 Eonblast
  • 19. An Erlang Game Stack Client Architecture • Fat JavaScript Browser Client • COMET Not discussed in this talk. 19 Eonblast
  • 20. An Erlang Game Stack Language Wishlist • Robustness • Deadlock-free • Multi-core • Linear Scale er? 20 Eonblast
  • 21. An Erlang Game Stack Database CAP • Distributed • Consistent • Highly-available • Partition-tolerant All of it! Brewer on CAP 2012: http://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed 21 Eonblast
  • 22. An Erlang Game Stack Database ACID • Atomicity • Consistency • Isolation • Durability For Granted? 22 Eonblast
  • 23. An Erlang Game Stack Database Double Bookkeeping • Not every game needs it • Requires ACID Transactions • Neigh impossible to emulate • Impossible with BASE / Eventual Consistency 23 Eonblast
  • 24. An Erlang Game Stack Database Upcoming Blog Post • Looking at 14 databases • Riak, Cassandra, Membase, H-Base, Voldemort, MySQL, MySQL Cluster, Redis, Redis Cluster, Tokyo Cabinet, Memcached, CouchDB, Couchbase, VoltDB, MongoDB, Postgres • In the light of what games need • Unbiased comparison • Twitter @hdiedrich 24 Eonblast
  • 25. An Erlang Game Stack Protocol Wishlist • Small footprint • Fast to encode • Human-readable 25 Eonblast
  • 26. An Erlang Game Stack Logic Wishlist • Human Readable • Stable • Fast • Concise • Small Footprint 26 Eonblast
  • 27. An Erlang Game Stack The Answers • Client • Protocol • Server • Logic • Data Client: HTML5/JS, Protocol: JSON, Server: Erlang, Logic: Lua, Data: VoltDB. 27 Eonblast
  • 28. An Erlang Game Stack “Embeddable scripting language” 28 Eonblast
  • 29. An Erlang Game Stack Lua ”Lua is strange.“ R. Virding “It has mutable variables, what more need I say.” 29 Eonblast
  • 30. An Erlang Game Stack Lua a = “Roberto” if a ~= nil then print “Hello ” .. a .. “!” end 30 Eonblast
  • 31. An Erlang Game Stack Lua • Created 1993 • Simple, imperative syntax • Stable syntax, stable VMs • Two main VMs: ISO C, JIT • Game scripting champion • Open Source, 100% dictatorial* *benevolent, of course Site: http://www.lua.org List: lua-l@lists.lua.org 31 Eonblast
  • 32. An Erlang Game Stack Lua • Made for non-programmers - imperative syntax • Powerful for programmers - Scheme semantics • Made for DSLs - extensible semantics • Made to be extended - simple C API • Made to be embedded - small VM footprint • Now with a native Erlang VM! 32 Eonblast
  • 33. An Erlang Game Stack Lua Caveats • Deceiving Looks • Encourages magic • Simple but not for beginners • Syntax forked • Only one collection type 33 Eonblast
  • 34. An Erlang Game Stack Lua VMs • PUC Reference VM pure ISO C Lua 5.2 super compatible • JIT VM X86, ARM, PPC, MIPS remains at Lua 5.1 super fast adds extensions • Luerl native Erlang VM Lua 5.2 super stable incomplete 34 Eonblast
  • 35. An Erlang Game Stack Architecture 35 Eonblast
  • 36. An Erlang Game Stack Perceived reaction to asking about benchmarks on the Erlang mailing list. 36 Eonblast
  • 37. An Erlang Game Stack World State State Where does the state go? Into the Logic core, for speed. 37 Eonblast
  • 38. An Erlang Game Stack World State State State State State State State 38 Eonblast
  • 39. An Erlang Game Stack World State State State State State State State 39 Eonblast
  • 40. An Erlang Game Stack World State State State State State State State 40 Eonblast
  • 41. An Erlang Game Stack World State State State State State State State 41 Eonblast
  • 42. An Erlang Game Stack “High Velocity Database” 42 Eonblast
  • 43. An Erlang Game Stack VoltDB • Created 2009 • Simple SQL syntax • Stable 2.5 • Commercial developer, support • High Velocity Secret Tip • Open Source, 100% dictatorial* *benevolent, of course Site: http://www.voltdb.com Help: http://community.voltdb.com/forum 43 Eonblast
  • 44. An Erlang Game Stack VoltDB • ACID transactions – double bookkeeping • SQL – subset of '92 • Linear scale - „unlimited“ data (but ...) • Made for OLTP - fast, cheap writes, high throughput • “More SQL than SQL” – invites clean sep. of data • In-memory - 100x faster than MySQL • Replication, Snapshots – 'hot backup built in' 44 Eonblast
  • 45. An Erlang Game Stack VoltDB Caveats • Less agile than MySQL/NoSQL • Need to understand partitions • Must program SPs in Java • Not elastic (yet) • No online schema change (yet) • There is always a bottleneck • Simple but not for beginners 45 Eonblast
  • 46. An Erlang Game Stack Horizonzal Partitions State # 46 Eonblast
  • 47. An Erlang Game Stack Replication State # 47 Eonblast
  • 48. An Erlang Game Stack Actual Connections State State State State State State 48 Eonblast
  • 49. An Erlang Game Stack The Mix Erlang + Lua + VoltDB 49 Eonblast
  • 50. An Erlang Game Stack How do we connect these components? 50 Eonblast
  • 51. An Erlang Game Stack Fleece Erlualib Erlvolt 51 Eonblast
  • 52. An Erlang Game Stack Fleece Luerl Erlvolt 52 Eonblast
  • 53. An Erlang Game Stack The Packages • Protocol Fleece Lua to JSON • Logic Erlualib Lua port • Logic Luerl Lua VM • Data Erlvolt VoltDB driver 53 Eonblast
  • 54. An Erlang Game Stack Erlualib • Lua embedding library for Erlang • Lua state in original PUC Lua VM • A fast way • A not secure way: can crash Erlang 54 Eonblast
  • 55. An Erlang Game Stack Erlualib hello() -> % get handle of the Lua engine {ok, L} = lua:new_s tate(), % put " print" global on top of s tack lua:getfield(L, global, " print" ), % put hello on top lua:pus hs tring(L, " Hello from Lua!" ), % exec ute on top 2 values on s tac k lua:c all(L, 1, 0). 55 Eonblast
  • 56. An Erlang Game Stack Erlualib hello() -> {ok, L} = lua:new_s tate(), lua:getfield(L, global, " print" ), lua:pus hs tring(L, " Hello from Lua!" ), lua:c all(L, 1, 0). 56 Eonblast
  • 57. An Erlang Game Stack Luerl • New Lua VM programmed in Erlang • Perfectly secure way • Precompiled Chunks • Re-usable State • Work in progress 57 Eonblast
  • 58. An Erlang Game Stack Luerl hello() -> L = luerl:init(), luerl:do(" print('Hello from Lua!')" , L). 58 Eonblast
  • 59. An Erlang Game Stack Luerl hello() -> L = luerl:init(), C hunk = luerl:eval(" print('Hello from Lua!')" , L), luerl:call(C hunk, L) % C hunk and L c an be re-us ed. 59 Eonblast
  • 60. An Erlang Game Stack Benchmark Luerl vs Erlualib Erlualib / PUC Luerl 270 µs state Init 250 µs 10 µs parse 1 + 1 15 µs 2.5 µs execute 1 + 1 13 µs 23 µs parse formula 63 µs 2.5 µs execute formula 35 µs 2.5 µs call a function 28 µs Formula: a = 7.33; b = 9000; c = (33 * a / b) ^ 15 * a + b 60 Eonblast
  • 61. An Erlang Game Stack Fast Lua to JSON encoder 61 Eonblast
  • 62. An Erlang Game Stack Fleece • Fastest Lua JSON encoder • C+ASM or ISO C • Faster than Lua JIT • Faster than concat • 10x faster than other fastest 62 Eonblast
  • 63. An Erlang Game Stack 63 Eonblast
  • 64. An Erlang Game Stack Erlvolt • Native Erlang VoltDB driver • Async parallel data shuffling • Coming next quarter • Your help is wanted • Connect over github 64 Eonblast
  • 65. An Erlang Game Stack Server Architecture • Erlang • Luerl • Lua • Erlualib • JSON • Fleece • VoltDB • Erlvolt 65 Eonblast
  • 66. An Erlang Game Stack Invitation • All at github • All w/samples & docs • All maintained by Eonblast • Luerl maintained by R. Virding • Updates @hdiedrich, @rvirding 66 Eonblast
  • 67. An Erlang Game Stack Questions Mail: hdiedrich ∂ eonblast.com Skype: eonblast Twitter: @hdiedrich 67 Eonblast