About V300 #174
Replies: 18 comments 7 replies
-
Hi, |
Beta Was this translation helpful? Give feedback.
-
Hello, I’m currently trying to use the V300 branch for beta development. However, I noticed that the actor.Call function frequently times out during usage. I’m wondering if I’m using it incorrectly or if there might be another issue causing this problem. Could you please provide me with some guidance or assistance on this matter? Thank you.
…________________________________
发件人: Taras Halturin ***@***.***>
发送时间: 2024年2月19日 2:42
收件人: ergo-services/ergo ***@***.***>
抄送: Kirin ***@***.***>; Author ***@***.***>
主题: Re: [ergo-services/ergo] About V300 (Discussion #174)
Hi,
Its in progress now and will be published along with the release 3.0.
―
Reply to this email directly, view it on GitHub<#174 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AI652E2VZ3EAB2GRU6FRHF3YUJDR7AVCNFSM6AAAAABDN2COS2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DKMBZGEYDC>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
func GetNodeById(process gen.Process, id string) (gen.Atom, bool, error) {
reply, err := process.Call(gen.Atom("#cluster"), sync_search_node_by_id{id: id})
if err != nil {
return "", false, errors.WithMessage(err, "get node by id failed")
}
ret := reply.(sync_search_node_by_id_ret)
return ret.node, ret.ok, nil
}
func CallById(process gen.Process, to any, id string, msg any) (any, error) {
node, ok, err := GetNodeById(process, id)
if err != nil {
return nil, errors.WithMessage(err, "'CallById' get remote game node failed")
}
if !ok {
return nil, ErrServerNotFound
}
fmt.Println(node)
switch target := to.(type) {
case gen.Alias:
return process.CallAlias(target, msg, 5)
case gen.PID:
return process.CallPID(target, msg, 5)
case string:
return process.CallProcessID(gen.ProcessID{Name: gen.Atom(target), Node: node}, msg, 5)
case gen.Atom:
return process.CallProcessID(gen.ProcessID{Name: target, Node: node}, msg, 5)
default:
process.Log().Error("'SendById' unknown target type: %T", target)
return nil, nil
}
}
Just like this, when calling with the same node, there may be a timeout. When calling with a remote node, the other party does not fail to receive the call, but is unable to effectively return. However, returning “nil, errors.New(“xxx”)” will succeed in returning, but it will not terminate the blocking of the Call invocation.
…________________________________
发件人: Taras Halturin ***@***.***>
发送时间: 2024年3月5日 17:17
收件人: ergo-services/ergo ***@***.***>
抄送: Kirin ***@***.***>; Author ***@***.***>
主题: Re: [ergo-services/ergo] About V300 (Discussion #174)
Could you please share the way you use it?
―
Reply to this email directly, view it on GitHub<#174 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AI652EZVSOKSUNHGKXVZ4LTYWWERPAVCNFSM6AAAAABDN2COS2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DMNZXGQ4DO>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
It is not allowed to use |
Beta Was this translation helpful? Give feedback.
-
here is an example you might find useful https://github.com/ergo-services/examples/tree/v300 |
Beta Was this translation helpful? Give feedback.
-
However, timeout can also occur when using it internally.
…________________________________
发件人: Taras Halturin ***@***.***>
发送时间: 2024年3月5日 17:58
收件人: ergo-services/ergo ***@***.***>
抄送: Kirin ***@***.***>; Author ***@***.***>
主题: Re: [ergo-services/ergo] About V300 (Discussion #174)
here is an example you might find useful https://github.com/ergo-services/examples/tree/v300
―
Reply to this email directly, view it on GitHub<#174 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AI652EYULLE3355VX343EU3YWWJK7AVCNFSM6AAAAABDN2COS2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DMNZXHE4TK>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
default timeout for Call requests is 5 seconds. Make sure your process (that handles this request) is able to handle it in time. |
Beta Was this translation helpful? Give feedback.
-
like this
func (this *cluster) HandleMessage(from gen.PID, message any) error {
switch val := message.(type) {
case async_node_discover:
node_name := gen.Atom(fmt.Sprintf("%s@%s", val.id, val.host))
if val.id == dust.Id() {
return nil
}
if err := dust.ConnectNode(node_name); err != nil {
this.Log().Error("cluster discover new node %s but connect failed: %s", node_name, err)
return nil
}
dict.HashPut(this.dict, dist_key, val.id, node_name, dict.Infinity)
fmt.Println(this.CallProcessID(gen.ProcessID{Name: "#hub", Node: node_name}, "test call", 5))
default:
this.Log().Error("cluster unhandled async message from [%s]%s. message: %T --> %#v", from.Node, from, val, val)
}
return nil
}
…________________________________
发件人: Taras Halturin ***@***.***>
发送时间: 2024年3月5日 17:58
收件人: ergo-services/ergo ***@***.***>
抄送: Kirin ***@***.***>; Author ***@***.***>
主题: Re: [ergo-services/ergo] About V300 (Discussion #174)
here is an example you might find useful https://github.com/ergo-services/examples/tree/v300
―
Reply to this email directly, view it on GitHub<#174 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AI652EYULLE3355VX343EU3YWWJK7AVCNFSM6AAAAABDN2COS2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DMNZXHE4TK>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
According to the logs of another node, it appears that the recipient receives the call message immediately and responds, but the caller does not receive the response effectively.
…________________________________
发件人: Taras Halturin ***@***.***>
发送时间: 2024年3月5日 18:01
收件人: ergo-services/ergo ***@***.***>
抄送: Kirin ***@***.***>; Author ***@***.***>
主题: Re: [ergo-services/ergo] About V300 (Discussion #174)
However, timeout can also occur when using it internally.
default timeout for Call requests is 5 seconds. Make sure your process (that handles this request) is able to handle it in time.
―
Reply to this email directly, view it on GitHub<#174 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AI652EZ3WR7Z3ALDUOXDWCTYWWJXFAVCNFSM6AAAAABDN2COS2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DMNZYGAZTO>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
[cid:1a2b9d7b-ca1a-4a06-a715-64501027708f]
this is my remote node HandleCall logic
…________________________________
发件人: Taras Halturin ***@***.***>
发送时间: 2024年3月5日 18:03
收件人: ergo-services/ergo ***@***.***>
抄送: Kirin ***@***.***>; Author ***@***.***>
主题: Re: [ergo-services/ergo] About V300 (Discussion #174)
please, share your HandleCall on the remote process.
―
Reply to this email directly, view it on GitHub<#174 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AI652EZXJ2JJK66D2WWAMFDYWWJ75AVCNFSM6AAAAABDN2COS2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DMNZYGA3DM>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
func factor() gen.ProcessBehavior { return &adaptor{} }
type adaptor struct {
act.Actor
}
func (this *adaptor) HandleMessage(from gen.PID, message any) error {
switch val := message.(type) {
default:
this.Log().Error("adaptor got unhandled object from [%s]%s. object: %T --> %#v", from.Node, from, val, val)
return nil
}
}
func (this *adaptor) HandleCall(from gen.PID, ref gen.Ref, request any) (any, error) {
this.Log().Warning("Actor.HandleCall: unhandled request from %s", from)
return "test reply", nil
}
this is my remote node HandleCall logic
…________________________________
发件人: Cui WenBin ***@***.***>
发送时间: 2024年3月5日 18:08
收件人: ergo-services/ergo ***@***.***>
主题: 回复: [ergo-services/ergo] About V300 (Discussion #174)
[cid:1a2b9d7b-ca1a-4a06-a715-64501027708f]
this is my remote node HandleCall logic
________________________________
发件人: Taras Halturin ***@***.***>
发送时间: 2024年3月5日 18:03
收件人: ergo-services/ergo ***@***.***>
抄送: Kirin ***@***.***>; Author ***@***.***>
主题: Re: [ergo-services/ergo] About V300 (Discussion #174)
please, share your HandleCall on the remote process.
―
Reply to this email directly, view it on GitHub<#174 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AI652EZXJ2JJK66D2WWAMFDYWWJ75AVCNFSM6AAAAABDN2COS2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DMNZYGA3DM>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply and answer. I need to check to see if there is something wrong with the way I am using it. |
Beta Was this translation helpful? Give feedback.
-
demo.go: package main
import (
"time"
"ergo.services/ergo"
"ergo.services/ergo/act"
"ergo.services/ergo/gen"
"ergo.services/ergo/net/edf"
"ergo.services/logger/colored"
)
type doCallLocal struct{}
type doCallRemote struct{}
type MyMessage struct {
MyBool bool
MyString string
}
func main() {
var options gen.NodeOptions
// disable default logger to get rid of multiple logging to the os.Stdout
options.Log.DefaultLogger.Disable = true
// add logger "colored".
loggercolored, err := colored.CreateLogger(colored.Options{})
if err != nil {
panic(err)
}
options.Log.Loggers = append(options.Log.Loggers, gen.Logger{Name: "cl", Logger: loggercolored})
options.Log.Level = gen.LogLevelInfo
// options.Log.Level = gen.LogLevelTrace
// set network cookie
options.Network.Cookie = "123"
// to be able to use self-signed cert
options.Network.InsecureSkipVerify = true
// starting node1
node1, err := ergo.StartNode("node1@localhost", options)
if err != nil {
panic(err)
}
// register network messages
if err := edf.RegisterTypeOf(MyMessage{}); err != nil {
panic(err)
}
// use the same options, but remove loggers we added for node1 to use the default one in node2
options.Log.Loggers = nil
options.Log.DefaultLogger.Disable = false
node2, err := ergo.StartNode("node2@localhost", options)
if err != nil {
panic(err)
}
defer node2.StopForce()
node2.SpawnRegister("b", factoryB, gen.ProcessOptions{})
node1.SpawnRegister("b", factoryB, gen.ProcessOptions{})
node1.SpawnRegister("a", factoryA, gen.ProcessOptions{})
node1.Send(gen.Atom("a"), doCallLocal{})
node1.Wait()
}
//
// Actor A
//
func factoryA() gen.ProcessBehavior {
return &actorA{}
}
type actorA struct {
act.Actor
}
func (a *actorA) Init(args ...any) error {
a.Log().Info("started A process on %s: %s", a.Name(), a.Node().Name())
return nil
}
func (a *actorA) HandleMessage(from gen.PID, message any) error {
switch message.(type) {
case doCallLocal:
local := gen.Atom("b")
if result, err := a.Call(local, MyMessage{MyString: "abc"}); err == nil {
a.Log().Info("received result: %#v", result)
} else {
a.Log().Error("call local process failed: %s", err)
}
a.SendAfter(a.PID(), doCallRemote{}, time.Second)
return nil
case doCallRemote:
remote := gen.ProcessID{Name: "b", Node: "node2@localhost"}
if result, err := a.Call(remote, MyMessage{MyBool: true, MyString: "def"}); err == nil {
a.Log().Info("received result: %#v", result)
} else {
a.Log().Error("call remote process failed: %s", err)
}
a.SendAfter(a.PID(), doCallLocal{}, time.Second)
return nil
}
a.Log().Error("unknown message %#v", message)
return nil
}
//
// Actor B
//
func factoryB() gen.ProcessBehavior {
return &actorB{}
}
type actorB struct {
act.Actor
}
func (b *actorB) Init(args ...any) error {
b.Log().Info("started B process on %s: %s", b.Name(), b.Node().Name())
return nil
}
func (b *actorB) HandleCall(from gen.PID, ref gen.Ref, request any) (any, error) {
switch r := request.(type) {
case MyMessage:
b.Log().Info("received MyMessage request from %s: %#v", from, r)
return true, nil
}
b.Log().Info("received unknown request: %#v", request)
return false, nil
} go.mod
|
Beta Was this translation helpful? Give feedback.
-
also added this example here https://github.com/ergo-services/examples/tree/v300 |
Beta Was this translation helpful? Give feedback.
-
This is my calling process. As you can see, when HandleCall actively throws an error, it will be returned to the caller. However, at this point, the caller’s Call is still blocked until it times out. In other words, there is no issue with network connectivity or the logic of the Call; it’s just unclear why the correct response is not being received. |
Beta Was this translation helpful? Give feedback.
-
This is the code that does not actively throw an error. As you can see in the console, it did not return “try reply remote call” as expected, but instead threw a timeout. |
Beta Was this translation helpful? Give feedback.
-
Just fixed an issue that might be related to your problem. Pull the latest changes in v300. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hi, I saw the submission of the new V300 branch. Is there any relevant documentation to check?
Beta Was this translation helpful? Give feedback.
All reactions