SlideShare a Scribd company logo
1 of 28
Download to read offline
Presenting users with a consistent world without
                persistent clients



Permanent State in a Serverless
        Environment
➲Presenting   users with a persistent state is easy if you have a
persistent host.
➲With a few techniques it can be done without a server, as
long as clients remain in the game.
➲Primary benefit is the saving on Server hosting costs.




                     Overview
➲   Traditional Model : Client/Server
➲   Server runs game logic, deciding when events occur.
➲   Game clients receive incoming events and process them
    (deterministically).
➲   Late-joiners can receive a snapshot of the world from the host.




                Server based model
➲   One of the clients acts as the server.
➲   That client drives the others via events.
➲   Processes events themselves.
➲   The problem is that the server “state” is never transmitted, only
    the client state.
➲   If the integrated server leaves, what do we do.




                   Integrated server
➲   If we make the server logic “stateless” we can move the server
    at will.
➲   The server is now just code, that runs on one machine. The
    only thing the server code can do is send events.
➲   Server is non-deterministic. Client code deterministic.




            Integrated server (cont)
➲   This would suffice if only the host needs to interact with the
    world, and everyone else just views them.
➲   The real problem comes when we allow the clients to interact
    with the world as well. (clients become peers)
➲   Peers actions can overlap, creating race conditions.
➲   To resolve these race conditions we could lock resources using
    the host as a token server.




             Moving to peer-to-peer
➲   Tokens are often touted as a solution
➲   Peer signal requests for tokens
➲   Server grants, or refuses
➲   Peer then can control the object
➲   What if server migrates after the signal?
➲   What if peer leaves after obtaining the token?
➲   We cannot reclaim the token until the peer is definitely gone.




           The problem with tokens
➲   What if the server, merely re-broadcasts the signals, without
    any logic.
➲   The outgoing broadcasts are ordered, so all the peers see the
    signals in the same order.
➲   Peers smart enough to work out when locks fail, or succeed.
➲   Now we can implement complex behaviors.
➲   Example, can only get into a vehicle if it's empty, or occupied
    by a team mate.




            Introducing the reflector
➲   The reflector is like a server with no state, nor game specific
    logic.
➲   It is a true peer-peer logic, all clients are identical, except for
    the automatic reflecting of requests.
➲   Peers must remember the sent signals. If the host changes,
    they must resend all signals they have not seen reflected.
➲




                       The Reflector
➲   Peers send signals and handle events.
➲   The reflector reflects the signals. Reflected signals are events,
    and are in the same order on all machines.
➲   Signals have a unique identifier formed from machine ID and
    count of signals sent.
➲   Events also have a unique ID of the reflector and the event
    count. (also known as the event stream position)




                       Terminology
➲   The reflect method is exposed on all machines.
➲   On any client who is not the reflector, the method does nothing.
➲   On the reflector, the event occurs immediately, with the event
    sent as normal to other clients.
➲   Reflect methods must not change state, only generate events.




                The Reflect Method
➲   Three common ownership patterns
➲   Unique ownership : no-one else can signal, clients can signal
    whenever they like.
➲   Single ownership : State is changed using reflect, effective like
    the old “server code” pattern.
➲   No/Shared Ownership: context never changes, peers signal
    when they wish to change state. Changes may fail.




               Ownership analogies
In this example, Peer 1, wants to signal
Peer     Reflecto   Peer         something about an object they own.
1        r          3      Peer 1 call Signal, which sends a signal
                                 to the reflector.
Signal
                           The reflector calls the reflect method, and
                                 sends the results to all clients,
                                 including themselves.

            Event          A use of this pattern might be used for
                               example to allow a player to select
                               their own weapon.




     Unique ownership pattern
In this example, something must get
Peer      Reflecto   Peer         done, once and once only. In this
1         r          3            case we poll for the condition on
                                  each client. Each client calls the
                                  reflect method when required.
                            Only the reflector will do anything when
                                  reflect is called, and they will send
                                  an event to all clients (including
             Event                themselves).

                            It is important to note, that we cannot
                                   guarantee that there is always a
                                   reflector, but we can guarantee that
                                   one will exist at some point. When a
                                   host does exist, they should call the
                                   reflect, and the event will get done.

                            This usage pattern also has the lowest
                                 latency (for obvious reasons)

                            A good us for this pattern might be to
                                trigger the end of the round.




       Single ownership pattern
This pattern is identical to the unique
Peer       Reflecto   Peer            ownership pattern, with BIG caveat.
1          r          3
                                 No ownership means more than one peer
Signal                  Signal
                                     may try and use a resource, creating
                                     a race condition.

                                 It is the job of the reflector to resolve the
              Event                     race condition, by giving definitive
                                        ordering to the events.

                                 This pattern could be used for example to
                                      determine which player gets a
                                      weapon pick up.




         No ownership pattern
➲   A major problem still exists.
➲   The state on the peers may not be up to date (as defined as
    the state on the server).
➲   This means that peers can send signals that are no longer valid
    when they are reflected.
➲   Most obvious is referencing an object that has since been
    deleted.




                 The context issue
An example of context problem
   Peer         Reflecto    Peer       •   The object is deleted twice.
   1            r           3          •   The second delete is valid when
                                           sent, because the first delete has not
Delete object
                                           arrived yet.
                                       •   Could be solved by unique object
                           Delete object   identifiers, but...
                                       •   This is a generic problem. It occurs
                                           because the knowledge of the state
                                           is perfect, but always lags the
                                           reflector.
                                       •   Three common re-occurring causes.
                                       •   Game state change. (i.e. BE
                                           transition)
                                       •   Level state change. (i.e. end of
                                           round)
                                       •   Object state, mainly deletion.




         Example context problem
➲   Signals are tagged with the event processed last.
➲   Provide a number of context markers. Markers are updated
    with the last event the context changed.
➲   Simply compare signal tag with the context marker to see if the
    context has changed (how to handle left to user).
➲   Markers can be deleted when all peers send signals with event
    ID's greater than the marker.




                     Signal context
➲   All signals originate from non-deterministic actions (such as
    user input)
➲   Reflection translates into a deterministic flow.
➲   Once inside a deterministic event, we may not use the signal
    method to trigger more non-deterministic behaviour.




               Determinism barriers
Using signals from events problematic
                              •   Event sent to all clients
Peer 1   Reflector   Peer 3   •   We end up with multiple signals.
                              •   Could be solved by detecting
Signal                            multiple events, but...
                              •   A better way exists.




Signal               Signal




         Signal from event
➲   A good example of the single ownership pattern.
➲   Signaling from inside event handlers, causes the
    event to be stored as pending, on all machines.
➲   Peers use reflect method to cause events which are
    pending.
➲   Events are removed from the store when the event is
    seen.
➲   Pending buffer is a deterministic to non-deterministic
    barrier.




     Non Deterministic-Signal buffer
➲   Non-deterministic code can generate signals, but not change
    state.
➲   Deterministic code can change state, but not generate signals.
➲   By splitting code into deterministic and non-deterministic, we
    can do almost anything, without the need for a server.




                         Summary
➲   Events are always owned by a single “Type”, but many types
    can listen to those events.
➲   This leads to an ordering problem. If an event constructs an
    object then the event must be processed first
➲   If an event destroys an object, then the listeners must be called
    first.
➲   This is a property of the event, and can be specified on
    creation.




Construction order/destruction order
             problems
➲   Define event object .It needs pack/unpack and name.
➲   I strongly urge use of PureEvent/IntEvent/etc
➲   Inherit from EventOwner
➲   Define an event handler
➲   Initialise Event handler (with order and determinism flags)
➲   Add ReflectionHandler if required




                 Implementing code
➲   Inherit from EventListner
➲   Implement listen function.
➲   (remember the header file only needs the event structure
    name, nothing else)




                  Adding listeners
➲   We can improve network efficiency by allowing reflection as a
    translation stage.
➲   Signal->Event/Events from user defined handlers.
➲   Can also enforce that no invalid context events ever seen
    (simplifies event handling, allowing designers to write scripted
    code)




            Reflection as translation
➲   The event system provides a general purpose dispatching
    mechanism which might be of use to non-network related code.
➲   Dispatcher, with nice-ish auto-registration
➲   Events can be prototyped (not many people seem to realize
    this)
