fasthttp icon indicating copy to clipboard operation
fasthttp copied to clipboard

Client connection cleaner

Open chhquan opened this issue 2 years ago • 5 comments

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.

chhquan avatar Sep 11 '21 08:09 chhquan

I love this idea

moredure avatar Sep 11 '21 13:09 moredure

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

moredure avatar Sep 11 '21 13:09 moredure

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.

moredure avatar Sep 11 '21 13:09 moredure

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 avatar Sep 11 '21 13:09 moredure

@moredure @erikdubbelboer @tylitianrui ok! i will change the code for your suggestion.

chhquan avatar Sep 26 '21 03:09 chhquan