Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: prototype runtime system #232

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/runtime-prototype/.stylish-haskell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
steps:
- imports:
align: none
list_align: with_module_name
pad_module_names: false
long_list_align: new_line_multiline
empty_list_align: inherit
list_padding: 7 # length "import "
separate_lists: false
space_surround: false
- language_pragmas:
style: vertical
align: false
remove_redundant: true
- simple_align:
cases: false
top_level_patterns: false
records: false
- trailing_whitespace: {}

# You need to put any language extensions that's enabled for the entire project
# here.
language_extensions: []

columns: 72
5 changes: 5 additions & 0 deletions src/runtime-prototype/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for stunt-double

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
3 changes: 3 additions & 0 deletions src/runtime-prototype/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Copyright (c) 2021 Symbiont Inc.

All rights reserved.
107 changes: 107 additions & 0 deletions src/runtime-prototype/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
### stunt-double

`stunt-double` is an actor implementation where the real actors can easily and
faithfully be swapped out for fakes, to make testing of distributed systems
easier.

#### Actors

* Erlang is perhaps the most commonly associated programming language when one
thinks of implementations of actor systems today

* Many other programming languages have tried to copy Erlang, e.g. Scala, Cloud
Haskell, etc.

* The concept is, of course, older: Smalltalk (1972), Hewitt, Carl; Bishop,
Peter; Steiger, Richard (1973). "A Universal Modular Actor Formalism for
Artificial Intelligence". IJCAI.

* Erlang was influenced by Smalltalk, which many people associated with OOP but
as per Alan Key's
[email](http://lists.squeakfoundation.org/pipermail/squeak-dev/1998-October/017019.html)
the key idea is actually message passing.

#### Interfaces (a.k.a. "behaviours")

* Joe Armstrong's PhD thesis "Making reliable distributed systems in the
presence of software errors" written in 2003 when he was 53 years old, he
started working on telecom systems in 1981. Quite different from a typical PhD
thesis written by a 20-something year old person with no or very little
experience from industry...

* Anyway, the thesis can perhaps best be summarised by "the big idea in Erlang
isn't messaging/actors for concurrency, but using interfaces (a.k.a.
"behaviours") to *abstract away the concurrency*" (these are not Joe's words,
but rather my interpretation)

* "network normal form"

* Examples of interfaces: gen_server, gen_supervisor, gen_fsm, gen_event. The
idea is that an application can be written by largely combining several
instances of these.

* Concurrent application becomes sequential, easier to write (especially for
less experience programmers) according to Joe

* easier to maintain, if an interface is improved or a bug fixed in it, then all
application written against the interface will benefit

* easier to test/prove according to Joe

* In the future work section of the thesis: "How can we program components - the
idea of a set of communicating processes leads naturally to the idea of
writing the components in different languages. How can we do this?"

#### Deployments

* Infrastructure is a map from machine id (ip address) to set of Vat ids

* Deployment is a supervisor tree (each actor and supervisor has a child id) and
a map from child id to machine id and Vat id

* Deploy git commit hashes or hashes of the AST (Unison-style)?

* Join two deployments (make assumptions about existing deployments)?

#### Live debugging

* Connect to (remote) event loop
* REPL
* Check crashes that happened by checking the supervisors' logs
* Check the source code of each actor
* Check the state of each actor

* Keep a ring buffer for each actor with the last X messages it received so we
can step back and forth through time and see how the state changed

* Keep a ring buffer with the latest Y crashes together with a ring buffer with
the last Y messages before that crash

#### Upgrades

* Hot-code swapping

* Automatic rollbacks

#### Automatic scaling

* E.g. kubernetes detects high resource usage on some event loop, provisions a new machine, writes to some global register that the new machine is available

#### Protocols

* Type system? Dynamic session types!


#### Capabilities

* E programming language
* [Goblins](https://spritelyproject.org/#goblins)
* OpenBSD's [pledge](https://man.openbsd.org/pledge.2) and
[unveil](https://man.openbsd.org/unveil.2)

#### Deterministic testing

#### See also

* Erlang's [supervisors](https://erlang.org/doc/man/supervisor.html);
* https://capnproto.org/
2 changes: 2 additions & 0 deletions src/runtime-prototype/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
6 changes: 6 additions & 0 deletions src/runtime-prototype/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Control.Concurrent

main :: IO ()
main = print =<< getNumCapabilities
11 changes: 11 additions & 0 deletions src/runtime-prototype/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
packages: .

with-compiler: ghc-8.10.4

reject-unconstrained-dependencies: all

package stunt-double
ghc-options: -Wall

allow-older: *
allow-newer: *
Loading