Skip to content

Commit

Permalink
GC optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Jul 7, 2021
1 parent 0bb72e0 commit 148846b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tcp/tcp_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ func NewPacketPool(max int, ttl int) *pktPool {
var released int
// GC
for {
for i := 0; i < 1000; i++ {
for i := 0; i < 500; i++ {
select {
case c := <-pool.packets:
if now.Sub(c.created) < time.Duration(ttl)*time.Second {
// GC If buffer is too big and lived for too long
if len(c.buf) < 16384 && now.Sub(c.created) < time.Duration(ttl)*time.Second {
select {
case pool.packets <- c:
default:
Expand Down

0 comments on commit 148846b

Please sign in to comment.