Skip to content

Commit

Permalink
add support for actor runtime config, to make idle timeout scanning a…
Browse files Browse the repository at this point in the history
…nd gc of runtime actor in effective dapr#334

Signed-off-by: wangxw <[email protected]>
  • Loading branch information
wXwcoder committed Nov 14, 2022
1 parent c2dfec6 commit 3774c94
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
34 changes: 33 additions & 1 deletion actor/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import "github.com/dapr/go-sdk/actor/codec/constant"

// ActorConfig is Actor's configuration struct.
type ActorConfig struct {
SerializerType string
SerializerType string
ActorIdleTimeout string
ActorScanInterval string
DrainOngingCallTimeout string
DrainBalancedActors bool
}

// Option is option function of ActorConfig.
Expand All @@ -30,6 +34,34 @@ func WithSerializerName(serializerType string) Option {
}
}

// WithActorIdleTimeout set actorIdleTimeout type of the actor as @actorIdleTimeout.
func WithActorIdleTimeout(actorIdleTimeout string) Option {
return func(config *ActorConfig) {
config.ActorIdleTimeout = actorIdleTimeout
}
}

// WithActorScanInterval set actorScanInterval type of the actor as @actorScanInterval.
func WithActorScanInterval(actorScanInterval string) Option {
return func(config *ActorConfig) {
config.ActorScanInterval = actorScanInterval
}
}

// WithDrainOngingCallTimeout set drainOngingCallTimeout type of the actor as @drainOngingCallTimeout.
func WithDrainOngingCallTimeout(drainOngingCallTimeout string) Option {
return func(config *ActorConfig) {
config.DrainOngingCallTimeout = drainOngingCallTimeout
}
}

// WithDrainBalancedActors set drainBalancedActors type of the actor as @drainBalancedActors.
func WithDrainBalancedActors(drainBalancedActors bool) Option {
return func(config *ActorConfig) {
config.DrainBalancedActors = drainBalancedActors
}
}

// GetConfigFromOptions get final ActorConfig set by @opts.
func GetConfigFromOptions(opts ...Option) *ActorConfig {
conf := &ActorConfig{
Expand Down
8 changes: 8 additions & 0 deletions actor/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ func TestRegisterActorTimer(t *testing.T) {
t.Run("get config with option", func(t *testing.T) {
config := GetConfigFromOptions(
WithSerializerName("mockSerializerType"),
WithActorIdleTimeout("1m"),
WithActorScanInterval("10s"),
WithDrainOngingCallTimeout("10s"),
WithDrainBalancedActors(true),
)
assert.NotNil(t, config)
assert.Equal(t, "mockSerializerType", config.SerializerType)
assert.Equal(t, "1m", config.ActorIdleTimeout)
assert.Equal(t, "10s", config.ActorScanInterval)
assert.Equal(t, "10s", config.DrainOngingCallTimeout)
assert.Equal(t, true, config.DrainBalancedActors)
})
}
4 changes: 4 additions & 0 deletions actor/runtime/actor_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (r *ActorRunTime) RegisterActorFactory(f actor.Factory, opt ...config.Optio
conf := config.GetConfigFromOptions(opt...)
actType := f().Type()
r.config.RegisteredActorTypes = append(r.config.RegisteredActorTypes, actType)
r.config.ActorIdleTimeout = conf.ActorIdleTimeout
r.config.ActorScanInterval = conf.ActorScanInterval
r.config.DrainOngingCallTimeout = conf.DrainOngingCallTimeout
r.config.DrainBalancedActors = conf.DrainBalancedActors
mng, ok := r.actorManagers.Load(actType)
if !ok {
newMng, err := manager.NewDefaultActorManager(conf.SerializerType)
Expand Down

0 comments on commit 3774c94

Please sign in to comment.