Compare commits

..

1 Commits

6 changed files with 34 additions and 70 deletions

View File

@ -1,19 +0,0 @@
# 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

@ -1,19 +0,0 @@
# 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

@ -337,7 +337,7 @@ func SetVersion(coll *mongo.Collection, key string, version int) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
option := options.Update().SetUpsert(true)
filter := bson.M{"key": key}
filter := bson.M{"key": key, "value": strconv.Itoa(version)}
update := bson.M{"$set": bson.M{"key": key, "value": strconv.Itoa(version)}}
return mongoutil.UpdateOne(ctx, coll, filter, update, false, option)
}

View File

@ -56,7 +56,6 @@ var (
const (
MaxUser = 100000
Max1kUser = 1000
Max100KGroup = 100
Max999Group = 1000
MaxInviteUserLimit = 999
@ -162,7 +161,7 @@ func (st *StressTest) PostRequest(ctx context.Context, url string, reqbody any)
if baseResp.ErrCode != 0 {
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
}
@ -531,20 +530,9 @@ func main() {
// Create 100K groups
st.Wg.Add(1)
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 func() {
st.Mutex.Lock()
st.Create100kGroupCounter++
st.Mutex.Unlock()
}()
groupID := fmt.Sprintf("v2_StressTest_Group_100K_%d", idx)
@ -554,7 +542,7 @@ func main() {
// continue
}
for i := 0; i <= MaxUser/MaxInviteUserLimit; i++ {
for i := 0; i < MaxUser/MaxInviteUserLimit; i++ {
InviteUserIDs := make([]string, 0)
// ensure TargetUserList is in group
InviteUserIDs = append(InviteUserIDs, TestTargetUserList...)
@ -568,7 +556,7 @@ func main() {
}
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
}
@ -579,7 +567,7 @@ func main() {
}
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
}
@ -614,20 +602,9 @@ func main() {
// Create 999 groups
st.Wg.Add(1)
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 func() {
st.Mutex.Lock()
st.Create999GroupCounter++
st.Mutex.Unlock()
}()
groupID := fmt.Sprintf("v2_StressTest_Group_1K_%d", idx)
@ -636,13 +613,13 @@ func main() {
log.ZError(st.Ctx, "Create group failed.", err)
// continue
}
for i := 0; i <= Max1kUser/MaxInviteUserLimit; i++ {
for i := 0; i < MaxUser/MaxInviteUserLimit; i++ {
InviteUserIDs := make([]string, 0)
// ensure TargetUserList is in group
InviteUserIDs = append(InviteUserIDs, TestTargetUserList...)
startIdx := max(i*MaxInviteUserLimit, 1)
endIdx := min((i+1)*MaxInviteUserLimit, Max1kUser)
endIdx := min((i+1)*MaxInviteUserLimit, MaxUser)
for j := startIdx; j < endIdx; j++ {
userCreatedID := fmt.Sprintf("v2_StressTest_User_%d", j)
@ -650,7 +627,7 @@ func main() {
}
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
}
@ -661,7 +638,7 @@ func main() {
}
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
}

View File

@ -0,0 +1,25 @@
# 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/
```