Closed maskwang closed 6 years ago
使用 SendPushBytes(), // str, err := c.SendPushBytes(bytes)
代码如下:
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strings"
"github.com/ylywyn/jpush-api-go-client"
)
var url = "http://www.baidu.com/"
func main() {
for i := 0; i < 200; i++ {
go func() {
jpushclient.SendPostBytes(url, []byte("123"), "")
//jpushclient.SendPostBytes2(url, []byte("123"), "")
log.Println("done")
}()
//time.Sleep(1 * time.Second)
log.Println("open files:", openFiles())
}
select {}
}
func openFiles() int {
out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -p %v", os.Getpid())).Output()
if err != nil {
log.Fatal(err)
}
lines := strings.Split(string(out), "\n")
return len(lines) - 1
}
结果一样的:
SendPostBytes
方法测试结果:
SendPostBytes2
方法测试结果:
当大规模调用推送,会导致tcp全部都是链接状态,而不能复用以及释放, 进而导致文件句柄占满,导致服务不可用