refactor: move stress-test tools location. (#3295)

* refactor: move stress-test tools location.

* improve stress tools.

* improve stress_test-v2
This commit is contained in:
Monet Lee 2025-04-25 15:57:23 +08:00 committed by GitHub
parent 91db18168d
commit dd981b976d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 69 additions and 33 deletions

View File

@ -0,0 +1,19 @@
# Stress Test V2
## Usage
You need set `TestTargetUserList` variables.
### Build
```bash
go build -o test/stress-test-v2/stress-test-v2 test/stress-test-v2/main.go
```
### Excute
```bash
tools/stress-test-v2/stress-test-v2 -c config/
```

View File

@ -56,6 +56,7 @@ var (
const ( const (
MaxUser = 100000 MaxUser = 100000
Max1kUser = 1000
Max100KGroup = 100 Max100KGroup = 100
Max999Group = 1000 Max999Group = 1000
MaxInviteUserLimit = 999 MaxInviteUserLimit = 999
@ -161,7 +162,7 @@ func (st *StressTest) PostRequest(ctx context.Context, url string, reqbody any)
if baseResp.ErrCode != 0 { if baseResp.ErrCode != 0 {
err = fmt.Errorf(baseResp.ErrMsg) err = fmt.Errorf(baseResp.ErrMsg)
log.ZError(ctx, "Failed to send request", err, "url", url, "reqbody", reqbody, "resp", baseResp) // log.ZError(ctx, "Failed to send request", err, "url", url, "reqbody", reqbody, "resp", baseResp)
return nil, err return nil, err
} }
@ -530,9 +531,20 @@ func main() {
// Create 100K groups // Create 100K groups
st.Wg.Add(1) st.Wg.Add(1)
go func(idx int) { go func(idx int) {
startTime := time.Now()
defer func() {
elapsedTime := time.Since(startTime)
log.ZInfo(st.Ctx, "100K group creation completed",
"groupID", fmt.Sprintf("v2_StressTest_Group_100K_%d", idx),
"index", idx,
"duration", elapsedTime.String())
}()
defer st.Wg.Done() defer st.Wg.Done()
defer func() { defer func() {
st.Mutex.Lock()
st.Create100kGroupCounter++ st.Create100kGroupCounter++
st.Mutex.Unlock()
}() }()
groupID := fmt.Sprintf("v2_StressTest_Group_100K_%d", idx) groupID := fmt.Sprintf("v2_StressTest_Group_100K_%d", idx)
@ -542,7 +554,7 @@ func main() {
// continue // continue
} }
for i := 0; i < MaxUser/MaxInviteUserLimit; i++ { for i := 0; i <= MaxUser/MaxInviteUserLimit; i++ {
InviteUserIDs := make([]string, 0) InviteUserIDs := make([]string, 0)
// ensure TargetUserList is in group // ensure TargetUserList is in group
InviteUserIDs = append(InviteUserIDs, TestTargetUserList...) InviteUserIDs = append(InviteUserIDs, TestTargetUserList...)
@ -556,7 +568,7 @@ func main() {
} }
if len(InviteUserIDs) == 0 { if len(InviteUserIDs) == 0 {
log.ZWarn(st.Ctx, "InviteUserIDs is empty", nil, "groupID", groupID) // log.ZWarn(st.Ctx, "InviteUserIDs is empty", nil, "groupID", groupID)
continue continue
} }
@ -567,7 +579,7 @@ func main() {
} }
if len(InviteUserIDs) == 0 { if len(InviteUserIDs) == 0 {
log.ZWarn(st.Ctx, "InviteUserIDs is empty", nil, "groupID", groupID) // log.ZWarn(st.Ctx, "InviteUserIDs is empty", nil, "groupID", groupID)
continue continue
} }
@ -602,9 +614,20 @@ func main() {
// Create 999 groups // Create 999 groups
st.Wg.Add(1) st.Wg.Add(1)
go func(idx int) { go func(idx int) {
startTime := time.Now()
defer func() {
elapsedTime := time.Since(startTime)
log.ZInfo(st.Ctx, "999 group creation completed",
"groupID", fmt.Sprintf("v2_StressTest_Group_1K_%d", idx),
"index", idx,
"duration", elapsedTime.String())
}()
defer st.Wg.Done() defer st.Wg.Done()
defer func() { defer func() {
st.Mutex.Lock()
st.Create999GroupCounter++ st.Create999GroupCounter++
st.Mutex.Unlock()
}() }()
groupID := fmt.Sprintf("v2_StressTest_Group_1K_%d", idx) groupID := fmt.Sprintf("v2_StressTest_Group_1K_%d", idx)
@ -613,13 +636,13 @@ func main() {
log.ZError(st.Ctx, "Create group failed.", err) log.ZError(st.Ctx, "Create group failed.", err)
// continue // continue
} }
for i := 0; i < MaxUser/MaxInviteUserLimit; i++ { for i := 0; i <= Max1kUser/MaxInviteUserLimit; i++ {
InviteUserIDs := make([]string, 0) InviteUserIDs := make([]string, 0)
// ensure TargetUserList is in group // ensure TargetUserList is in group
InviteUserIDs = append(InviteUserIDs, TestTargetUserList...) InviteUserIDs = append(InviteUserIDs, TestTargetUserList...)
startIdx := max(i*MaxInviteUserLimit, 1) startIdx := max(i*MaxInviteUserLimit, 1)
endIdx := min((i+1)*MaxInviteUserLimit, MaxUser) endIdx := min((i+1)*MaxInviteUserLimit, Max1kUser)
for j := startIdx; j < endIdx; j++ { for j := startIdx; j < endIdx; j++ {
userCreatedID := fmt.Sprintf("v2_StressTest_User_%d", j) userCreatedID := fmt.Sprintf("v2_StressTest_User_%d", j)
@ -627,7 +650,7 @@ func main() {
} }
if len(InviteUserIDs) == 0 { if len(InviteUserIDs) == 0 {
log.ZWarn(st.Ctx, "InviteUserIDs is empty", nil, "groupID", groupID) // log.ZWarn(st.Ctx, "InviteUserIDs is empty", nil, "groupID", groupID)
continue continue
} }
@ -638,7 +661,7 @@ func main() {
} }
if len(InviteUserIDs) == 0 { if len(InviteUserIDs) == 0 {
log.ZWarn(st.Ctx, "InviteUserIDs is empty", nil, "groupID", groupID) // log.ZWarn(st.Ctx, "InviteUserIDs is empty", nil, "groupID", groupID)
continue continue
} }

View File

@ -0,0 +1,19 @@
# Stress Test
## Usage
You need set `TestTargetUserList` and `DefaultGroupID` variables.
### Build
```bash
go build -o test/stress-test/stress-test test/stress-test/main.go
```
### Excute
```bash
tools/stress-test/stress-test -c config/
```

View File

@ -1,25 +0,0 @@
# Stress Test
## Usage
You need set `TestTargetUserList` and `DefaultGroupID` variables.
### Build
```bash
go build -o _output/bin/tools/linux/amd64/stress-test tools/stress-test/main.go
# or
go build -o tools/stress-test/stress-test tools/stress-test/main.go
```
### Excute
```bash
_output/bin/tools/linux/amd64/stress-test -c config/
#or
tools/stress-test/stress-test -c config/
```