diff --git a/internal/pool.go b/internal/pool.go index 2118eca..7d4e5bd 100644 --- a/internal/pool.go +++ b/internal/pool.go @@ -58,13 +58,13 @@ func NewPool(ctx context.Context, config *pkg.Config, outputCh chan *baseline) ( var bl *baseline resp, reqerr := pool.client.Do(pctx, req) + defer fasthttp.ReleaseResponse(resp) + defer fasthttp.ReleaseRequest(req) if reqerr != nil && reqerr != fasthttp.ErrBodyTooLarge { //logs.Log.Debugf("%s request error, %s", strurl, err.Error()) pool.errorCount++ bl = &baseline{UrlString: pool.BaseURL + unit.path, Err: reqerr} } else { - defer fasthttp.ReleaseResponse(resp) - defer fasthttp.ReleaseRequest(req) //defer resp.Body.Close() // 必须要关闭body ,否则keep-alive无法生效 if err = pool.PreCompare(resp); err == nil || unit.source == CheckSource { // 通过预对比跳过一些无用数据, 减少性能消耗 diff --git a/pkg/client.go b/pkg/client.go index dd60e6e..2bdc742 100644 --- a/pkg/client.go +++ b/pkg/client.go @@ -13,16 +13,6 @@ var ( ) func NewClient(thread int, timeout int) *Client { - //tr := &http.Transport{ - // //Proxy: Proxy, - // //TLSHandshakeTimeout : delay * time.Second, - // TLSClientConfig: &tls.Config{ - // Renegotiation: tls.RenegotiateOnceAsClient, - // InsecureSkipVerify: true, - // }, - // MaxConnsPerHost: thread, - // IdleConnTimeout: time.Duration(timeout) * time.Second, - //} c := &Client{ client: &fasthttp.Client{ TLSConfig: &tls.Config{ @@ -30,7 +20,7 @@ func NewClient(thread int, timeout int) *Client { InsecureSkipVerify: true, }, //ReadBufferSize: 20480, - MaxConnsPerHost: thread, + MaxConnsPerHost: thread * 2, MaxIdleConnDuration: time.Duration(timeout) * time.Second, MaxConnWaitTimeout: time.Duration(timeout) * time.Second, ReadTimeout: time.Duration(timeout) * time.Second,