-
-
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
lockFreeQueue的gc问题 #283
Comments
你可以测一下,然后把数据贴出来看看,看看是不是的确会有很大影响。 |
1.新增的测试代码/cmd/main.go type testCodec struct {
}
func (cc *testCodec) Encode(c gnet.Conn, buf []byte) (out []byte, err error) {
return buf, nil
}
func (cc *testCodec) Decode(c gnet.Conn) ([]byte, error) {
var buf innerBuffer
buf = c.Read()
msg, _ := buf.readN(4)
if msg == nil {
return nil, nil
}
c.ShiftN(4)
return msg, nil
}
type testServer struct {
*gnet.EventServer
svr gnet.Server
protoAddr string
workerPool *goroutine.Pool
}
func (s *testServer) React(packet []byte, c gnet.Conn) (out []byte, action gnet.Action) {
data := append([]byte{}, packet...)
_ = s.workerPool.Submit(func() {
_ = c.AsyncWrite(data)
})
return nil, gnet.None
}
func main() {
f, _ := os.OpenFile("gate-cpu.pprof", os.O_CREATE|os.O_RDWR, 0644)
_ = pprof.StartCPUProfile(f)
defer func() {
pprof.StopCPUProfile()
f.Close()
}()
ts := &testServer{
protoAddr: "tcp4://0.0.0.0:9999",
workerPool: goroutine.Default(),
}
go func() {
time.Sleep(70 * time.Second)
_ = gnet.Stop(context.TODO(), ts.protoAddr)
}()
err := gnet.Serve(ts,
ts.protoAddr,
gnet.WithLockOSThread(true),
gnet.WithNumEventLoop(3),
gnet.WithReuseAddr(true),
gnet.WithTCPNoDelay(gnet.TCPNoDelay),
gnet.WithCodec(&testCodec{}),
gnet.WithLoadBalancing(gnet.LeastConnections))
fmt.Println("serve", err)
} 2.go tool pprof数据: 3.runtime.mallocgc相关的调用 |
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. |
lock_free_queue.go的Enqueue()函数内的
n := &node{value: task}
会调用到runtime.newobject和runtime.mallocgc,Enqueue()频繁调用时,是否会有gc问题,是否考虑用类似sync.Pool的形式来管理node
The text was updated successfully, but these errors were encountered: