tree_state_source

command
v0.19.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

/examples/tree_state_source

cd /

[!NOTE] asyncmachine-go is a batteries-included graph control flow library (AOP, actor model, state-machine).

State source of flight statuses - in the real world this data-oriented problem should be modelled using composition and handler delegation, but it's flat in this example for simplicity and research purposes.

Source available at /examples/tree_state_source.

States

The repo version has 5 flights and 3 gates (149 states). The amount of flights and gates can be adjusted and re-generated using go run ./gen_states. Full schema file is available at states/ss_flights.go. Sample definition without relations can be found below.

// FlightsStatesDef contains all the states of the Flights state machine.
type FlightsStatesDef struct {
    *am.StatesBase

    Flight1OnTime string
    Flight1Delayed string
    Flight1Departed string
    Flight1Arrived string
    Flight1Scheduled string
    Flight1Inbound string
    Flight1Outbound string
    Flight1GoToGate string
    Flight1GateUnknown string
    Flight1Gate1 string
    Flight1Gate2 string
    Flight1Gate3 string
    Flight1Gate4 string
    Flight1Gate5 string

    // ...

    // inherit from BasicStatesDef
    *ssam.BasicStatesDef
    // inherit from rpc/NetSourceStatesDef
    *ssrpc.NetSourceStatesDef
}

Actors

  • root
  • replicant L1
  • replicant L2

Scenario:

  • root process runs the flight-status state machine
  • replicants of the 1st level connect to the root
  • replicants of the 2st level connect to replicants of the 1st level
  • state clocks flow from the root to replicants
  • http clients GET active states from the 2nd level replicants
  • all state machines are connected to am-dbg, prometheus, and loki

Running

From the monorepo root:

  1. task web-metrics
  2. task gen-grafana-tree-state-source
  3. task start
  4. http://localhost:3000 -> Dashboards -> tree-state-source

Possibilities

  • L1 and L2 replicants can execute handlers locally (TODO)
  • root-L1 can have shorter push interval than L1-L2

Benchmark

HTTP endpoints have been benchmarked using go-wrk, see /examples/benchmark_state_source for more info.

Config

Config available in the .env file.

# grafana sync

GRAFANA_TOKEN=
GRAFANA_URL=http://localhost:3000

# metrics

PUSH_GATEWAY_URL=http://localhost:9091
LOKI_ADDR=localhost:3100
AM_LOG=3

# AM debugging

#AM_DEBUG=1
#AM_DBG_ADDR=:6831
#AM_HEALTHCHECK=1

#AM_RPC_LOG_SERVER=1
#AM_RPC_LOG_CLIENT=1
#AM_RPC_LOG_MUX=1

#AM_NODE_LOG_SUPERVISOR=1
#AM_NODE_LOG_CLIENT=1
#AM_NODE_LOG_WORKER=1

monorepo

Go back to the monorepo root to continue reading.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL