Skip to content

Conversation

@ii2day
Copy link
Member

@ii2day ii2day commented May 11, 2023

No description provided.

@ii2day ii2day requested a review from weizhoublue as a code owner May 11, 2023 06:48
@ii2day ii2day added enhancement New feature or request release/feature feature pr recoded in new release labels May 11, 2023
@ii2day ii2day force-pushed the http_client_hey branch from 9a0e042 to b9cf7c9 Compare May 11, 2023 06:52
@codecov
Copy link

codecov bot commented May 11, 2023

Codecov Report

Merging #346 (950b52d) into main (ba3afc2) will increase coverage by 1.33%.
The diff coverage is n/a.

Impacted file tree graph

@@            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              
Flag Coverage Δ
unittests 31.56% <ø> (+1.33%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/loadRequest/loadDns/dns.go 78.32% <ø> (ø)

@ii2day ii2day force-pushed the http_client_hey branch 5 times, most recently from 5019b0c to e367d17 Compare May 11, 2023 11:27
w.Init()

// The monitoring task timed out
if duration > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

duration <=0 , error ?

Copy link
Member Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

2023

Copy link
Member Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

// comment ?

Copy link
Member Author

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
Copy link
Collaborator

@weizhoublue weizhoublue May 11, 2023

Choose a reason for hiding this comment

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

// comment ?

Copy link
Member Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

what size

Copy link
Member Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

MaxResultChannelSize = ?

Copy link
Member Author

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"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

P50_inMs int

Copy link
Member Author

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()
Copy link
Collaborator

Choose a reason for hiding this comment

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

启动, 结束 ? 日志

Copy link
Member Author

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++ {
Copy link
Collaborator

@weizhoublue weizhoublue May 11, 2023

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

Copy link
Member Author

Choose a reason for hiding this comment

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

b.NumberRequest 为int32的最大值,不存在0的情况

Copy link
Collaborator

Choose a reason for hiding this comment

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

1900/1000 = 1 ? 误差过大

Copy link
Member Author

Choose a reason for hiding this comment

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

int32最大值为2147483647最多的情况下发送这么多请求,并平分给每一个协程

@ii2day ii2day force-pushed the http_client_hey branch 2 times, most recently from e40635f to f6bb21d Compare May 12, 2023 06:21
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 4 Security Hotspots
Code Smell A 5 Code Smells

No Coverage information No Coverage information
9.4% 9.4% Duplication

@ii2day ii2day force-pushed the http_client_hey branch 4 times, most recently from fac8ae9 to 9872858 Compare May 17, 2023 10:58
| spiderdoctor | 1m | 67346 | 1122.43 | 2Gi |
| wrk | 1m | 53612 | 892.85 | 2Mb |
## Http1.1

Copy link
Collaborator

Choose a reason for hiding this comment

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

并发连接是多少

Copy link
Member Author

Choose a reason for hiding this comment

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

700

Copy link
Collaborator

Choose a reason for hiding this comment

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

我是指 要 写到 md 上

Copy link
Member Author

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
Copy link
Collaborator

@weizhoublue weizhoublue May 19, 2023

Choose a reason for hiding this comment

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

todo:configmap 化

Copy link
Member Author

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))
Copy link
Collaborator

Choose a reason for hiding this comment

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

b.Concurrency*1000 是什么意思

Copy link
Member Author

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) {
Copy link
Collaborator

@weizhoublue weizhoublue May 19, 2023

Choose a reason for hiding this comment

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

DNSStart ?也会 生成 dns 指标是吧 ?

Copy link
Member Author

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))
Copy link
Collaborator

@weizhoublue weizhoublue May 19, 2023

Choose a reason for hiding this comment

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

为什么 每个请求的 超时 控制 没体现在 req.Context 中 ?

Copy link
Member Author

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)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

b.QPS <=0 ? error

Copy link
Member Author

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

不能 指针复用,需要 clone 么 ?

Copy link
Member Author

@ii2day ii2day May 19, 2023

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
Copy link
Collaborator

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 的 复用

Copy link
Member Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

时间的统计要前置,才精确

Copy link
Member Author

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:
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里就return 了 ? 不等 最后一个 request 收到 响应 进入统计 ?

Copy link
Member Author

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{
Copy link
Collaborator

Choose a reason for hiding this comment

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

这最终是个什么报告 格式

Copy link
Member Author

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

@ii2day ii2day force-pushed the http_client_hey branch 2 times, most recently from ef72056 to 03f1ffa Compare May 22, 2023 10:39
InsecureSkipVerify: true,
ServerName: b.Request.Host,
},
MaxIdleConnsPerHost: 50,
Copy link
Collaborator

@weizhoublue weizhoublue May 22, 2023

Choose a reason for hiding this comment

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

hardcode 不是 直接真的写死,而是 环境变量化
同理 DNS ?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@ii2day ii2day force-pushed the http_client_hey branch 2 times, most recently from 436f1bc to d5e9e5b Compare May 23, 2023 06:24
@ii2day ii2day force-pushed the http_client_hey branch from d5e9e5b to 950b52d Compare May 23, 2023 07:05
@weizhoublue weizhoublue merged commit 039f458 into main May 23, 2023
@weizhoublue weizhoublue deleted the http_client_hey branch May 23, 2023 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request release/feature feature pr recoded in new release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants