-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于高分位时延的疑问 #2
Comments
nbio支持EPOLLET,也支持 g.OnRead 设置用户自己处理读事件,这样就相当于只传递事件给应用层、应用层可以自己在事件到来时去协程池取一个协程进行实际的读写。 我之前在nbhttp里试过这种,但是压测数据并没有提升。因为除了epoll loop里的事件,还涉及读buffer,现在的是每个epoll loop对应一个buffer,如果是 epoll loop 只传递事件、另外的协成池去处理实际的读,协程池里的每个协程仍然需要对应一个固定的buffer。对于nbhttp,使用的协成池里的协程是: 但是其他自定制协议,是可以这样做的,毕竟协程池的那点数量个buffer相比于海量并发时每个连接一个协程,已经节省了大量的内存了 |
EPOLLET每次有新数据到达都会触发,只要当前未读完之前数据,重复触发读可能就会造成浪费,所以可以考虑给Conn如果是 EPOLLET+g.OnRead,g.OnRead还可以为每个Conn.SetSession维护个当前状态,如果是已经可读,就不再触发syacall.Read,只有当前是未读状态并且有读事件到来,才去触发syscall.Read,这样能尽量节约syscall,刚好前两天在这里也提到过这个: |
另外就是标准库的EPOLL loop + runtime调度的亲和性更友好更节约,比用chan或者每次go一个协程应该是要好一点。 |
还有就是,总吞吐是差不多的,所以P99/999主要还是epoll loop里排在后面的fd的等待久一点造成的,avg应该是差不多的,对于整体服务,还好 |
TP99/999是取末尾的请求的耗时最大值,可能把TP50-90范围都统计出来更好些,比如总共1000个请求,取第990和999个对比可能某个框架表现更好,但前面的900个可能是其他框架表现更好。1000连接的数据对比就是这个样子,标准库的TP99/999仍然最佳但整体吞吐已经不如其他几个高,也就是说前面的大部分请求标准库不如其他几个框架快,比如前面大部分请求其他框架2ms而标准库4ms。 |
1000连接时标准库不如其他几个异步的吞吐,应该是因为连接数多了调度消耗更多些了,而异步框架只需要poller num个协程(netpoll有些不同),调度切换协程更少。 |
@lesismal 感谢大佬,我最近准备改成ringbuff的方式读写,看TP99会不会改进,netpoll用的ringbuff,它的TP99在echo压测模型下挺不错 |
ringbuffer我在一些地方有解释过,可以思考下: 所以netpoll我估计应该不是ringbuffer的功劳,而是因为它类似标准库,仍然是为每个fd可读时专门用一个协程去处理,但是因为不是runtime调度,所以它的T99响应也并不如标准库,并且吞吐远低于其他所有参赛者。并且如我前面所讲,T99数据好、整体吞吐却不好说明前面更大范围的请求数响应不如其他框架,比如可能95%的请求比别的框架慢,只是尾部部分比别人尾部请求略快,实际的统计需要加更多日志比如TP50/60/70/80/90/95才能得到。 当然,你可以折腾一波试试看ringbuffer是否能真的带来提升,我只是理论上推测、并没有去实际压测 |
赞同标准库是以空间换时间 我感觉在http场景,异步库真的还不要用。 这是nbio http, 50w连接时的qps
这是go http50w连接时的qps
|
对,我之前在几个地方也说过,普通连接数普通接口,异步库没有优势。 但还是有些领域适合,对于50w连接数这种,通常异步库可能会更好。http_1m的示例只是简单请求、小buffer echo,而实际业务场景不会这么简单。随着每个接口的参数、数据长度的不同,在这种大连接数下对runtime的压力是不一样的,你可以把测试接口里面加一点cpu消耗计算进去,再把buffer调大一些看看效果,我这里用1024的buffer、加上10w loop的简单计算sum,8c8g(c/s都在一个虚拟机里)直接OOM了 再说实际的场景,还是有一些的。比如大厂基础设施,中间件、代理之类的,每个节点承载的量都比较大。用标准库方案,硬件成本也是很高的。中小公司省成本也是同样的道理,虽然堆机器也能搞定,但纯依赖机器,成本、环保都不划算的 |
1024 buffer、加了点cpu消耗: 标准库: func onEcho(w http.ResponseWriter, r *http.Request) {
sum := 0
for i := 0; i < 100000; i++ {
sum += i
}
data, _ := io.ReadAll(r.Body)
if len(data) > 0 {
w.Write(data)
} else {
w.Write([]byte(time.Now().Format("20060102 15:04:05")))
}
atomic.AddUint64(&qps, 1)
} client package main
import (
"bytes"
"flag"
"fmt"
"net"
"os"
"runtime"
"sync/atomic"
"time"
)
var (
connected uint64 = 0
success uint64 = 0
failed uint64 = 0
totalSuccess uint64 = 0
totalFailed uint64 = 0
numClient = flag.Int("c", 500000, "client num")
numGoroutine = flag.Int("g", 1000, "goroutine num")
body = make([]byte, 1024)
)
func main() {
flag.Parse()
for i := 0; i < 1024; i++ {
body[i] = 'a' + byte(i%26)
}
connNum := *numClient
goroutineNum := *numGoroutine
for i := 0; i < goroutineNum; i++ {
go loop(addrs[i%len(addrs)], connNum/goroutineNum)
}
ticker := time.NewTicker(time.Second)
for i := 1; true; i++ {
<-ticker.C
nSuccess := atomic.SwapUint64(&success, 0)
nFailed := atomic.SwapUint64(&failed, 0)
totalSuccess += nSuccess
totalFailed += nFailed
fmt.Printf("running for %v seconds, online: %v, NumGoroutine: %v, success: %v, totalSuccess: %v, failed: %v, totalFailed: %v\n", i, connected, runtime.NumGoroutine(), nSuccess, totalSuccess, failed, totalFailed)
}
}
func loop(addr string, connNum int) {
conns := make([]net.Conn, connNum)
for i := 0; i < connNum; i++ {
for {
conn, err := net.Dial("tcp", addr)
if err == nil {
conns[i] = conn
atomic.AddUint64(&connected, 1)
break
}
time.Sleep(time.Second / 10)
}
}
reqData := []byte(fmt.Sprintf("POST /echo HTTP/1.1\r\nHost: %v\r\nContent-Length: 1024\r\nAccept-Encoding: gzip\r\n\r\n", addr))
reqData = append(reqData, body...)
for {
for i := 0; i < connNum; i++ {
post(conns[i], reqData)
}
}
}
func post(conn net.Conn, reqData []byte) {
resData := make([]byte, 1024*2)
n, err := conn.Write(reqData)
if err != nil || n < len(reqData) {
atomic.AddUint64(&failed, 1)
fmt.Println("write failed:", n, err)
return
}
// time.Sleep(time.Second / 10)
// n, err = io.ReadFull(conn, resData)
n, err = conn.Read(resData)
if err != nil || !bytes.Equal(resData[n-1024:n], body) {
atomic.AddUint64(&failed, 1)
fmt.Println("read failed:", n, err, string(resData[n-1024:n]))
os.Exit(0)
}
atomic.AddUint64(&success, 1)
}
var addrs = []string{
"localhost:28001",
"localhost:28002",
"localhost:28003",
"localhost:28004",
"localhost:28005",
"localhost:28006",
"localhost:28007",
"localhost:28008",
"localhost:28009",
"localhost:28010",
"localhost:28011",
"localhost:28012",
"localhost:28013",
"localhost:28014",
"localhost:28015",
"localhost:28016",
"localhost:28017",
"localhost:28018",
"localhost:28019",
"localhost:28020",
"localhost:28021",
"localhost:28022",
"localhost:28023",
"localhost:28024",
"localhost:28025",
"localhost:28026",
"localhost:28027",
"localhost:28028",
"localhost:28029",
"localhost:28030",
"localhost:28031",
"localhost:28032",
"localhost:28033",
"localhost:28034",
"localhost:28035",
"localhost:28036",
"localhost:28037",
"localhost:28038",
"localhost:28039",
"localhost:28040",
"localhost:28041",
"localhost:28042",
"localhost:28043",
"localhost:28044",
"localhost:28045",
"localhost:28046",
"localhost:28047",
"localhost:28048",
"localhost:28049",
"localhost:28050",
} output: running for 1 seconds, online: 18783, NumGoroutine: 1001, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 2 seconds, online: 40541, NumGoroutine: 1003, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 3 seconds, online: 63772, NumGoroutine: 1001, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 4 seconds, online: 86171, NumGoroutine: 1001, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 5 seconds, online: 108934, NumGoroutine: 1001, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 6 seconds, online: 131222, NumGoroutine: 1002, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 7 seconds, online: 146469, NumGoroutine: 1001, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 8 seconds, online: 161895, NumGoroutine: 1001, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 9 seconds, online: 178536, NumGoroutine: 1003, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 10 seconds, online: 193894, NumGoroutine: 1003, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 11 seconds, online: 206362, NumGoroutine: 1001, success: 2, totalSuccess: 2, failed: 0, totalFailed: 0
running for 12 seconds, online: 223479, NumGoroutine: 1001, success: 3, totalSuccess: 5, failed: 0, totalFailed: 0
running for 13 seconds, online: 235686, NumGoroutine: 1003, success: 1, totalSuccess: 6, failed: 0, totalFailed: 0
running for 14 seconds, online: 252053, NumGoroutine: 1001, success: 9, totalSuccess: 15, failed: 0, totalFailed: 0
running for 15 seconds, online: 264258, NumGoroutine: 1001, success: 0, totalSuccess: 15, failed: 0, totalFailed: 0
running for 16 seconds, online: 277843, NumGoroutine: 1001, success: 12, totalSuccess: 27, failed: 0, totalFailed: 0
running for 17 seconds, online: 291761, NumGoroutine: 1003, success: 3, totalSuccess: 30, failed: 0, totalFailed: 0
running for 18 seconds, online: 308240, NumGoroutine: 1001, success: 6, totalSuccess: 36, failed: 0, totalFailed: 0
running for 19 seconds, online: 321924, NumGoroutine: 1001, success: 8, totalSuccess: 44, failed: 0, totalFailed: 0
running for 20 seconds, online: 335931, NumGoroutine: 1003, success: 4, totalSuccess: 48, failed: 0, totalFailed: 0
running for 21 seconds, online: 348310, NumGoroutine: 1003, success: 12, totalSuccess: 60, failed: 0, totalFailed: 0
running for 22 seconds, online: 363288, NumGoroutine: 1001, success: 28, totalSuccess: 88, failed: 0, totalFailed: 0
running for 23 seconds, online: 380325, NumGoroutine: 1001, success: 19, totalSuccess: 107, failed: 0, totalFailed: 0
running for 24 seconds, online: 388488, NumGoroutine: 1001, success: 35, totalSuccess: 142, failed: 0, totalFailed: 0
running for 25 seconds, online: 398988, NumGoroutine: 1001, success: 46, totalSuccess: 188, failed: 0, totalFailed: 0
running for 26 seconds, online: 417832, NumGoroutine: 1001, success: 13, totalSuccess: 201, failed: 0, totalFailed: 0
running for 27 seconds, online: 431164, NumGoroutine: 1003, success: 45, totalSuccess: 246, failed: 0, totalFailed: 0
running for 28 seconds, online: 442897, NumGoroutine: 1001, success: 94, totalSuccess: 340, failed: 0, totalFailed: 0
running for 29 seconds, online: 452870, NumGoroutine: 1003, success: 60, totalSuccess: 400, failed: 0, totalFailed: 0
running for 30 seconds, online: 464070, NumGoroutine: 1001, success: 29, totalSuccess: 429, failed: 0, totalFailed: 0
running for 31 seconds, online: 476819, NumGoroutine: 1001, success: 81, totalSuccess: 510, failed: 0, totalFailed: 0
running for 32 seconds, online: 486747, NumGoroutine: 1001, success: 33, totalSuccess: 543, failed: 0, totalFailed: 0
running for 33 seconds, online: 491506, NumGoroutine: 1001, success: 787, totalSuccess: 1330, failed: 0, totalFailed: 0
running for 34 seconds, online: 493710, NumGoroutine: 1001, success: 17045, totalSuccess: 18375, failed: 0, totalFailed: 0
running for 35 seconds, online: 495434, NumGoroutine: 1001, success: 26439, totalSuccess: 44814, failed: 0, totalFailed: 0
running for 36 seconds, online: 496015, NumGoroutine: 1001, success: 20157, totalSuccess: 64971, failed: 0, totalFailed: 0
running for 37 seconds, online: 496212, NumGoroutine: 1001, success: 30615, totalSuccess: 95586, failed: 0, totalFailed: 0
running for 38 seconds, online: 498542, NumGoroutine: 1001, success: 58815, totalSuccess: 154401, failed: 0, totalFailed: 0
running for 39 seconds, online: 498568, NumGoroutine: 1001, success: 35348, totalSuccess: 189749, failed: 0, totalFailed: 0
running for 40 seconds, online: 498568, NumGoroutine: 1001, success: 34650, totalSuccess: 224399, failed: 0, totalFailed: 0
running for 41 seconds, online: 498902, NumGoroutine: 1001, success: 34196, totalSuccess: 258595, failed: 0, totalFailed: 0
running for 42 seconds, online: 498939, NumGoroutine: 1001, success: 35723, totalSuccess: 294318, failed: 0, totalFailed: 0
running for 43 seconds, online: 498939, NumGoroutine: 1001, success: 32988, totalSuccess: 327306, failed: 0, totalFailed: 0
running for 44 seconds, online: 498939, NumGoroutine: 1001, success: 36581, totalSuccess: 363887, failed: 0, totalFailed: 0
running for 45 seconds, online: 498939, NumGoroutine: 1001, success: 62607, totalSuccess: 426494, failed: 0, totalFailed: 0
running for 46 seconds, online: 498939, NumGoroutine: 1001, success: 92239, totalSuccess: 518733, failed: 0, totalFailed: 0
running for 47 seconds, online: 498939, NumGoroutine: 1001, success: 91302, totalSuccess: 610035, failed: 0, totalFailed: 0
running for 48 seconds, online: 498939, NumGoroutine: 1001, success: 89452, totalSuccess: 699487, failed: 0, totalFailed: 0
running for 49 seconds, online: 498939, NumGoroutine: 1001, success: 29663, totalSuccess: 729150, failed: 0, totalFailed: 0
running for 50 seconds, online: 498939, NumGoroutine: 1001, success: 37721, totalSuccess: 766871, failed: 0, totalFailed: 0
running for 51 seconds, online: 498939, NumGoroutine: 1001, success: 37214, totalSuccess: 804085, failed: 0, totalFailed: 0
running for 52 seconds, online: 498939, NumGoroutine: 1001, success: 30514, totalSuccess: 834599, failed: 0, totalFailed: 0
running for 53 seconds, online: 498939, NumGoroutine: 1001, success: 41117, totalSuccess: 875716, failed: 0, totalFailed: 0
running for 54 seconds, online: 498939, NumGoroutine: 1001, success: 44506, totalSuccess: 920222, failed: 0, totalFailed: 0
running for 55 seconds, online: 498939, NumGoroutine: 1001, success: 33536, totalSuccess: 953758, failed: 0, totalFailed: 0
running for 56 seconds, online: 498939, NumGoroutine: 1001, success: 28511, totalSuccess: 982269, failed: 0, totalFailed: 0
running for 57 seconds, online: 498939, NumGoroutine: 1001, success: 17312, totalSuccess: 999581, failed: 0, totalFailed: 0
running for 58 seconds, online: 498939, NumGoroutine: 1001, success: 13247, totalSuccess: 1012828, failed: 0, totalFailed: 0
running for 59 seconds, online: 498939, NumGoroutine: 1001, success: 11465, totalSuccess: 1024293, failed: 0, totalFailed: 0
running for 60 seconds, online: 498939, NumGoroutine: 1001, success: 8431, totalSuccess: 1032724, failed: 0, totalFailed: 0
running for 61 seconds, online: 498939, NumGoroutine: 1001, success: 9221, totalSuccess: 1041945, failed: 0, totalFailed: 0
running for 62 seconds, online: 498939, NumGoroutine: 1001, success: 8358, totalSuccess: 1050303, failed: 0, totalFailed: 0
running for 63 seconds, online: 498939, NumGoroutine: 1001, success: 8260, totalSuccess: 1058563, failed: 0, totalFailed: 0
running for 64 seconds, online: 498939, NumGoroutine: 1001, success: 9020, totalSuccess: 1067583, failed: 0, totalFailed: 0
running for 65 seconds, online: 498939, NumGoroutine: 1001, success: 7821, totalSuccess: 1075404, failed: 0, totalFailed: 0
running for 66 seconds, online: 498939, NumGoroutine: 1001, success: 8186, totalSuccess: 1083590, failed: 0, totalFailed: 0
running for 67 seconds, online: 498939, NumGoroutine: 1001, success: 7975, totalSuccess: 1091565, failed: 0, totalFailed: 0
running for 68 seconds, online: 498939, NumGoroutine: 1001, success: 7771, totalSuccess: 1099336, failed: 0, totalFailed: 0
running for 69 seconds, online: 498939, NumGoroutine: 1001, success: 8296, totalSuccess: 1107632, failed: 0, totalFailed: 0
running for 70 seconds, online: 498939, NumGoroutine: 1001, success: 7895, totalSuccess: 1115527, failed: 0, totalFailed: 0
running for 71 seconds, online: 499188, NumGoroutine: 1001, success: 7200, totalSuccess: 1122727, failed: 0, totalFailed: 0
running for 72 seconds, online: 500000, NumGoroutine: 1001, success: 7980, totalSuccess: 1130707, failed: 0, totalFailed: 0
running for 73 seconds, online: 500000, NumGoroutine: 1001, success: 8463, totalSuccess: 1139170, failed: 0, totalFailed: 0
running for 74 seconds, online: 500000, NumGoroutine: 1001, success: 10266, totalSuccess: 1149436, failed: 0, totalFailed: 0
running for 75 seconds, online: 500000, NumGoroutine: 1001, success: 6879, totalSuccess: 1156315, failed: 0, totalFailed: 0
running for 76 seconds, online: 500000, NumGoroutine: 1001, success: 8582, totalSuccess: 1164897, failed: 0, totalFailed: 0
running for 77 seconds, online: 500000, NumGoroutine: 1001, success: 6784, totalSuccess: 1171681, failed: 0, totalFailed: 0
running for 78 seconds, online: 500000, NumGoroutine: 1001, success: 7699, totalSuccess: 1179380, failed: 0, totalFailed: 0
running for 79 seconds, online: 500000, NumGoroutine: 1001, success: 7563, totalSuccess: 1186943, failed: 0, totalFailed: 0
running for 80 seconds, online: 500000, NumGoroutine: 1001, success: 7882, totalSuccess: 1194825, failed: 0, totalFailed: 0
running for 81 seconds, online: 500000, NumGoroutine: 1001, success: 7599, totalSuccess: 1202424, failed: 0, totalFailed: 0
running for 82 seconds, online: 500000, NumGoroutine: 1001, success: 6981, totalSuccess: 1209405, failed: 0, totalFailed: 0
running for 83 seconds, online: 500000, NumGoroutine: 1001, success: 7059, totalSuccess: 1216464, failed: 0, totalFailed: 0
running for 84 seconds, online: 500000, NumGoroutine: 1001, success: 4126, totalSuccess: 1220590, failed: 0, totalFailed: 0
running for 85 seconds, online: 500000, NumGoroutine: 1001, success: 5965, totalSuccess: 1226555, failed: 0, totalFailed: 0
running for 86 seconds, online: 500000, NumGoroutine: 1001, success: 7603, totalSuccess: 1234158, failed: 0, totalFailed: 0
running for 87 seconds, online: 500000, NumGoroutine: 1001, success: 6816, totalSuccess: 1240974, failed: 0, totalFailed: 0
running for 88 seconds, online: 500000, NumGoroutine: 1001, success: 7676, totalSuccess: 1248650, failed: 0, totalFailed: 0
running for 89 seconds, online: 500000, NumGoroutine: 1001, success: 7341, totalSuccess: 1255991, failed: 0, totalFailed: 0
running for 90 seconds, online: 500000, NumGoroutine: 1001, success: 7427, totalSuccess: 1263418, failed: 0, totalFailed: 0
running for 91 seconds, online: 500000, NumGoroutine: 1001, success: 7192, totalSuccess: 1270610, failed: 0, totalFailed: 0
running for 92 seconds, online: 500000, NumGoroutine: 1001, success: 6384, totalSuccess: 1276994, failed: 0, totalFailed: 0
running for 93 seconds, online: 500000, NumGoroutine: 1001, success: 6199, totalSuccess: 1283193, failed: 0, totalFailed: 0
running for 94 seconds, online: 500000, NumGoroutine: 1001, success: 6348, totalSuccess: 1289541, failed: 0, totalFailed: 0
running for 95 seconds, online: 500000, NumGoroutine: 1001, success: 6712, totalSuccess: 1296253, failed: 0, totalFailed: 0 消耗: top -d 1 |
可以看到的是,增加buffer size和一点cpu消耗模拟实际业务后,内存占用过高,并且qps也下降了,因为runtime的gc压力大了很多,应该是STW比较多导致cpu都发挥不起来了 http_1m只是为了演示内存优势,没有去模拟实际业务,因为实际业务确实难模拟,用户还是应该自行选择。 |
再看下nbio的1024+cpu消耗: func onEcho(w http.ResponseWriter, r *http.Request) {
sum := 0
for i := 0; i < 100000; i++ {
sum += i
}
data, _ := io.ReadAll(r.Body)
if len(data) > 0 {
w.Write(data)
} else {
w.Write([]byte(time.Now().Format("20060102 15:04:05")))
}
atomic.AddUint64(&qps, 1)
} client跟上面测标准库的相同 output: running for 1 seconds, online: 142119, NumGoroutine: 1001, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 2 seconds, online: 328438, NumGoroutine: 1002, success: 0, totalSuccess: 0, failed: 0, totalFailed: 0
running for 3 seconds, online: 499858, NumGoroutine: 1002, success: 8585, totalSuccess: 8585, failed: 0, totalFailed: 0
running for 4 seconds, online: 500000, NumGoroutine: 1001, success: 72042, totalSuccess: 80627, failed: 0, totalFailed: 0
running for 5 seconds, online: 500000, NumGoroutine: 1001, success: 95376, totalSuccess: 176003, failed: 0, totalFailed: 0
running for 6 seconds, online: 500000, NumGoroutine: 1001, success: 96099, totalSuccess: 272102, failed: 0, totalFailed: 0
running for 7 seconds, online: 500000, NumGoroutine: 1001, success: 82225, totalSuccess: 354327, failed: 0, totalFailed: 0
running for 8 seconds, online: 500000, NumGoroutine: 1001, success: 103987, totalSuccess: 458314, failed: 0, totalFailed: 0
running for 9 seconds, online: 500000, NumGoroutine: 1001, success: 100681, totalSuccess: 558995, failed: 0, totalFailed: 0
running for 10 seconds, online: 500000, NumGoroutine: 1001, success: 81808, totalSuccess: 640803, failed: 0, totalFailed: 0
running for 11 seconds, online: 500000, NumGoroutine: 1001, success: 98235, totalSuccess: 739038, failed: 0, totalFailed: 0
running for 12 seconds, online: 500000, NumGoroutine: 1001, success: 103170, totalSuccess: 842208, failed: 0, totalFailed: 0
running for 13 seconds, online: 500000, NumGoroutine: 1001, success: 85211, totalSuccess: 927419, failed: 0, totalFailed: 0
running for 14 seconds, online: 500000, NumGoroutine: 1001, success: 100749, totalSuccess: 1028168, failed: 0, totalFailed: 0
running for 15 seconds, online: 500000, NumGoroutine: 1001, success: 98372, totalSuccess: 1126540, failed: 0, totalFailed: 0
running for 16 seconds, online: 500000, NumGoroutine: 1001, success: 79420, totalSuccess: 1205960, failed: 0, totalFailed: 0
running for 17 seconds, online: 500000, NumGoroutine: 1001, success: 92194, totalSuccess: 1298154, failed: 0, totalFailed: 0
running for 18 seconds, online: 500000, NumGoroutine: 1001, success: 100267, totalSuccess: 1398421, failed: 0, totalFailed: 0
running for 19 seconds, online: 500000, NumGoroutine: 1001, success: 94731, totalSuccess: 1493152, failed: 0, totalFailed: 0
running for 20 seconds, online: 500000, NumGoroutine: 1001, success: 87267, totalSuccess: 1580419, failed: 0, totalFailed: 0
running for 21 seconds, online: 500000, NumGoroutine: 1001, success: 97277, totalSuccess: 1677696, failed: 0, totalFailed: 0
running for 22 seconds, online: 500000, NumGoroutine: 1001, success: 94567, totalSuccess: 1772263, failed: 0, totalFailed: 0
running for 23 seconds, online: 500000, NumGoroutine: 1001, success: 86103, totalSuccess: 1858366, failed: 0, totalFailed: 0
running for 24 seconds, online: 500000, NumGoroutine: 1001, success: 103035, totalSuccess: 1961401, failed: 0, totalFailed: 0
running for 25 seconds, online: 500000, NumGoroutine: 1001, success: 97126, totalSuccess: 2058527, failed: 0, totalFailed: 0
running for 26 seconds, online: 500000, NumGoroutine: 1001, success: 79992, totalSuccess: 2138519, failed: 0, totalFailed: 0
running for 27 seconds, online: 500000, NumGoroutine: 1001, success: 99274, totalSuccess: 2237793, failed: 0, totalFailed: 0
running for 28 seconds, online: 500000, NumGoroutine: 1001, success: 100299, totalSuccess: 2338092, failed: 0, totalFailed: 0
running for 29 seconds, online: 500000, NumGoroutine: 1001, success: 102970, totalSuccess: 2441062, failed: 0, totalFailed: 0
running for 30 seconds, online: 500000, NumGoroutine: 1001, success: 84929, totalSuccess: 2525991, failed: 0, totalFailed: 0
running for 31 seconds, online: 500000, NumGoroutine: 1001, success: 94345, totalSuccess: 2620336, failed: 0, totalFailed: 0
running for 32 seconds, online: 500000, NumGoroutine: 1001, success: 99340, totalSuccess: 2719676, failed: 0, totalFailed: 0
running for 33 seconds, online: 500000, NumGoroutine: 1001, success: 85706, totalSuccess: 2805382, failed: 0, totalFailed: 0
running for 34 seconds, online: 500000, NumGoroutine: 1001, success: 97082, totalSuccess: 2902464, failed: 0, totalFailed: 0
running for 35 seconds, online: 500000, NumGoroutine: 1001, success: 102339, totalSuccess: 3004803, failed: 0, totalFailed: 0
running for 36 seconds, online: 500000, NumGoroutine: 1001, success: 96240, totalSuccess: 3101043, failed: 0, totalFailed: 0
running for 37 seconds, online: 500000, NumGoroutine: 1001, success: 80855, totalSuccess: 3181898, failed: 0, totalFailed: 0
running for 38 seconds, online: 500000, NumGoroutine: 1001, success: 94926, totalSuccess: 3276824, failed: 0, totalFailed: 0
running for 39 seconds, online: 500000, NumGoroutine: 1001, success: 99174, totalSuccess: 3375998, failed: 0, totalFailed: 0
running for 40 seconds, online: 500000, NumGoroutine: 1001, success: 102677, totalSuccess: 3478675, failed: 0, totalFailed: 0
running for 41 seconds, online: 500000, NumGoroutine: 1001, success: 71755, totalSuccess: 3550430, failed: 0, totalFailed: 0
running for 42 seconds, online: 500000, NumGoroutine: 1001, success: 97453, totalSuccess: 3647883, failed: 0, totalFailed: 0
running for 43 seconds, online: 500000, NumGoroutine: 1001, success: 98880, totalSuccess: 3746763, failed: 0, totalFailed: 0
running for 44 seconds, online: 500000, NumGoroutine: 1001, success: 102045, totalSuccess: 3848808, failed: 0, totalFailed: 0
running for 45 seconds, online: 500000, NumGoroutine: 1001, success: 87112, totalSuccess: 3935920, failed: 0, totalFailed: 0
running for 46 seconds, online: 500000, NumGoroutine: 1001, success: 102314, totalSuccess: 4038234, failed: 0, totalFailed: 0
running for 47 seconds, online: 500000, NumGoroutine: 1001, success: 92366, totalSuccess: 4130600, failed: 0, totalFailed: 0
running for 48 seconds, online: 500000, NumGoroutine: 1001, success: 82082, totalSuccess: 4212682, failed: 0, totalFailed: 0
running for 49 seconds, online: 500000, NumGoroutine: 1001, success: 91192, totalSuccess: 4303874, failed: 0, totalFailed: 0
running for 50 seconds, online: 500000, NumGoroutine: 1001, success: 98275, totalSuccess: 4402149, failed: 0, totalFailed: 0
running for 51 seconds, online: 500000, NumGoroutine: 1001, success: 97724, totalSuccess: 4499873, failed: 0, totalFailed: 0
running for 52 seconds, online: 500000, NumGoroutine: 1001, success: 82122, totalSuccess: 4581995, failed: 0, totalFailed: 0
running for 53 seconds, online: 500000, NumGoroutine: 1001, success: 96324, totalSuccess: 4678319, failed: 0, totalFailed: 0
running for 54 seconds, online: 500000, NumGoroutine: 1001, success: 99298, totalSuccess: 4777617, failed: 0, totalFailed: 0
running for 55 seconds, online: 500000, NumGoroutine: 1001, success: 98663, totalSuccess: 4876280, failed: 0, totalFailed: 0
running for 56 seconds, online: 500000, NumGoroutine: 1001, success: 83489, totalSuccess: 4959769, failed: 0, totalFailed: 0
running for 57 seconds, online: 500000, NumGoroutine: 1001, success: 94015, totalSuccess: 5053784, failed: 0, totalFailed: 0
running for 58 seconds, online: 500000, NumGoroutine: 1001, success: 93981, totalSuccess: 5147765, failed: 0, totalFailed: 0
running for 59 seconds, online: 500000, NumGoroutine: 1001, success: 84348, totalSuccess: 5232113, failed: 0, totalFailed: 0
running for 60 seconds, online: 500000, NumGoroutine: 1001, success: 87356, totalSuccess: 5319469, failed: 0, totalFailed: 0
running for 61 seconds, online: 500000, NumGoroutine: 1001, success: 98284, totalSuccess: 5417753, failed: 0, totalFailed: 0
running for 62 seconds, online: 500000, NumGoroutine: 1001, success: 97754, totalSuccess: 5515507, failed: 0, totalFailed: 0
running for 63 seconds, online: 500000, NumGoroutine: 1001, success: 82670, totalSuccess: 5598177, failed: 0, totalFailed: 0
running for 64 seconds, online: 500000, NumGoroutine: 1001, success: 90031, totalSuccess: 5688208, failed: 0, totalFailed: 0
running for 65 seconds, online: 500000, NumGoroutine: 1001, success: 98516, totalSuccess: 5786724, failed: 0, totalFailed: 0
running for 66 seconds, online: 500000, NumGoroutine: 1001, success: 101117, totalSuccess: 5887841, failed: 0, totalFailed: 0
running for 67 seconds, online: 500000, NumGoroutine: 1001, success: 79006, totalSuccess: 5966847, failed: 0, totalFailed: 0
running for 68 seconds, online: 500000, NumGoroutine: 1001, success: 100489, totalSuccess: 6067336, failed: 0, totalFailed: 0
running for 69 seconds, online: 500000, NumGoroutine: 1001, success: 97181, totalSuccess: 6164517, failed: 0, totalFailed: 0
running for 70 seconds, online: 500000, NumGoroutine: 1001, success: 97435, totalSuccess: 6261952, failed: 0, totalFailed: 0
running for 71 seconds, online: 500000, NumGoroutine: 1001, success: 76442, totalSuccess: 6338394, failed: 0, totalFailed: 0
running for 72 seconds, online: 500000, NumGoroutine: 1001, success: 98346, totalSuccess: 6436740, failed: 0, totalFailed: 0
running for 73 seconds, online: 500000, NumGoroutine: 1001, success: 101912, totalSuccess: 6538652, failed: 0, totalFailed: 0
running for 74 seconds, online: 500000, NumGoroutine: 1001, success: 94463, totalSuccess: 6633115, failed: 0, totalFailed: 0
running for 75 seconds, online: 500000, NumGoroutine: 1001, success: 74964, totalSuccess: 6708079, failed: 0, totalFailed: 0
running for 76 seconds, online: 500000, NumGoroutine: 1001, success: 97997, totalSuccess: 6806076, failed: 0, totalFailed: 0
running for 77 seconds, online: 500000, NumGoroutine: 1001, success: 101100, totalSuccess: 6907176, failed: 0, totalFailed: 0
running for 78 seconds, online: 500000, NumGoroutine: 1001, success: 100266, totalSuccess: 7007442, failed: 0, totalFailed: 0
running for 79 seconds, online: 500000, NumGoroutine: 1001, success: 76948, totalSuccess: 7084390, failed: 0, totalFailed: 0
running for 80 seconds, online: 500000, NumGoroutine: 1001, success: 95402, totalSuccess: 7179792, failed: 0, totalFailed: 0
running for 81 seconds, online: 500000, NumGoroutine: 1001, success: 99296, totalSuccess: 7279088, failed: 0, totalFailed: 0
running for 82 seconds, online: 500000, NumGoroutine: 1001, success: 94681, totalSuccess: 7373769, failed: 0, totalFailed: 0
running for 83 seconds, online: 500000, NumGoroutine: 1001, success: 85122, totalSuccess: 7458891, failed: 0, totalFailed: 0
running for 84 seconds, online: 500000, NumGoroutine: 1001, success: 95900, totalSuccess: 7554791, failed: 0, totalFailed: 0
running for 85 seconds, online: 500000, NumGoroutine: 1001, success: 96551, totalSuccess: 7651342, failed: 0, totalFailed: 0
running for 86 seconds, online: 500000, NumGoroutine: 1001, success: 87017, totalSuccess: 7738359, failed: 0, totalFailed: 0
running for 87 seconds, online: 500000, NumGoroutine: 1001, success: 83920, totalSuccess: 7822279, failed: 0, totalFailed: 0
running for 88 seconds, online: 500000, NumGoroutine: 1001, success: 89833, totalSuccess: 7912112, failed: 0, totalFailed: 0
running for 89 seconds, online: 500000, NumGoroutine: 1001, success: 96766, totalSuccess: 8008878, failed: 0, totalFailed: 0
running for 90 seconds, online: 500000, NumGoroutine: 1001, success: 89377, totalSuccess: 8098255, failed: 0, totalFailed: 0
running for 91 seconds, online: 500000, NumGoroutine: 1001, success: 81048, totalSuccess: 8179303, failed: 0, totalFailed: 0
running for 92 seconds, online: 500000, NumGoroutine: 1001, success: 94305, totalSuccess: 8273608, failed: 0, totalFailed: 0
running for 93 seconds, online: 500000, NumGoroutine: 1001, success: 100855, totalSuccess: 8374463, failed: 0, totalFailed: 0
running for 94 seconds, online: 500000, NumGoroutine: 1001, success: 91703, totalSuccess: 8466166, failed: 0, totalFailed: 0
running for 95 seconds, online: 500000, NumGoroutine: 1001, success: 92517, totalSuccess: 8558683, failed: 0, totalFailed: 0
running for 96 seconds, online: 500000, NumGoroutine: 1001, success: 94160, totalSuccess: 8652843, failed: 0, totalFailed: 0
running for 97 seconds, online: 500000, NumGoroutine: 1001, success: 94903, totalSuccess: 8747746, failed: 0, totalFailed: 0 消耗: top -d 1 |
加上1024 size的buffer和cpu消耗后,nbio的内存占用仍然稳定,cpu利用率持续稳定,qps仍然能保持再9-10w级别,不像标准库下降到几k、不稳定、runtime半假死、cpu利用不起来了 |
你可以在自己环境再用不同buffer size和cpu消耗模拟下,再看看异步库实际是否有优势 |
@lesismal 是真的快,太猛了,我试试 |
@lesismal 但是你贴的是client的output,server的是漏了吗,不过没关系,我自己试试吧 |
server的output只是打印协程数、qps,qps client日志已经有了,nbio的协程数就是几百到几千的范围,标准库是一连接一协程50+w个,所以server的日志没啥用但是挺长的占篇幅我就没放,主要是看server的top占用我截了图的 |
标准库与nbio,连接数、mem与cpu的空间换时间,runtime的调度、gc和stw,存在很多平衡点、阈值,这个仓库主要是测吞吐,nbio_examples主要是提供各种示例没有做专业测试,所以不要跑简单示例后轻易下结论,要根据实际情况分析这里列出来的这些消耗、平衡点来考虑 |
我今天用这个仓库跑了下300跟1000连接的压测,数据如下:
300连接的时候
1000连接的时候
对比发现异步库跟原生Go net,在高分位时延这块,比如TP99跟TP999,,异步库是大大落后于Go net。
分析异步库的事件处理机制,我猜想原因大概是:
异步库处理读写事件循环时,是遍历所有事件,逐个去处理对应的fd,比如读取完当前fd上的数据再处理下一个fd。
这样导致越往后遍历的fd,响应越慢,比如nbio这里
而Go net是获取有读写事件的协程列表,逐个唤醒,让具体协程去处理读写事件,也就是只负责唤醒。
我的疑问这里有没有优化空间来减少高分位的时延,目前我能想到的是利用ringbuffer来实现引用读,减少遍历里边的Read耗时。
The text was updated successfully, but these errors were encountered: