Skip to content

Commit 53599ae

Browse files
committed
.
1 parent 8c90bda commit 53599ae

File tree

7 files changed

+25
-10
lines changed

7 files changed

+25
-10
lines changed

cluster/gossiper.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func (g *Gossiper) RegisterConsensusCheck(key string, getValue func(*anypb.Any)
174174

175175
func (g *Gossiper) StartGossiping() error {
176176
var err error
177+
g.cluster.Logger().Info("Starting gossip")
177178
g.pid, err = g.cluster.ActorSystem.Root.SpawnNamed(actor.PropsFromProducerWithActorSystem(func(system *actor.ActorSystem) actor.Actor {
178179
return NewGossipActor(
179180
g.cluster.Config.GossipRequestTimeout,
@@ -221,7 +222,7 @@ func (g *Gossiper) Shutdown() {
221222
}
222223

223224
func (g *Gossiper) gossipLoop() {
224-
g.cluster.Logger().Info("Starting gossip loop")
225+
g.cluster.Logger().Debug("Starting gossip loop")
225226

226227
// create a ticker that will tick each GossipInterval milliseconds
227228
// we do not use sleep as sleep puts the goroutine out of the scheduler
@@ -231,26 +232,31 @@ breakLoop:
231232
for !g.cluster.ActorSystem.IsStopped() {
232233
select {
233234
case <-g.close:
234-
g.cluster.Logger().Info("Stopping Gossip Loop")
235+
g.cluster.Logger().Debug("Stopping Gossip Loop")
235236
break breakLoop
236237
case <-ticker.C:
237-
238+
g.cluster.Logger().Debug("Gossip Loop Tick")
238239
g.blockExpiredHeartbeats()
239240
g.blockGracefullyLeft()
240-
241241
g.SetState(HearthbeatKey, &MemberHeartbeat{
242-
// todo collect the actor statistics
243242
ActorStatistics: &ActorStatistics{
244-
ActorCount: GetActorCount(),
243+
ActorCount: g.GetActorCount(),
245244
},
246245
})
247246
g.SendState()
248247
}
249248
}
250249
}
251250

252-
func GetActorCount() map[string]int64 {
251+
func (g *Gossiper) GetActorCount() map[string]int64 {
253252
m := make(map[string]int64)
253+
clusterKinds := g.cluster.GetClusterKinds()
254+
for _, kindName := range clusterKinds {
255+
kind := g.cluster.GetClusterKind(kindName)
256+
m[kindName] = int64(kind.count)
257+
}
258+
g.cluster.Logger().Debug("Actor Count", slog.Any("count", m))
259+
254260
return m
255261
}
256262

examples/actor-inprocess-benchmark/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module inprocessbenchmark
22

33
go 1.21
44

5-
require github.com/asynkron/protoactor-go v0.0.0-20240116091649-93e384a26d0d
5+
require github.com/asynkron/protoactor-go v0.0.0-20240406090656-8c90bda12e81
66

77
require (
88
github.com/Workiva/go-datastructures v1.1.1 // indirect

examples/actor-inprocess-benchmark/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ github.com/Workiva/go-datastructures v1.1.1 h1:9G5u1UqKt6ABseAffHGNfbNQd7omRlWE5
22
github.com/Workiva/go-datastructures v1.1.1/go.mod h1:1yZL+zfsztete+ePzZz/Zb1/t5BnDuE2Ya2MMGhzP6A=
33
github.com/asynkron/protoactor-go v0.0.0-20240116091649-93e384a26d0d h1:/hjPIUib6lReKTncaTIW6FMwO/2sa2Kgv9TCDODZDpo=
44
github.com/asynkron/protoactor-go v0.0.0-20240116091649-93e384a26d0d/go.mod h1:4KJf8vAca0fX3EShIBwyY77HV8NldoO1RzFGNlNkjWA=
5+
github.com/asynkron/protoactor-go v0.0.0-20240406090656-8c90bda12e81 h1:n/hoTcXlJ24nczsq8KwJu/hwTiuwvLZ91+WBhcWJncc=
6+
github.com/asynkron/protoactor-go v0.0.0-20240406090656-8c90bda12e81/go.mod h1:kFxBmdgouTsJa56gCYYZBW+0NR3RFi+g55AvxQ5ye0g=
57
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
68
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
79
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
Binary file not shown.

examples/cluster-gossip/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
google.golang.org/protobuf v1.31.0
88
)
99

10-
require github.com/asynkron/protoactor-go v0.0.0-20240116091649-93e384a26d0d
10+
require github.com/asynkron/protoactor-go v0.0.0-20240406090656-8c90bda12e81
1111

1212
require (
1313
github.com/Workiva/go-datastructures v1.1.1 // indirect

examples/cluster-gossip/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/asynkron/gofun v0.0.0-20220329210725-34fed760f4c2 h1:jEsFZ9d/ieJGVrx3
1717
github.com/asynkron/gofun v0.0.0-20220329210725-34fed760f4c2/go.mod h1:5GMOSqaYxNWwuVRWyampTPJEntwz7Mj9J8v1a7gSU2E=
1818
github.com/asynkron/protoactor-go v0.0.0-20240116091649-93e384a26d0d h1:/hjPIUib6lReKTncaTIW6FMwO/2sa2Kgv9TCDODZDpo=
1919
github.com/asynkron/protoactor-go v0.0.0-20240116091649-93e384a26d0d/go.mod h1:4KJf8vAca0fX3EShIBwyY77HV8NldoO1RzFGNlNkjWA=
20+
github.com/asynkron/protoactor-go v0.0.0-20240406090656-8c90bda12e81 h1:n/hoTcXlJ24nczsq8KwJu/hwTiuwvLZ91+WBhcWJncc=
21+
github.com/asynkron/protoactor-go v0.0.0-20240406090656-8c90bda12e81/go.mod h1:kFxBmdgouTsJa56gCYYZBW+0NR3RFi+g55AvxQ5ye0g=
2022
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
2123
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
2224
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=

examples/cluster-gossip/node1/main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ func startNode() *cluster.Cluster {
4646
case *cluster.ClusterTopology:
4747
fmt.Printf("\nClusterTopology %v\n\n", msg)
4848
case *cluster.GossipUpdate:
49-
fmt.Printf("\nGossipUpdate %v\n\n", msg)
49+
50+
as := &cluster.ActorStatistics{}
51+
52+
if unpackErr := msg.Value.UnmarshalTo(as); unpackErr != nil {
53+
fmt.Printf("\nActorStatistics %v\n\n", as)
54+
}
5055
}
5156
})
5257

0 commit comments

Comments
 (0)