Improve queue cleanup, batch fairness, and worker CPU efficiency

This commit is contained in:
Amin.MasterkinG
2026-04-20 20:29:23 +03:30
parent c4776c88e1
commit 1c4dd0138b
5 changed files with 117 additions and 9 deletions
+10
View File
@@ -29,8 +29,10 @@ type Client struct {
connMu sync.Mutex
conns map[net.Conn]struct{}
workCh chan struct{}
lastPollUnixMS atomic.Int64
batchCursor atomic.Uint64
}
func New(cfg config.Config, lg *logger.Logger) *Client {
@@ -43,6 +45,7 @@ func New(cfg config.Config, lg *logger.Logger) *Client {
socksConnections: NewSOCKSConnectionStore(),
chunkPolicy: newChunkPolicy(cfg),
conns: make(map[net.Conn]struct{}),
workCh: make(chan struct{}, 1),
}
}
@@ -118,6 +121,13 @@ func (c *Client) closeAllConns() {
}
}
func (c *Client) signalSendWork() {
select {
case c.workCh <- struct{}{}:
default:
}
}
func generateClientSessionKey() string {
now := time.Now().UTC().Format("20060102T150405.000000000Z")
random := make([]byte, 16)