DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

1m websocket use go

原文链接

解决too many files

every socket is represented by a file descriptor

optimization:

  • goroutines

在goroutines部分,采用epoll的方式

1
2
3
4
5
6
7
8
9
fd, err := unix.EpollCreatel(0)
if err != nil {
return nil, err
}
fd := websocketFD(conn)
err := unix.EpollCtl(e.fd, syscall.EPOLL_CTL_ADD, fd, &unix.EpollEvent{}..)
if err !=nil {
return err
}

reduce 30%

  • buffers allocations

github.com/gobwas/ws

reduce 97%

*