-
Notifications
You must be signed in to change notification settings - Fork 3
optimize HTTP client performance #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## main #346 +/- ##
==========================================
+ Coverage 30.23% 31.56% +1.33%
==========================================
Files 7 6 -1
Lines 473 453 -20
==========================================
Hits 143 143
+ Misses 319 299 -20
Partials 11 11
Flags with carried forward coverage won't be shown. Click here to find out more.
|
5019b0c to
e367d17
Compare
pkg/loadRequest/loadHttp/http.go
Outdated
| w.Init() | ||
|
|
||
| // The monitoring task timed out | ||
| if duration > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duration <=0 , error ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duration 不存在小于0的情况 已删除此处判断
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // Copyright 2022 Authors of spidernet-io |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
|
||
| type report struct { | ||
| avgTotal float64 | ||
| average float64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// comment ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| total time.Duration | ||
|
|
||
| errorDist map[string]int | ||
| lats []float32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// comment ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
|
||
| errorDist map[string]int | ||
| lats []float32 | ||
| sizeTotal int64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| ) | ||
|
|
||
| // Max size of the buffer of result channel. | ||
| const maxResult = 1000000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MaxResultChannelSize = ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| // Mean is the mean request latency. | ||
| Mean string `json:"mean"` | ||
| // P50 is the 50th percentile request latency. | ||
| P50 string `json:"50th"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P50_inMs int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| // Run makes all the requests, prints the summary. It blocks until | ||
| // all work is done. | ||
| func (b *Work) Run() { | ||
| b.Init() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
启动, 结束 ? 日志
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| } | ||
| } | ||
|
|
||
| for i := 0; i < b.NumberRequest/b.Concurrency; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b.NumberRequest/b.Concurrency = 0 ?
log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b.NumberRequest 为int32的最大值,不存在0的情况
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1900/1000 = 1 ? 误差过大
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int32最大值为2147483647最多的情况下发送这么多请求,并平分给每一个协程
e40635f to
f6bb21d
Compare
|
SonarCloud Quality Gate failed.
|
fac8ae9 to
9872858
Compare
| | spiderdoctor | 1m | 67346 | 1122.43 | 2Gi | | ||
| | wrk | 1m | 53612 | 892.85 | 2Mb | | ||
| ## Http1.1 | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
并发连接是多少
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
700
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我是指 要 写到 md 上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| ) | ||
|
|
||
| // We report for max 1M results. | ||
| const maxRes = 1000000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo:configmap 化
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| // Init initializes internal data-structures | ||
| func (b *Work) Init() { | ||
| b.initOnce.Do(func() { | ||
| b.results = make(chan *result, minInt(b.Concurrency*1000, MaxResultChannelSize)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b.Concurrency*1000 是什么意思
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
| req = cloneRequest(b.Request, b.RequestBody) | ||
| } | ||
| trace := &httptrace.ClientTrace{ | ||
| DNSStart: func(info httptrace.DNSStartInfo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DNSStart ?也会 生成 dns 指标是吧 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的
| } | ||
| }, | ||
| } | ||
| req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么 每个请求的 超时 控制 没体现在 req.Context 中 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
超时是由client 控制的,req 只是表示请求体
| var ticker *time.Ticker | ||
| if b.QPS > 0 { | ||
| ticker = time.NewTicker(time.Duration(1e6*b.Concurrency/(b.QPS)) * time.Microsecond) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b.QPS <=0 ? error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<=0 表示 不限制qps ,按照当前并发量最大限度的去请求
|
|
||
| // cloneRequest returns a clone of the provided *http.Request. | ||
| // The clone is a shallow copy of the struct and its Header map. | ||
| func cloneRequest(r *http.Request, body []byte) *http.Request { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不能 指针复用,需要 clone 么 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
共享req存在并发安全需要每个请求要使用单独的req
| func (b *Work) makeRequest(c *http.Client) { | ||
| s := b.now() | ||
| var size int64 | ||
| var dnsStart, connStart, resStart time.Duration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哪里体现 http 1.1 的 并发 和 http 2.0 的 复用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
创建client时候,如果是http2 会对Transport 里的连接池进行设置
| } | ||
|
|
||
| t := b.now() | ||
| resDuration = t - resStart |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
时间的统计要前置,才精确
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b.now是结构体自己实现的方法,是基于任务开始时的时间统计
| for i := 0; i < b.NumberRequest/b.Concurrency; i++ { | ||
| // Check if application is stopped. Do not send into a closed channel. | ||
| select { | ||
| case <-b.stopCh: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里就return 了 ? 不等 最后一个 request 收到 响应 进入统计 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对于规定时间外的请求可以抛弃掉吧?等待响应同时也会增加任务的时间。
| } else { | ||
| testTargetList = append(testTargetList, &testTarget{Name: "typeAAAA_" + server + "_" + instance.Spec.Request.Domain, Request: &loadRequest.DnsRequestData{ | ||
| Protocol: loadRequest.RequestProtocol(*instance.Spec.Target.Protocol), | ||
| testTargetList = append(testTargetList, &testTarget{Name: "typeAAAA_" + server + "_" + instance.Spec.Request.Domain, Request: &loadDns.DnsRequestData{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这最终是个什么报告 格式
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
"FailureReason": "",
"MeanDelay": 1159.42,
"Metrics": {
"start": "2023-05-19T08:05:04.19319882Z",
"end": "2023-05-19T08:05:31.235607741Z",
"duration": "27.042408921s",
"requestCount": 50,
"successCount": 50,
"rate": 1.8489477082484356,
"status_codes": {
"200": 50
},
"total_request_data": "11592 byte",
"latencies": {
"P50_inMs": 1115,
"P90_inMs": 1387,
"P95_inMs": 1477.5,
"P99_inMs": 1494,
"Max_inMx": 1496,
"Min_inMs": 844,
"Mean_inMs": 1159.42
},
"errors": {}
},
"Succeed": "true",
"SucceedRate": "1",
"TargetMethod": "GET",
"TargetName": "AgentLoadbalancerV4IP_172.18.0.51:80",
"TargetUrl": "http://172.18.0.51:80"
}
ef72056 to
03f1ffa
Compare
| InsecureSkipVerify: true, | ||
| ServerName: b.Request.Host, | ||
| }, | ||
| MaxIdleConnsPerHost: 50, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hardcode 不是 直接真的写死,而是 环境变量化
同理 DNS ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
436f1bc to
d5e9e5b
Compare
Signed-off-by: ii2day <[email protected]>









No description provided.