Louis Thibault
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Introduction This repository demonstrates how to use Wetware to write distributed systems. It contains a simple application that schedules jobs for execution in a distributed worker pool. A single scheduler node exposes a REST API for scheduling "tasks", and distributes them pseudorandomly to workers via Cap'n Proto RPC. The scheduler discovers worker nodes using Wetware's zero-conf clustering API, and can adapt to works joining and leaving the network dynamically. ## Running it locally ### Installation 1. Clone the repository: ```bash git clone https://github.com/evan-schott/ww-scheduler.git ### First run 1. Build the single application binary: ```bash cd ww-scheduler && go build -o ww-sched cmd/scheduler/main.go ``` 2. Start the gateway node: ```bash ./ww-sched --gateway #Example Output: 12D3KooWKggVqaYBwJvCCFNV8zNqCQS6rbSMKTafjmMBH2pZpZ8t ``` 3. Start a worker and add it to the gateway's pool ```bash ./ww-sched --dial 12D3KooWKggVqaYBwJvCCFNV8zNqCQS6rbSMKTafjmMBH2pZpZ8t ``` The application is now deployed and ready to service requests. Under the hood, Wetware has automatically provided the following: - **Peer discovery:** Wetware peers automatically find each other via a configurable bootstrap system. By default, peers locate each other using a protocol that is similar to [mDNS](https://en.wikipedia.org/wiki/Multicast_DNS), but more scalable. - **Clustering:** Wetware peers automatically connect to form an efficient overlay network, which they use to maintain mutual awareness. Each peer is able to detect the presence of other peers, and negotiate network connections. - **Routing:** Peers can route data and network connections to each other, using each peer's unique identifier. - **Services:** Wetware provides a set of cluster-oriented services upon which to build applications. The present demo makes use of Wetware's native support for [Cap'n Proto's RPC](https://capnproto.org/rpc.html), which provides a compact data encoding, a latency-aware RPC API, and security through object-capabilities. ## Architecture ### Architecture of the Wetware Stack - Bootstrapping - Explain the bootstrapping problem - Peers can use p2p algos to find other peers - ... but how do I discover the first peer? - About ww's pluggable bootstrap architecture - Ww's stance: no one-size-fits-all solution - Provide Go interface called `Discovery`; implementations include - Static bootstrap nodes - Multicast UDP - Public boot server (centralized) - Crawl IP range (CIDR block) - List of static boot nodes - User-defined implementations - About the multicast udp boot service - How it works - Relation to mDNS (= "why not just use mDNS?") - Brief note about docker: how and why it works in containers - Brief note about UDP multicast in cloud environments: - It's generally not enabled - Use another bootstrap service, e.g.: - public boot server (centralized) - list of static boot nodes - crawl a CIDR block (surprisingly good experience) - Clustering - Problem statement: how can I group a set of computers together in a way that allows each computer to enumerate its peers? - Ww's stance: - There is a one-size-fits all solution - ... but it requires sacrifices - Solution is: [PA/EL](https://en.wikipedia.org/wiki/PACELC_theorem) system - Reliable systems can be built on top of unreliable parts - Model the cluster as: - Unreliable - Asynchronous - Stateful - Concurrent - Sacrifices are: - Consistency is an application concern - Users have to know what they are doing - Rationale: - "Sharp tools are useful" (e.g. the C language) - Today's "[The free lunch is over](http://www.gotw.ca/publications/concurrency-ddj.htm)" is distribution - Routing - Problem statement: how can peers form connections with each other and transmit data? - Ww's stance: this is provided to us by libp2p - Solution is: - "Process addressing" - Each process has its own peer.ID - Each process multiplexes data into "streams" - Each "stream" has a handler, analogous to HTTP - DHT - Immutable "records" - High persistence: records persist after hosts leave - Low liveness: updates slow to propagate - Records are - Immutable - Cryptographically signed & authenticated - PubSub - High-liveness "stream" of raw data - High liveness: responsive/updates propagate quickly - Low persistence: hosts must be online - Stream is pubsub topic - Asynchronous - Unreliable - Cryptographically signed & authenticated - Routed Host - Network interface for managing multiplexed streams between peers - Employs DHT & PubSub to route by global peer ID - Services - Problem Statement: what global services can be provided to the application? - Ww's stance: - The real world is a PA/EL system - never lie to the user about that. - Solution is: API design - Data is immutable - RPC calls are asynchronous - Security is provided by object capabilities - Sacrifices are: - APIs cannot offer any consistency guarantees - Rationale: - Consistent APIs can be built from inconsistent APIs - We can offer a standard library of commonly-used consistency protocols - Two-Phase Commit - Three-Phase Commit - Synchronous Consistency - RAFT - Paxos - Non-Byzantine Eventual Consistency - CRDT Log - Byzantine Eventual Consistency - Block Chain (probably L2 integration of some kind) ### Application Architecture - Gateway node: - Services used - Boot - Clustering - Routing - RPC - CSP - Application layer - HTTP REST server - Task Scheduling logic - Worker node - Services used - Boot - Clustering - Routing - RPC - CSP - Application layer - Cap'n Proto `Worker` capability - Executes WASM payload when told to by gateway node - WASM runtime - Executes arbitrary WASM bytecode ------ // In one shell to run gateway: (output will contain gateway peerID) go run cmd/scheduler/main.go --gateway true // In other shells to run workers go run cmd/scheduler/main.go --dial [INSERT GATEWAY PEERID] 12D3KooWKggVqaYBwJvCCFNV8zNqCQS6rbSMKTafjmMBH2pZpZ8t ``` # Running it with docker TODO: add docker config instructions # In more depth ## 1 Bootstrapping A node joins the wetware cluster by bootstrapping to a peer in the network. This procedure involves sending and listening for discover packets in the multicast group specified in the header flags. In order to view all the packets you download [casm](https://github.com/wetware/casm)and run `casm cluster ls` . <details><summary>Example Output</summary> ``` [0000] Got multicast packet (171 byte) type: survey namespace: ww size: 171 bytes peer: 12D3KooWKggVqaYBwJvCCFNV8zNqCQS6rbSMKTafjmMBH2pZpZ8t distance: 255 [0000] Got multicast packet (217 byte) type: response namespace: ww size: 217 bytes peer: 12D3KooWQdc1sHWeBqbWuCPZEG5gjLy4tWrc8ppKYTRAMq4upeTP [0006] Got multicast packet (171 byte) type: survey namespace: ww size: 171 bytes peer: 12D3KooWQdc1sHWeBqbWuCPZEG5gjLy4tWrc8ppKYTRAMq4upeTP distance: 255 [0006] Got multicast packet (217 byte) type: response namespace: ww size: 217 bytes peer: 12D3KooWKggVqaYBwJvCCFNV8zNqCQS6rbSMKTafjmMBH2pZpZ8t [0009] Got multicast packet (171 byte) type: survey namespace: ww size: 171 bytes peer: 12D3KooWKggVqaYBwJvCCFNV8zNqCQS6rbSMKTafjmMBH2pZpZ8t distance: 255 [0009] Got multicast packet (217 byte) type: response namespace: ww size: 217 bytes peer: 12D3KooWQdc1sHWeBqbWuCPZEG5gjLy4tWrc8ppKYTRAMq4upeTP ``` </details> ## 2. Capabilities Capabilities are fundamental to the access control model of Wetware. A process must own a capability from another process in order to call RPCs. Capabilities can be broadcasted as demonstrated with: ```go // Create synchronous channel server on Gateway server and export it // Now any node on network can send to our channel server by using the channel capability ch := csp.NewChan(&csp.SyncChan{}) defer ch.Close(c.Context) n.Vat.Export(chanCap, chanProvider{ch}) ``` Capabilities can also be sent privately by way of transmission through a channel. ```go // Setup of the worker capability. Start a worker server, and derive a client from it. server := worker.WorkerServer{} // Block until we're able to send our worker capability to the // gateway server. This is where the load-balancing happens. // We are competing with other Send()s, and the gateway will // pick one of the senders at random each time it handles an // HTTP request. e := capnp.Client(worker.Worker_ServerToClient(server)) err = ch.Send(context.Background(), csp.Client(e)) ``` ## 3. Channel Server The channel server is a fundamental primitive for interprocess communication (IPC). Here are the primary differences between using PubSub and using channels for IPC: | Property | Channel | PubSub | ------------- |:-------------:|:-----:| | Reliability | Every object sent to the channel server will be held onto until it is received. | Packets will be dropped once buffer capacity is hit. | | Ordering | If a receive request arrives at the channel server before another receive request, then it will return a value from a send request that arrived to the channel before the send request value returned to the later receive request | No ordering guarantees. | | Synchrony | A call to send an object to the channel server will block until the value is successfully received. Likewise a call to receive an object from the channel will block until an object is available. | No synchrony guarantees. | | Medium | Uses unicast | Uses multicast | ## 4. Layering (Libp2p, Cap'n Proto, Casm, Wetware) Libp2p: (Networking stack) - "Host" abstraction to represent node in network. - "Connections" abstraction of transport layer link between two peers that can support multiple "Streams" on top of them to represent different communication topics. Cap'n Proto: (RPC protocol) - "Capabilities" abstraction to represent permission for making calls on remote objects. - Architecture for configuring dynamic configuration of capabilities between hosts. - Efficient serialization scheme - Promise pipelining Casm: (Low level cluster primitives) - Merger between Cap'n Proto and Libp2p layers to allow for capabilities sharing on cluster of Libp2p Hosts. - Bootstrap protocol for joining cluster to peers on cluster and forming cluster. Wetware: (Cluster middleware) - Higher level primitives for IPC (PubSub and Channels), shared memory (Anchors), processes, and querying information about cluster state. ## 5. WASM In this example, the "tasks" that can be scheduled on worker nodes take the form of hash puzzles. But really any .wasm file can be used as a task. The directions below outline how the tasks are compiled, and then how to make requests to the cluster to execute the tasks. ``` // To compile hash.go into a .wasm representation tinygo build -o wasm/hash.wasm -target=wasi hash.go // To schedule a difficulty 3 hash puzzle with seed "0", that will start 1 second after it is received, and repeat every 2 seconds for 3 iterations. curl -X POST -H "Content-Type: multipart/form-data" \ -F "id=task1" \ -F "description=Hash puzzle" \ -F "complete=0" \ -F "duration=5" \ -F "start=1" \ -F "delay=2" \ -F "repeats=3" \ -F "wasm=@hash.wasm" \ -F "input=0" \ -F "difficulty=3" \ http://localhost:8080/tasks // To see the current state of jobs, and their progress towards completion curl -X GET http://localhost:8080/tasks ``` # In action - Link to video TODO: create video

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully