Comments (7)
@xtaci any idea, why? looking at the profiler it shows somehow this list https://github.com/xtaci/gaio/blob/master/watcher.go#L563 is getting larger and larger and eventually runs out even though I have 8GB machine.
from gaio.
lemme look into this, somewhat wired.
from gaio.
@xtaci Please let me know if you need any more info. I can provide that pretty quickly since I spent few days tweaking it. Also, I have one question regarding async io call backs. It appears to me(although not 100% sure) that an aiocb object is created for every write request (ignoring reads for the sake of this discussion) if so, I am guessing what might be happening is that if we have slow clients the number of callbacks are piling up in the list pointed out in my previous comment and eventually running out of 8GB memory. so I tried changing write
to writeTimeout
of 100ms in the above code and that still didn't work. it is still causing OOM. Now the question I wanted to ask is, what happens if my server send a ton of write requests to all 3K sockets? would ii block at some point? if not, how to prevent OOM?
from gaio.
could you show me a code snippet which can re-appear the OOM
from gaio.
clients
aiocb is allocated via pool, and will be recycled
func init() {
aiocbPool.New = func() interface{} {
return new(aiocb)
}
}
from gaio.
@xtaci its the same as pasted above. let me know if you need more clarification ? I am also pasting below. this is very similar to your push server example, except I am using map of connections instead of can array. OOM happens when there are 1K+ connections with the code below. On a high level the code is just trying broadcast each message from a message queue to all the connected clients concurrently.
clients := map[string]net.Conn{}
go func() {
for {
select {
case res := <-chIO: // receive IO events from watcher
if res.Error != nil {
log.Error().Msgf("Error receiving IO event from watcher: %v", res.Error)
delete(clients, res.Conn.RemoteAddr().String())
err = w.Free(res.Conn)
if err != nil {
log.Error().Msgf("error freeing connection: %v", err)
}
continue
}
case feed := <-out:
f := ws.NewTextFrame(feed)
bts := CompileHeader(f.Header)
for index, conn := range clients {
if conn != nil {
err = w.Write(nil, conn, bts)
if err != nil {
if errors.Is(err, syscall.EPIPE) || errors.Is(err, syscall.ECONNRESET) {
delete(clients, index)
} else {
log.Error().Msgf("unable to write header: %v", err)
}
}
err = w.Write(nil, conn, f.Payload)
if err != nil {
if errors.Is(err, syscall.EPIPE) || errors.Is(err, syscall.ECONNRESET) {
delete(clients, index)
} else {
log.Error().Msgf("unable to write payload: %v", err)
}
}
}
}
case conn := <-chConn: // receive new connection events
clients[conn.RemoteAddr().String()] = conn
}
}
}()
@xtaci let me know if there are specific parts of this code you want me to explain?
from gaio.
func init() {
aiocbPool.New = func() interface{} {
return new(aiocb)
}
}
@xtaci what is the pool size here? and what happens if the pool is full? Does the event loop suspend its thread?
from gaio.
Related Issues (19)
- Memory consumption benchmark? HOT 2
- does this support UDP ? HOT 1
- Detach a connection from watcher. HOT 5
- tls support
- does this support UDP also ? HOT 3
- Watcher should not be limited to net.Conn, file descriptor maybe better HOT 1
- 如何获取客户端关闭链接事件
- poller没有区分提交的是读还是写请求问题 HOT 9
- `go get` error HOT 2
- dara race issue HOT 2
- go 1.17在linux下编译不过
- when support tls?
- net.Dial可以用吗? HOT 1
- 关于 loop 函数中 copy(pending, w.pending) 的疑问 HOT 1
- epoll边缘触发数据未读完的问题 HOT 3
- 如何利用多核呢 HOT 1
- 为什么不支持windows啊- - HOT 2
- 超时处理问题
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gaio.