Git Product home page Git Product logo

lockstep's Introduction

Lockstep

A Java framework for running interactive simulations across a network.

About

The problem:

  • We have a large simulation that we want to run on several machines on a network
  • Commands may be sent to the simulation at any time, by any machine
  • Each machine must see the exact same simulation

There are two approaches:

  1. Client-server: One participant runs the whole simulation and sends periodic state-updates to all clients. The server is the single-source-of-truth.
  2. Peer-to-peer: Every participant runs the simulation deterministicly. Interactive commands must be coordinated to ensure everyone is in-sync.

The problem with the former approach is that it scales poorly with simulation size. The problem with the latter approach is that it scales poorly with participant count. The best trade-off will be application specific.

This is a framework for the peer-to-peer approach.

Overview

  • Peers report their progress to each other
  • Each peer only runs n ticks ahead of the slowest peer, waiting if necessary
  • Actions are scheduled >n ticks ahead of the slowest peer, ensuring they are always executed at the right time

The framework takes care of all of this.

The programmer must ensure:

  • The simulation is deterministic
  • Actions can be encoded and decoded properly

Get Started

  • Lockstep/ contains the framework; LockstepSample/ contains an example application.
  • Each has an Ant build file, or they can be imported into Eclipse.
  • See io.njlr.lockstep.sample.Main for an example of how it fits together.
  • Take a look at io.njlr.lockstep.sample.tests.SyncTests for an example of two peers running a simulation.

Future Work

  • Use sliding window protocol as the reliable transport mechanism for greater throughput
  • Implement channel layers e.g. for fragmenting large packets
  • Add a channel-timeout mechanism
  • Allow for the coordinated dropping of peers (e.g. participant crashes, quits)
  • Provide automatic state hash checking e.g. by including the hash with sequence number updates
  • Build a more interesting example simulation

See Also

lockstep's People

Contributors

nlr avatar njlr avatar

Stargazers

江宁周杰伦 avatar  avatar LeekingWeng avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.