gocircuit - modrpc/info GitHub Wiki

Table of Contents

Overview

Basics

The circuit is a minimal distributed operating system that enables programmatic, reactive control over hosts, processes and connections within a compute cluster.

Spawn

The main operation provided by the Circuit Runtime is spawning a function on a remote (or local) host, in a new “worker” OS-process — in other words, in a new Go runtime. Spawning is performed by the library function circuit.Spawn, that is declared as follows:

  Spawn(host circuit.Host, anchor []string, f circuit.Func, in ...interface{}) 
      (out []interface{}, addr circuit.A
  1. arguments
    1. host: physical machine where Func is to be executed
    2. anchor: list of directories in the anchor file system
    3. f: worker function written in Go
    4. in: list of input arguments
  2. spawn semantics:
    1. A new worker process is started on the desired host and a connection is established between the parent and child circuit runtimes
    2. the worker (an OS-process) proceeds to:
      1. execute the desired worker function
      2. send its return values back to the parent process, and
      3. die immediately after
    3. the calling process receives the return values (or detects failure) and returns (unblocks) from the call to Spawn

Worker Functions

  • Functions to be executed remotely using the Spawn command.
  import "circuit/use/circuit"
  type MyWorkerFunc struct{}

  func (MyWorkerFunc) SingletonMethod(greeting string) (response string) {
	return "Hello " + greeting
  }
  func init() {
	circuit.RegisterFunc(MyWorkerFunc{})
  }

Communicating Across Workers

  • Two situations: where data transferred between worker processes
    • cross calls (= Spawn): spawning worker functions
    • cross invocations (= Cross-interfaces): invoking methods of objects that live on remote workers

Values: Marshalling

  • If function arguments or return value have concrete (non-interface) types, then whenever this function is cross-called the supplied Go value will be transported across the network by value.
    • it will be flattened recursively, serialized and consequently reconstructed in the same form at the receiving worker's Go runtime environment

Cross-Interfaces

  • (Pure) Go interface is a value, which embodies some state along with a list of callable methods over the underlying state
  • GoCircuit cross-interface is different from pure Go interface in that it can refer to an underlying object that lives in a process other than the currently executing one
⚠️ **GitHub.com Fallback** ⚠️