0

我使用 go-micro 编写了一个简单的 rpc 服务,我发现每个调用将花费 1 秒以上,在 micro web 中也是如此。于是我运行官方的examples包,选择helloworld进行测试,又出现了这种情况。

type Greeter struct{}

func (g *Greeter) Hello(ctx context.Context, req *proto.HelloRequest, rsp *proto.HelloResponse) error {
    rsp.Greeting = "Hello " + req.Name
    return nil
}

func main() {
    service := micro.NewService(
        micro.Name("greeter"),
    )

service.Init()

proto.RegisterGreeterHandler(service.Server(), new(Greeter))

if err := service.Run(); err != nil {
    log.Fatal(err)
    }
}

以下是执行几个示例请求的结果:

started
Id:"1" UserName:"max"
1.099975019s
started
Id:"1" UserName:"max"
1.104435591s
started
Id:"1" UserName:"max"
1.103551837s
started
Id:"1" UserName:"max"
1.100724299s
started
Id:"1" UserName:"max"
1.098161724s

谁能告诉我为什么每个请求都需要这么长时间?

4

0 回答 0