-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
gnet 单核和多核配置的性能问题 #84
Comments
你是怎么看线程数量的?具体步骤贴一下?什么输出? |
我用
|
我是用如下方式测试的, 不知道为啥loops多了之后,TPS反而慢了 (multi-cores: true, loops: 1) 的 TPS大概在200K |
贴一下 server 的代码我看下? |
package main
import (
"bytes"
"flag"
"fmt"
"github.com/panjf2000/gnet"
"log"
"net/http"
)
type httpServer struct {
*gnet.EventServer
}
var rtn_close="HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/html;charset=utf-8\r\nContent-Length:2\r\n\r\nok "
var rtn="HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nContent-Type: text/html;charset=utf-8\r\nContent-Length:2\r\n\r\nok "
func (hs *httpServer) React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action) {
if c.Context() != nil {
// bad thing happened
action = gnet.Close
return
}
if bytes.Contains(frame, []byte("Keep-Alive")) || bytes.Contains(frame, []byte("keep-alive")) {
out = append(out, rtn...)
} else {
out = append(out, rtn_close...)
action = gnet.Close
}
return
}
func (hs *httpServer) OnInitComplete(srv gnet.Server) (action gnet.Action) {
log.Printf("HTTP server is listening on %s (multi-cores: %t, loops: %d)\n",
srv.Addr.String(), srv.Multicore, srv.NumEventLoop)
return
}
func main() {
var port int
var NumEventLoop int
// Example command: go run http.go --port 8080
flag.IntVar(&port, "port", 50007, "server port")
flag.IntVar(&NumEventLoop, "NumEventLoop", 4, "num loops")
flag.Parse()
http := new(httpServer)
// Start serving!
log.Fatal(gnet.Serve(http, fmt.Sprintf("tcp://:%d", port), gnet.WithNumEventLoop(NumEventLoop), gnet.WithMulticore(true)))
} |
抱歉,回复晚了。 |
ab 是单核心测试工具,试下wrk呢。我猜和客户端有关系,客户端只能使用一个物理核心的算力,服务端加两个核心,benchmark数据也是上不去的。 |
上不去也不应该下降吧 |
可能是测试结果波动?多测几次也是这样吗?或者试试只设置 |
通过下面设置单核真的比默认开启多核性能高 |
测试代码业务处理很快,瓶颈在I/0, 启动多核后也无法解决I/0的瓶颈 |
请问这个问题得到了验证吗 |
我们利用gnet实现的ws框架,性能4核的时候是1核的2倍多一点,很好奇这个cpu 亲和性是怎么做的 |
This issue is marked as stale because it has been open for 30 days with no activity. You should take one of the following actions:
This issue will be automatically closed in 7 days if no further activity occurs. |
This issue was closed because it has been inactive for 7 days since being marked as stale. If you believe this is a false alarm, please leave a comment for it or open a new issue, you can also reopen this issue directly if you have permission. |
多核linux和mac下配置NumEventLoop多了反而没有没有配置1的性能高,然后用pprof查看线程不管配置1还是4,都是只有一个线程(多个协程)。
怎样能让gnet确实启动多个线程呢?
The text was updated successfully, but these errors were encountered: