mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-27 06:10:26 +08:00
optimize: add thread pool
This commit is contained in:
@@ -1,12 +1,32 @@
|
||||
package head
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/fumiama/WireGold/config"
|
||||
"github.com/fumiama/WireGold/internal/file"
|
||||
"github.com/fumiama/orbyte/pbuf"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var packetPool = pbuf.NewBufferPool[Packet]()
|
||||
|
||||
func init() {
|
||||
if config.ShowDebugLog {
|
||||
go status()
|
||||
}
|
||||
}
|
||||
|
||||
// selectPacket 从池中取出一个 Packet
|
||||
func selectPacket(buf ...byte) *PacketItem {
|
||||
return packetPool.NewBuffer(buf)
|
||||
}
|
||||
|
||||
func status() {
|
||||
for range time.NewTicker(time.Minute).C {
|
||||
out, in := packetPool.CountItems()
|
||||
logrus.Infoln(file.Header(), "packet outside:", out, "inside:", in)
|
||||
out, in = pbuf.CountItems()
|
||||
logrus.Infoln(file.Header(), "default outside:", out, "inside:", in)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user