smallnest / rpcx

Best microservices framework in Go, like alibaba Dubbo, but with more features, Scale easily. Try it. Test it. If you feel it's better, use it! 𝐉𝐚𝐯𝐚有𝐝𝐮𝐛𝐛𝐨, 𝐆𝐨𝐥𝐚𝐧𝐠有𝐫𝐩𝐜𝐱! build for cloud!
https://rpcx.io
Other
8.11k stars 1.17k forks source link

RPC 调用之后不及时返回结果。 #791

Closed yaoding16 closed 1 year ago

yaoding16 commented 1 year ago

rpc调用之后,需要等待几秒钟 reply 才会有值 希望调用之后,能直接有结果了。

打印输出:

2023/03/15 11:03:06 After 5 seconds, client => Hi, client
2023/03/15 11:03:06 client => 
2023/03/15 11:03:11 After 5 seconds, client => Hi, client
2023/03/15 11:03:11 client => 

重现代码:

type Test struct{}

type GreetingArgs struct {
    Name string
}

func (t *Test) Greeting(ctx context.Context, args *GreetingArgs, reply *string) error {
    *reply = "Hi, " + args.Name
    return nil
}

func main() {
    go func() {
        s := server.NewServer()
        s.RegisterName("Test", new(Test), "")
        s.Serve("tcp", "127.0.0.1:8701")
    }()

    d, err := client.NewPeer2PeerDiscovery("tcp@127.0.0.1:8701", "")
    if err != nil {
        log.Panicln(err)
        return
    }
    xclient := client.NewXClient("Test", client.Failtry, client.RandomSelect, d, client.DefaultOption)
    defer xclient.Close()

    args := &GreetingArgs{
        Name: "client",
    }

    for {
        var reply string
        err := xclient.Call(context.Background(), "Greeting", args, &reply)
        if err != nil {
            log.Printf("failed to call: %v\n", err)
            time.Sleep(5 * time.Second)
            continue
        }
        log.Printf("%s => %s", args.Name, reply)

        time.Sleep(5 * time.Second)
        log.Printf("After 5 seconds, %s => %s", args.Name, reply)
    }
}
smallnest commented 1 year ago

实际 Call调用返回后, reply就应该有值,不必等5秒. 如https://github.com/rpcxio/rpcx-examples/tree/master/101basic 中的例子,每秒调用一次,每次立马返回。

image

你的 rpcx版本是多少?

yaoding16 commented 1 year ago

实际 Call调用返回后, reply就应该有值,不必等5秒. 如https://github.com/rpcxio/rpcx-examples/tree/master/101basic 中的例子,每秒调用一次,每次立马返回。 image

你的 rpcx版本是多少?

rpcx: v1.8.3 go: 1.19.2

smallnest commented 1 year ago

你升级一下rpcx版本。 1.8.3有些问题

yaoding16 commented 1 year ago

升级到1.8.4就可以了,谢谢