1
0
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:
源文雨
2025-04-14 20:56:06 +09:00
parent 8b28dbcd3c
commit 8e79f419b8
6 changed files with 69 additions and 6 deletions

View File

@@ -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)
}
}