SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Jignesh Shah
 
When Kafka Meets the Scaling and Reliability needs of World's Largest Retaile...
When Kafka Meets the Scaling and Reliability needs of World's Largest Retaile...When Kafka Meets the Scaling and Reliability needs of World's Largest Retaile...
When Kafka Meets the Scaling and Reliability needs of World's Largest Retaile...
confluent
 
Solving Hadoop Replication Challenges with an Active-Active Paxos Algorithm
Solving Hadoop Replication Challenges with an Active-Active Paxos AlgorithmSolving Hadoop Replication Challenges with an Active-Active Paxos Algorithm
Solving Hadoop Replication Challenges with an Active-Active Paxos Algorithm
DataWorks Summit
 
윈도우 매니저 스터디: 1. 윈도우 매니저 출력
윈도우 매니저 스터디: 1. 윈도우 매니저 출력윈도우 매니저 스터디: 1. 윈도우 매니저 출력
윈도우 매니저 스터디: 1. 윈도우 매니저 출력
nemoux
 
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
confluent
 
Brdf기반 사전정의 스킨 셰이더
Brdf기반 사전정의 스킨 셰이더Brdf기반 사전정의 스킨 셰이더
Brdf기반 사전정의 스킨 셰이더
동석 김
 

La actualidad más candente (20)

Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
 
Exploring MongoDB & Elasticsearch: Better Together
Exploring MongoDB & Elasticsearch: Better TogetherExploring MongoDB & Elasticsearch: Better Together
Exploring MongoDB & Elasticsearch: Better Together
 
Understanding and tuning WiredTiger, the new high performance database engine...
Understanding and tuning WiredTiger, the new high performance database engine...Understanding and tuning WiredTiger, the new high performance database engine...
Understanding and tuning WiredTiger, the new high performance database engine...
 
Performance Tuning RocksDB for Kafka Streams' State Stores (Dhruba Borthakur,...
Performance Tuning RocksDB for Kafka Streams' State Stores (Dhruba Borthakur,...Performance Tuning RocksDB for Kafka Streams' State Stores (Dhruba Borthakur,...
Performance Tuning RocksDB for Kafka Streams' State Stores (Dhruba Borthakur,...
 
When Kafka Meets the Scaling and Reliability needs of World's Largest Retaile...
When Kafka Meets the Scaling and Reliability needs of World's Largest Retaile...When Kafka Meets the Scaling and Reliability needs of World's Largest Retaile...
When Kafka Meets the Scaling and Reliability needs of World's Largest Retaile...
 
Solving Hadoop Replication Challenges with an Active-Active Paxos Algorithm
Solving Hadoop Replication Challenges with an Active-Active Paxos AlgorithmSolving Hadoop Replication Challenges with an Active-Active Paxos Algorithm
Solving Hadoop Replication Challenges with an Active-Active Paxos Algorithm
 
Ceph as software define storage
Ceph as software define storageCeph as software define storage
Ceph as software define storage
 
윈도우 매니저 스터디: 1. 윈도우 매니저 출력
윈도우 매니저 스터디: 1. 윈도우 매니저 출력윈도우 매니저 스터디: 1. 윈도우 매니저 출력
윈도우 매니저 스터디: 1. 윈도우 매니저 출력
 
Introduction to the Disruptor
Introduction to the DisruptorIntroduction to the Disruptor
Introduction to the Disruptor
 
HBaseCon 2013: Apache HBase Table Snapshots
HBaseCon 2013: Apache HBase Table SnapshotsHBaseCon 2013: Apache HBase Table Snapshots
HBaseCon 2013: Apache HBase Table Snapshots
 
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
 
HBase Advanced - Lars George
HBase Advanced - Lars GeorgeHBase Advanced - Lars George
HBase Advanced - Lars George
 
A Closer Look at RabbitMQ
A Closer Look at RabbitMQA Closer Look at RabbitMQ
A Closer Look at RabbitMQ
 
Operating and Supporting Apache HBase Best Practices and Improvements
Operating and Supporting Apache HBase Best Practices and ImprovementsOperating and Supporting Apache HBase Best Practices and Improvements
Operating and Supporting Apache HBase Best Practices and Improvements
 
HBase Low Latency
HBase Low LatencyHBase Low Latency
HBase Low Latency
 
HBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ SalesforceHBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ Salesforce
 
Supporting Apache HBase : Troubleshooting and Supportability Improvements
Supporting Apache HBase : Troubleshooting and Supportability ImprovementsSupporting Apache HBase : Troubleshooting and Supportability Improvements
Supporting Apache HBase : Troubleshooting and Supportability Improvements
 
Brdf기반 사전정의 스킨 셰이더
Brdf기반 사전정의 스킨 셰이더Brdf기반 사전정의 스킨 셰이더
Brdf기반 사전정의 스킨 셰이더
 
Big Data Meets NVM: Accelerating Big Data Processing with Non-Volatile Memory...
Big Data Meets NVM: Accelerating Big Data Processing with Non-Volatile Memory...Big Data Meets NVM: Accelerating Big Data Processing with Non-Volatile Memory...
Big Data Meets NVM: Accelerating Big Data Processing with Non-Volatile Memory...
 

Destacado

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
 

Destacado (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
 

Último

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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

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