# stresstest-iserver-ios **Repository Path**: runui/stresstest-iserver-ios ## Basic Information - **Project Name**: stresstest-iserver-ios - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-01-03 - **Last Updated**: 2024-01-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Local Server Stress Testing environment for IOS > 用于搭建 IOS 本地 http 服务压力测试环境 ## Swift Side default address: `[ipv4] 0.0.0.0:9780` route: `/ping` request: ``` HTTP/1.1 200 OK content-type: text/plain; charset=utf-8 content-length: 5 connection: keep-alive date: Wed, 03 Jan 2024 13:47:02 GMT Hello ``` curl: `curl "http://172.1.1.1:9780/ping" -s -i` ## Golang Side default address: `[ipv4] 0.0.0.0:9870` route: `/` request: ``` HTTP/1.1 200 OK Date: Wed, 03 Jan 2024 13:46:37 GMT Content-Length: 18 Content-Type: text/plain; charset=utf-8 Hello golang http! ``` curl: `curl "http://172.1.1.1:9870/" -s -i` ## use golang code Stress Testing examples import ``` package main import ( "flag" "fmt" "strconv" "sync" "github.com/gin-gonic/gin" "github.com/google/uuid" ) func main() { fmt.Printf("// Stress Testing Start\n") // 构造测试结果实例 srt := NewStressRequestTesting() count, _ := strconv.ParseUint("10", 10, 64) // 请求次数 concurrent, _ := strconv.ParseUint("1000", 10, 64) // 并发数 // 测试资源链接 urlStr := "http://172.1.1.1:9780/ping?q=1" // 并发请求 srt.IsRunning = true wg := sync.WaitGroup{} for i := 0; i < int(concurrent); i++ { wg.Add(1) go func(_threadIndex int) { defer wg.Done() for i := 0; i < int(count); i++ { if !srt.IsRunning { return } srt.RequestTesting(urlStr + "&uuid=" + uuid.New().String()) } fmt.Printf("[StressTest] Task for test thread %d/%d end\n", _threadIndex, concurrent) }(i) } signals := make(chan bool) go func(signals chan bool) { wg.Wait() signals <- true }(signals) select { case <-signals: srt.IsRunning = false fmt.Println("[StressPhoto] take the initiative to cancel the task") } fmt.Println("result ", srt.Counting, "\n", gin.H{ "code": 1, "result": gin.H{ "successes": srt.Counting.Successes, "failures": srt.Counting.Failures, "time_ms": srt.Counting.TimeConsuming, "total": srt.Counting.TotalCount, "http_status_code_200": srt.Counting.HttpStatusCode_200, "http_status_code_not_200": srt.Counting.HttpStatusCode_not_200, }, "msg": srt.LoggerMsg, }) } ```