simulationdeterministicfoundationdb

How to implement deterministic single threaded network simulation


I read about how FoundationDB does its network testing/simulation here: http://www.slideshare.net/FoundationDB/deterministic-simulation-testing

I would like to implement something very similar, but cannot figure out how they actually did implement it. How would one go about writing, for example, a C++ class that does what they do. Is it possible to do the kind of simulation they do without doing any code generation (as they presumeably do)?

Also: How can a simulation be repeated, if it contains random events?? Each time the simulation would require to choose a new random value and thus be not the same run as the one before. Maybe I am missing something here...hope somebody can shed a bit of light on the matter.


Solution

  • You can find a little bit more detail in the talk that went along with those slides here: https://www.youtube.com/watch?v=4fFDFbi3toc

    As for the determinism question, you're right that a simulation cannot be repeated exactly unless all possible sources of randomness and other non-determinism are carefully controlled. To that end:

    (1) Generate all random numbers from a PRNG that you seed with a known value.

    (2) Avoid any sort of branching or conditionals based on facts about the world which you don't control (e.g. the time of day, the load on the machine, etc.), or if you can't help that, then pseudo-randomly simulate those things too.

    (3) Ensure that whatever mechanism you pick for concurrency has a mode in which it can guarantee a deterministic execution order.

    Since it's easy to mess all those things up, you'll also want to have a way of checking whether determinism has been violated.

    All of this is covered in greater detail in the talk that I linked above.