Skip to content

Commit

Permalink
- open OnWriteBufferRelease for http
Browse files Browse the repository at this point in the history
  • Loading branch information
lesismal committed Jul 3, 2021
1 parent 5083379 commit 5a8ed7b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ go 1.16
require (
github.com/gorilla/websocket v1.4.2
github.com/julienschmidt/httprouter v1.3.0
github.com/lesismal/llib v1.0.3
github.com/lesismal/llib v1.0.4
github.com/valyala/fasthttp v1.24.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/lesismal/llib v1.0.2 h1:7tj63E7oGHpzn+j2i/UsqOR8zdnWb1zzbrOA09cG1vo=
github.com/lesismal/llib v1.0.2/go.mod h1:3vmCrIMrpkaoA3bDu/sI+J7EyEUMPbOvmAxb7PlzilM=
github.com/lesismal/llib v1.0.3 h1:FAiXf4GSCNveBw+dpH/mC9/tmsopi3ifC/GDwV2IDP0=
github.com/lesismal/llib v1.0.3/go.mod h1:3vmCrIMrpkaoA3bDu/sI+J7EyEUMPbOvmAxb7PlzilM=
github.com/lesismal/llib v1.0.4 h1:hZ+gHeDAIiSfk3QMHuNxAX6nHCZB5sVdZdsbJGcMpJM=
github.com/lesismal/llib v1.0.4/go.mod h1:3vmCrIMrpkaoA3bDu/sI+J7EyEUMPbOvmAxb7PlzilM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
Expand Down
5 changes: 4 additions & 1 deletion mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,15 @@ func (c *ChosMemPool) Realloc(buf []byte, size int) []byte {
}
newBuf := c.Malloc(size)
copy(newBuf, buf)
// c.pool.Put(buf)
c.pool.Put(buf)
return newBuf[:size]
}

// Free .
func (c *ChosMemPool) Free(buf []byte) error {
if cap(buf) < c.minSize {
return nil
}
atomic.AddInt64(&freeCnt, 1)
atomic.AddInt64(&freeCntSize, int64(cap(buf)))
c.pool.Put(buf)
Expand Down
12 changes: 6 additions & 6 deletions nbhttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ func NewServer(conf Config, handler http.Handler, messageHandlerExecutor func(in
// return mempool.Malloc(int(conf.ReadBufferSize))
// })
// g.OnReadBufferFree(func(c *nbio.Conn, buffer []byte) {})
// g.OnWriteBufferRelease(func(c *nbio.Conn, buffer []byte) {
// mempool.Free(buffer)
// })
g.OnWriteBufferRelease(func(c *nbio.Conn, buffer []byte) {
mempool.Free(buffer)
})

g.OnStop(func() {
svr._onStop()
Expand Down Expand Up @@ -535,9 +535,9 @@ func NewServerTLS(conf Config, handler http.Handler, messageHandlerExecutor func
// return mempool.Malloc(int(conf.ReadBufferSize))
// })
// g.OnReadBufferFree(func(c *nbio.Conn, buffer []byte) {})
// g.OnWriteBufferRelease(func(c *nbio.Conn, buffer []byte) {
// mempool.Free(buffer)
// })
g.OnWriteBufferRelease(func(c *nbio.Conn, buffer []byte) {
mempool.Free(buffer)
})

g.OnStop(func() {
svr._onStop()
Expand Down

0 comments on commit 5a8ed7b

Please sign in to comment.