➲   Can be used for delayed (deletion order) problems




                      Code re-use
➲   How to choose the next reflector?
➲   Form voting pools.
➲   Majority vote makes host.
➲   Perhaps a vote-less algorithm can be found.
➲   Ideal would be to use external server (Matchmaking2 lobby
    messages?) as host voting reflector.
➲   Without a server, split games are possible, although merging
    split games is possible




                    Host Migration

More Related Content

Similar to Event System Presentation

Transactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsTransactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsVlad Mihalcea
 
Zookeeper Architecture
Zookeeper ArchitectureZookeeper Architecture
Zookeeper ArchitecturePrasad Wali
 
Mobile Weekend Budapest presentation
Mobile Weekend Budapest presentationMobile Weekend Budapest presentation
Mobile Weekend Budapest presentationPéter Ádám Wiesner
 
Introduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actorsIntroduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actorsdatamantra
 
Introduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsIntroduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsShashank L
 
Cryptographic authentication
Cryptographic authenticationCryptographic authentication
Cryptographic authenticationnirmal08
 
Дмитрий Копляров , Потокобезопасные сигналы в C++
Дмитрий Копляров , Потокобезопасные сигналы в C++Дмитрий Копляров , Потокобезопасные сигналы в C++
Дмитрий Копляров , Потокобезопасные сигналы в C++Sergey Platonov
 
Magento code testability: Problems and Solutions
Magento code testability: Problems and SolutionsMagento code testability: Problems and Solutions
Magento code testability: Problems and SolutionsAnton Kril
 
Building stateful systems with akka cluster sharding
Building stateful systems with akka cluster shardingBuilding stateful systems with akka cluster sharding
Building stateful systems with akka cluster shardingKnoldus Inc.
 
Inventing the future Business Programming Language
Inventing the future  Business Programming LanguageInventing the future  Business Programming Language
Inventing the future Business Programming LanguageESUG
 
Win8 development lessons learned jayway
Win8 development lessons learned jaywayWin8 development lessons learned jayway
Win8 development lessons learned jaywayAndreas Hammar
 
Alternate concurrency models
Alternate concurrency modelsAlternate concurrency models
Alternate concurrency modelsAbid Khan
 
Observables in Angular
Observables in AngularObservables in Angular
Observables in AngularKnoldus Inc.
 
Real World Event Sourcing and CQRS
Real World Event Sourcing and CQRSReal World Event Sourcing and CQRS
Real World Event Sourcing and CQRSMatthew Hawkins
 
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Go Reactive: Event-Driven, Scalable, Resilient & Responsive SystemsGo Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Go Reactive: Event-Driven, Scalable, Resilient & Responsive SystemsJonas Bonér
 

Similar to Event System Presentation (20)

Transactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsTransactions and Concurrency Control Patterns
Transactions and Concurrency Control Patterns
 
Zookeeper Architecture
Zookeeper ArchitectureZookeeper Architecture
Zookeeper Architecture
 
Mobile Weekend Budapest presentation
Mobile Weekend Budapest presentationMobile Weekend Budapest presentation
Mobile Weekend Budapest presentation
 
Introduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actorsIntroduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actors
 
Introduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsIntroduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actors
 
Cryptographic authentication
Cryptographic authenticationCryptographic authentication
Cryptographic authentication
 
Autoencoder
AutoencoderAutoencoder
Autoencoder
 
Дмитрий Копляров , Потокобезопасные сигналы в C++
Дмитрий Копляров , Потокобезопасные сигналы в C++Дмитрий Копляров , Потокобезопасные сигналы в C++
Дмитрий Копляров , Потокобезопасные сигналы в C++
 
Distributed fun with etcd
Distributed fun with etcdDistributed fun with etcd
Distributed fun with etcd
 
Magento code testability: Problems and Solutions
Magento code testability: Problems and SolutionsMagento code testability: Problems and Solutions
Magento code testability: Problems and Solutions
 
Building stateful systems with akka cluster sharding
Building stateful systems with akka cluster shardingBuilding stateful systems with akka cluster sharding
Building stateful systems with akka cluster sharding
 
70 536
70 53670 536
70 536
 
Inventing the future Business Programming Language
Inventing the future  Business Programming LanguageInventing the future  Business Programming Language
Inventing the future Business Programming Language
 
Win8 development lessons learned jayway
Win8 development lessons learned jaywayWin8 development lessons learned jayway
Win8 development lessons learned jayway
 
Alternate concurrency models
Alternate concurrency modelsAlternate concurrency models
Alternate concurrency models
 
Observables in Angular
Observables in AngularObservables in Angular
Observables in Angular
 
Real World Event Sourcing and CQRS
Real World Event Sourcing and CQRSReal World Event Sourcing and CQRS
Real World Event Sourcing and CQRS
 
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Go Reactive: Event-Driven, Scalable, Resilient & Responsive SystemsGo Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
 
Chapter17 of clean code
Chapter17 of clean codeChapter17 of clean code
Chapter17 of clean code
 
Automate Design Patterns
Automate Design PatternsAutomate Design Patterns
Automate Design Patterns
 

More from slantsixgames

Supersize your production pipe enjmin 2013 v1.1 hd
Supersize your production pipe    enjmin 2013 v1.1 hdSupersize your production pipe    enjmin 2013 v1.1 hd
Supersize your production pipe enjmin 2013 v1.1 hdslantsixgames
 
Ask the Producers Feb 8th
Ask the Producers Feb 8thAsk the Producers Feb 8th
Ask the Producers Feb 8thslantsixgames
 
Maximize Your Production Effort (English)
Maximize Your Production Effort (English)Maximize Your Production Effort (English)
Maximize Your Production Effort (English)slantsixgames
 
Maximize Your Production Effort (Chinese)
Maximize Your Production Effort (Chinese)Maximize Your Production Effort (Chinese)
Maximize Your Production Effort (Chinese)slantsixgames
 
SCons an Introduction
SCons an IntroductionSCons an Introduction
SCons an Introductionslantsixgames
 
Confrontation Pipeline and SCons
Confrontation Pipeline and SConsConfrontation Pipeline and SCons
Confrontation Pipeline and SConsslantsixgames
 
Confrontation Audio GDC 2009
Confrontation Audio GDC 2009Confrontation Audio GDC 2009
Confrontation Audio GDC 2009slantsixgames
 
Collision Detection an Overview
Collision Detection an OverviewCollision Detection an Overview
Collision Detection an Overviewslantsixgames
 
Modern Graphics Pipeline Overview
Modern Graphics Pipeline OverviewModern Graphics Pipeline Overview
Modern Graphics Pipeline Overviewslantsixgames
 
PPU Optimisation Lesson
PPU Optimisation LessonPPU Optimisation Lesson
PPU Optimisation Lessonslantsixgames
 
Supersize Your Production Pipe
Supersize Your Production PipeSupersize Your Production Pipe
Supersize Your Production Pipeslantsixgames
 

More from slantsixgames (11)

Supersize your production pipe enjmin 2013 v1.1 hd
Supersize your production pipe    enjmin 2013 v1.1 hdSupersize your production pipe    enjmin 2013 v1.1 hd
Supersize your production pipe enjmin 2013 v1.1 hd
 
Ask the Producers Feb 8th
Ask the Producers Feb 8thAsk the Producers Feb 8th
Ask the Producers Feb 8th
 
Maximize Your Production Effort (English)
Maximize Your Production Effort (English)Maximize Your Production Effort (English)
Maximize Your Production Effort (English)
 
Maximize Your Production Effort (Chinese)
Maximize Your Production Effort (Chinese)Maximize Your Production Effort (Chinese)
Maximize Your Production Effort (Chinese)
 
SCons an Introduction
SCons an IntroductionSCons an Introduction
SCons an Introduction
 
Confrontation Pipeline and SCons
Confrontation Pipeline and SConsConfrontation Pipeline and SCons
Confrontation Pipeline and SCons
 
Confrontation Audio GDC 2009
Confrontation Audio GDC 2009Confrontation Audio GDC 2009
Confrontation Audio GDC 2009
 
Collision Detection an Overview
Collision Detection an OverviewCollision Detection an Overview
Collision Detection an Overview
 
Modern Graphics Pipeline Overview
Modern Graphics Pipeline OverviewModern Graphics Pipeline Overview
Modern Graphics Pipeline Overview
 
PPU Optimisation Lesson
PPU Optimisation LessonPPU Optimisation Lesson
PPU Optimisation Lesson
 
Supersize Your Production Pipe
Supersize Your Production PipeSupersize Your Production Pipe
Supersize Your Production Pipe
 

Recently uploaded

H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Event System Presentation

  • 1. Presenting users with a consistent world without persistent clients Permanent State in a Serverless Environment
  • 2. ➲Presenting users with a persistent state is easy if you have a persistent host. ➲With a few techniques it can be done without a server, as long as clients remain in the game. ➲Primary benefit is the saving on Server hosting costs. Overview
  • 3. Traditional Model : Client/Server ➲ Server runs game logic, deciding when events occur. ➲ Game clients receive incoming events and process them (deterministically). ➲ Late-joiners can receive a snapshot of the world from the host. Server based model
  • 4. One of the clients acts as the server. ➲ That client drives the others via events. ➲ Processes events themselves. ➲ The problem is that the server “state” is never transmitted, only the client state. ➲ If the integrated server leaves, what do we do. Integrated server
  • 5. If we make the server logic “stateless” we can move the server at will. ➲ The server is now just code, that runs on one machine. The only thing the server code can do is send events. ➲ Server is non-deterministic. Client code deterministic. Integrated server (cont)
  • 6. This would suffice if only the host needs to interact with the world, and everyone else just views them. ➲ The real problem comes when we allow the clients to interact with the world as well. (clients become peers) ➲ Peers actions can overlap, creating race conditions. ➲ To resolve these race conditions we could lock resources using the host as a token server. Moving to peer-to-peer
  • 7. Tokens are often touted as a solution ➲ Peer signal requests for tokens ➲ Server grants, or refuses ➲ Peer then can control the object ➲ What if server migrates after the signal? ➲ What if peer leaves after obtaining the token? ➲ We cannot reclaim the token until the peer is definitely gone. The problem with tokens
  • 8. What if the server, merely re-broadcasts the signals, without any logic. ➲ The outgoing broadcasts are ordered, so all the peers see the signals in the same order. ➲ Peers smart enough to work out when locks fail, or succeed. ➲ Now we can implement complex behaviors. ➲ Example, can only get into a vehicle if it's empty, or occupied by a team mate. Introducing the reflector
  • 9. The reflector is like a server with no state, nor game specific logic. ➲ It is a true peer-peer logic, all clients are identical, except for the automatic reflecting of requests. ➲ Peers must remember the sent signals. If the host changes, they must resend all signals they have not seen reflected. ➲ The Reflector
  • 10. Peers send signals and handle events. ➲ The reflector reflects the signals. Reflected signals are events, and are in the same order on all machines. ➲ Signals have a unique identifier formed from machine ID and count of signals sent. ➲ Events also have a unique ID of the reflector and the event count. (also known as the event stream position) Terminology
  • 11. The reflect method is exposed on all machines. ➲ On any client who is not the reflector, the method does nothing. ➲ On the reflector, the event occurs immediately, with the event sent as normal to other clients. ➲ Reflect methods must not change state, only generate events. The Reflect Method
  • 12. Three common ownership patterns ➲ Unique ownership : no-one else can signal, clients can signal whenever they like. ➲ Single ownership : State is changed using reflect, effective like the old “server code” pattern. ➲ No/Shared Ownership: context never changes, peers signal when they wish to change state. Changes may fail. Ownership analogies
  • 13. In this example, Peer 1, wants to signal Peer Reflecto Peer something about an object they own. 1 r 3 Peer 1 call Signal, which sends a signal to the reflector. Signal The reflector calls the reflect method, and sends the results to all clients, including themselves. Event A use of this pattern might be used for example to allow a player to select their own weapon. Unique ownership pattern
  • 14. In this example, something must get Peer Reflecto Peer done, once and once only. In this 1 r 3 case we poll for the condition on each client. Each client calls the reflect method when required. Only the reflector will do anything when reflect is called, and they will send an event to all clients (including Event themselves). It is important to note, that we cannot guarantee that there is always a reflector, but we can guarantee that one will exist at some point. When a host does exist, they should call the reflect, and the event will get done. This usage pattern also has the lowest latency (for obvious reasons) A good us for this pattern might be to trigger the end of the round. Single ownership pattern
  • 15. This pattern is identical to the unique Peer Reflecto Peer ownership pattern, with BIG caveat. 1 r 3 No ownership means more than one peer Signal Signal may try and use a resource, creating a race condition. It is the job of the reflector to resolve the Event race condition, by giving definitive ordering to the events. This pattern could be used for example to determine which player gets a weapon pick up. No ownership pattern
  • 16. A major problem still exists. ➲ The state on the peers may not be up to date (as defined as the state on the server). ➲ This means that peers can send signals that are no longer valid when they are reflected. ➲ Most obvious is referencing an object that has since been deleted. The context issue
  • 17. An example of context problem Peer Reflecto Peer • The object is deleted twice. 1 r 3 • The second delete is valid when sent, because the first delete has not Delete object arrived yet. • Could be solved by unique object Delete object identifiers, but... • This is a generic problem. It occurs because the knowledge of the state is perfect, but always lags the reflector. • Three common re-occurring causes. • Game state change. (i.e. BE transition) • Level state change. (i.e. end of round) • Object state, mainly deletion. Example context problem
  • 18. Signals are tagged with the event processed last. ➲ Provide a number of context markers. Markers are updated with the last event the context changed. ➲ Simply compare signal tag with the context marker to see if the context has changed (how to handle left to user). ➲ Markers can be deleted when all peers send signals with event ID's greater than the marker. Signal context
  • 19. All signals originate from non-deterministic actions (such as user input) ➲ Reflection translates into a deterministic flow. ➲ Once inside a deterministic event, we may not use the signal method to trigger more non-deterministic behaviour. Determinism barriers
  • 20. Using signals from events problematic • Event sent to all clients Peer 1 Reflector Peer 3 • We end up with multiple signals. • Could be solved by detecting Signal multiple events, but... • A better way exists. Signal Signal Signal from event
  • 21. A good example of the single ownership pattern. ➲ Signaling from inside event handlers, causes the event to be stored as pending, on all machines. ➲ Peers use reflect method to cause events which are pending. ➲ Events are removed from the store when the event is seen. ➲ Pending buffer is a deterministic to non-deterministic barrier. Non Deterministic-Signal buffer
  • 22. Non-deterministic code can generate signals, but not change state. ➲ Deterministic code can change state, but not generate signals. ➲ By splitting code into deterministic and non-deterministic, we can do almost anything, without the need for a server. Summary
  • 23. Events are always owned by a single “Type”, but many types can listen to those events. ➲ This leads to an ordering problem. If an event constructs an object then the event must be processed first ➲ If an event destroys an object, then the listeners must be called first. ➲ This is a property of the event, and can be specified on creation. Construction order/destruction order problems
  • 24. Define event object .It needs pack/unpack and name. ➲ I strongly urge use of PureEvent/IntEvent/etc ➲ Inherit from EventOwner ➲ Define an event handler ➲ Initialise Event handler (with order and determinism flags) ➲ Add ReflectionHandler if required Implementing code
  • 25. Inherit from EventListner ➲ Implement listen function. ➲ (remember the header file only needs the event structure name, nothing else) Adding listeners
  • 26. We can improve network efficiency by allowing reflection as a translation stage. ➲ Signal->Event/Events from user defined handlers. ➲ Can also enforce that no invalid context events ever seen (simplifies event handling, allowing designers to write scripted code) Reflection as translation
  • 27. The event system provides a general purpose dispatching mechanism which might be of use to non-network related code. ➲ Dispatcher, with nice-ish auto-registration ➲ Events can be prototyped (not many people seem to realize this) ➲ Can be used for delayed (deletion order) problems Code re-use
  • 28. How to choose the next reflector? ➲ Form voting pools. ➲ Majority vote makes host. ➲ Perhaps a vote-less algorithm can be found. ➲ Ideal would be to use external server (Matchmaking2 lobby messages?) as host voting reflector. ➲ Without a server, split games are possible, although merging split games is possible Host Migration