Ai
14 Star 50 Fork 12

Hprose/hprose-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
http_hello_client.go 871 Bytes
一键复制 编辑 原始数据 按行查看 历史
Hprose 提交于 2016-11-01 19:30 +08:00 . Moved fasthttp client & server to rpc/fasthttp
package main
import (
"fmt"
"sync/atomic"
"time"
"github.com/hprose/hprose-golang/rpc"
)
// Stub is ...
type Stub struct {
Hello func(string) (string, error)
AsyncHello func(func(string, error), string) `name:"hello"`
}
func main() {
client := rpc.NewHTTPClient("http://127.0.0.1:8080/")
client.MaxIdleConnsPerHost = 128
client.SetMaxConcurrentRequests(128)
var stub *Stub
client.UseService(&stub)
stub.AsyncHello(func(result string, err error) {
fmt.Println(result, err)
}, "async world")
fmt.Println(stub.Hello("world"))
start := time.Now()
var n int32 = 500000
done := make(chan bool)
for i := 0; i < 500000; i++ {
stub.AsyncHello(func(result string, err error) {
if atomic.AddInt32(&n, -1) == 0 {
done <- true
}
}, "async world")
}
<-done
stop := time.Now()
fmt.Println((stop.UnixNano() - start.UnixNano()) / 1000000)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/andot/hprose-go.git
git@gitee.com:andot/hprose-go.git
andot
hprose-go
hprose-go
v2.0.4

搜索帮助