Is your feature request related to a problem? Please describe.
In gRelay v0.0.x the default config is using goroutines which costs a lot of memory allocation as you can see in benchmark folder. To improve our future features, we need to do a refactor in our system.
Describe the solution you'd like
We would like to have an interface:
type grelayExec interface {
exec(service GrelayService, func() (interface{}, error)) (interface{}, error)
}
and an implementation of this interface:
type grelayExecWithGo struct {}
func (e grelayExecWithGo) exec(service GrelayService, func() (interface{}, error)) (interface{}, error) {
// implementation
}
Change the grelayServiceImpl struct:
type grelayServiceImpl struct {
// ...
realExec grelayExec
// ...
}
In NewGrelayService
creates grelayExecWithGo:
func NewGrelayService(c GrelayConfig) GrelayService {
var re grelayExec
if c.withGo {
re = grelayExecWithGo{}
}
g := &grelayServiceImpl{
// ...
realExec: re
}
// ...
}
In GrelayConfig include WithGo
method and withGo
attribute (put withGo = true as default in the future it will be false):
type GrelayConfig struct {
// ...
withGo bool
}
func NewGrelayConfig() GrelayConfig {
return GrelayConfig{
withGo: true,
}
}
func (c GrelayConfig) WithGo() GrelayConfig {
c.withGo = true
return c
}
move grelayServiceImpl.exec(f func() (interface{}, error))
to grelayExecWithGo.exec(service GrelayService, func() (interface{}, error))
. In the final, we would like to have the grelayServiceImpl.exec(f func() (interface{}, error))
like that:
func (g *grelayServiceImpl) exec(f func() (interface{}, error)) (interface{}, error) {
return g.realExec.exec(g, f)
}