Note
asyncmachine-go is a declarative control flow library implementing AOP and Actor Model through a clock-based state machine.
go-libp2p-pubsub-benchmark compares the default
go-libp2p-pubsub implementation to the asyncmachine version.
It runs TestSimpleDiscovery
for various host/msg configurations and presents a median for each iteration. The best
way to view the results is bench.md,
bench.pdf. Single runs can
be viewed in Jaeger and am-dbg after task test-discovery
. Benchmark uses go1.22 traces, thus needs at least this
version.
- pubsub host - eg
ps-17
(20 states)
PubSub state machine is a simple event loop with multi states which get responses via arg channels. Heavy use ofMachine.Eval()
. - discovery - eg
ps-17-disc
(10 states)
Discovery state machine is a simple event loop with multi states and a periodic refresh state. - discovery bootstrap - eg
ps-17-disc-bf3
(5 states)
BootstrapFlow
is a non-linear flow for topic bootstrapping with some retry logic.
See states structure and relations (pubsub host)
package states
import am "github.com/pancsta/asyncmachine-go/pkg/machine"
// States define relations between states
var States = am.Struct{
// peers
PeersPending: {},
PeersDead: {},
GetPeers: {Multi: true},
// peer
PeerNewStream: {Multi: true},
PeerCloseStream: {Multi: true},
PeerError: {Multi: true},
PublishMessage: {Multi: true},
BlacklistPeer: {Multi: true},
// topic
GetTopics: {Multi: true},
AddTopic: {Multi: true},
RemoveTopic: {Multi: true},
AnnouncingTopic: {Multi: true},
TopicAnnounced: {Multi: true},
// subscription
RemoveSubscription: {Multi: true},
AddSubscription: {Multi: true},
// misc
AddRelay: {Multi: true},
RemoveRelay: {Multi: true},
IncomingRPC: {Multi: true},
AddValidator: {Multi: true},
RemoveValidator: {Multi: true},
}
See states structure and relations (discovery & bootstrap)
package discovery
import am "github.com/pancsta/asyncmachine-go/pkg/machine"
// S is a type alias for a list of state names.
type S = am.S
// States define relations between states.
var States = am.Struct{
Start: {
Add: S{PoolTimer},
},
PoolTimer: {},
RefreshingDiscoveries: {
Require: S{Start},
},
DiscoveriesRefreshed: {
Require: S{Start},
},
// topics
DiscoveringTopic: {
Multi: true,
},
TopicDiscovered: {
Multi: true,
},
BootstrappingTopic: {
Multi: true,
},
TopicBootstrapped: {
Multi: true,
},
AdvertisingTopic: {
Multi: true,
},
StopAdvertisingTopic: {
Multi: true,
},
}
// StatesBootstrapFlow define relations between states for the bootstrap flow.
var StatesBootstrapFlow = am.Struct{
Start: {
Add: S{BootstrapChecking},
},
BootstrapChecking: {
Remove: BootstrapGroup,
},
DiscoveringTopic: {
Remove: BootstrapGroup,
},
BootstrapDelay: {
Remove: BootstrapGroup,
},
TopicBootstrapped: {
Remove: BootstrapGroup,
},
}
// Groups of mutually exclusive states.
var (
BootstrapGroup = S{DiscoveringTopic, BootstrapDelay, BootstrapChecking, TopicBootstrapped}
)
See github.com/pancsta/go-libp2p-pubsub-benchmark or the pdf results for more info.
Go back to the monorepo root to continue reading.