mirror of
https://github.com/chainreactors/spray.git
synced 2025-09-15 11:40:13 +00:00
略微优化fasthttp性能
This commit is contained in:
parent
ea3ea58dd2
commit
ecc83802e7
@ -58,13 +58,13 @@ func NewPool(ctx context.Context, config *pkg.Config, outputCh chan *baseline) (
|
|||||||
|
|
||||||
var bl *baseline
|
var bl *baseline
|
||||||
resp, reqerr := pool.client.Do(pctx, req)
|
resp, reqerr := pool.client.Do(pctx, req)
|
||||||
|
defer fasthttp.ReleaseResponse(resp)
|
||||||
|
defer fasthttp.ReleaseRequest(req)
|
||||||
if reqerr != nil && reqerr != fasthttp.ErrBodyTooLarge {
|
if reqerr != nil && reqerr != fasthttp.ErrBodyTooLarge {
|
||||||
//logs.Log.Debugf("%s request error, %s", strurl, err.Error())
|
//logs.Log.Debugf("%s request error, %s", strurl, err.Error())
|
||||||
pool.errorCount++
|
pool.errorCount++
|
||||||
bl = &baseline{UrlString: pool.BaseURL + unit.path, Err: reqerr}
|
bl = &baseline{UrlString: pool.BaseURL + unit.path, Err: reqerr}
|
||||||
} else {
|
} else {
|
||||||
defer fasthttp.ReleaseResponse(resp)
|
|
||||||
defer fasthttp.ReleaseRequest(req)
|
|
||||||
//defer resp.Body.Close() // 必须要关闭body ,否则keep-alive无法生效
|
//defer resp.Body.Close() // 必须要关闭body ,否则keep-alive无法生效
|
||||||
if err = pool.PreCompare(resp); err == nil || unit.source == CheckSource {
|
if err = pool.PreCompare(resp); err == nil || unit.source == CheckSource {
|
||||||
// 通过预对比跳过一些无用数据, 减少性能消耗
|
// 通过预对比跳过一些无用数据, 减少性能消耗
|
||||||
|
@ -13,16 +13,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewClient(thread int, timeout int) *Client {
|
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{
|
c := &Client{
|
||||||
client: &fasthttp.Client{
|
client: &fasthttp.Client{
|
||||||
TLSConfig: &tls.Config{
|
TLSConfig: &tls.Config{
|
||||||
@ -30,7 +20,7 @@ func NewClient(thread int, timeout int) *Client {
|
|||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
},
|
},
|
||||||
//ReadBufferSize: 20480,
|
//ReadBufferSize: 20480,
|
||||||
MaxConnsPerHost: thread,
|
MaxConnsPerHost: thread * 2,
|
||||||
MaxIdleConnDuration: time.Duration(timeout) * time.Second,
|
MaxIdleConnDuration: time.Duration(timeout) * time.Second,
|
||||||
MaxConnWaitTimeout: time.Duration(timeout) * time.Second,
|
MaxConnWaitTimeout: time.Duration(timeout) * time.Second,
|
||||||
ReadTimeout: time.Duration(timeout) * time.Second,
|
ReadTimeout: time.Duration(timeout) * time.Second,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user