Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

optimize the HTTPWithHeaders #1351

Merged
merged 1 commit into from
May 20, 2020

Conversation

wangforthinker
Copy link
Contributor

…ort and add timeout in request context to share the http client.

Signed-off-by: allen.wq [email protected]

Ⅰ. Describe what this PR did

Optimize the HTTPWithHeaders. When do a http request, share the transport and add timeout in request context to share the http client.
In the early version, if we do a request with HTTPWithHeaders, new transport will be generated every request, which cases a lot of goroutines for cached conn in transport.

In my unit test, it causes error:

go test -race -v
race: limit on 8128 simultaneously alive goroutines is exceeded, dying

Ⅱ. Does this pull request fix one issue?

NONE.

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

Add ut.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@wangforthinker wangforthinker changed the title optimize the HTTPWithHeaders.When do a http request, share the transp… optimize the HTTPWithHeaders May 18, 2020
@@ -52,6 +54,11 @@ const (
DefaultTimeout = 500 * time.Millisecond
)

var (
defaultBuiltInTransport *http.Transport
defaultBuiltInHTTPClient *http.Client
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMOP, it's better to expose them for other packages to customized them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

…ort and add timeout in request context to share the http client.

Signed-off-by: allen.wq <[email protected]>
@wangforthinker wangforthinker force-pushed the feat/optimize-HTTPWithHeaders branch from a8fe091 to edaaa3b Compare May 19, 2020 02:31
@codecov-commenter
Copy link

Codecov Report

Merging #1351 into master will increase coverage by 0.21%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1351      +/-   ##
==========================================
+ Coverage   51.34%   51.55%   +0.21%     
==========================================
  Files         130      130              
  Lines        8578     8612      +34     
==========================================
+ Hits         4404     4440      +36     
+ Misses       3806     3804       -2     
  Partials      368      368              
Impacted Files Coverage Δ
pkg/httputils/http_util.go 76.22% <100.00%> (+4.36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d499c51...edaaa3b. Read the comment docs.

Copy link
Member

@lowzj lowzj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lowzj lowzj merged commit eb8359c into dragonflyoss:master May 20, 2020
@wangforthinker wangforthinker deleted the feat/optimize-HTTPWithHeaders branch May 21, 2020 06:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants