fasthttp
fasthttp copied to clipboard
Client connection cleaner
Client and HostClient register itself to cleaner to clean resource, instead of creating a goroutine. new interface resourceClean
will help a client to clean resource. Client implements resourceClean
can register to the global cleaner.
I love this idea
@chhquan Maybe change this
func (c *Client) hasResource() bool {
c.mLock.Lock()
defer c.mLock.Unlock()
if len(c.m) > 0 || len(c.ms) > 0 {
return true
}
return false
}
to this
func (c *Client) hasResource() bool {
c.mLock.Lock()
defer c.mLock.Unlock()
return len(c.m) > 0 || len(c.ms) > 0
}
And in case !c.connsCleanerRun && !connectionClose new connection is connectionClosed we do not need to count it as a connection, maybe since we should no register such a connections in connectionsCleaner and in some cases if all connections across fasthttp.Client will be connectionClosed, maybe we don't need connectionsCleaner goroutine running.
I mean replace this
if c.connsCount == 1 {
startCleaner = true
}
maybe with this, not sure regarding connectionCounting maybe skip increasing connection counter in case connectionClose
if c.connsCount > 0 && !connectionClose {
startCleaner = true
}
to avoid creating connectionCleaner for one_time_requests-only client
@moredure @erikdubbelboer @tylitianrui ok! i will change the code for your suggestion.