refactor(usockets): reorganize lib directory structure for multi-platform support
- Organize lib directory by platform: windows/, macos-arm64/, macos-x64/, linux/ - Update build.sh to support unified build process for Windows/macOS/Linux - Compile libuv + uSockets and merge into complete static library - Update usockets.v conditional compilation to point to new directory structure - Optimize benchmark tests with connection pooling for high concurrency testing - Clean up unused legacy library files Performance test results (Windows): - 1000 concurrent, 1M requests: 35,223 req/s - 10000 concurrent, 1M requests: 26,884 req/s
This commit is contained in:
@@ -448,21 +448,49 @@ func checkKeepAlive(client *http.Client) bool {
|
||||
|
||||
func checkThroughput(client *http.Client) float64 {
|
||||
start := time.Now()
|
||||
success := 0
|
||||
requests := 200
|
||||
concurrency := 1000
|
||||
totalRequests := 1000000
|
||||
requestsPerWorker := totalRequests / concurrency
|
||||
|
||||
for i := 0; i < requests; i++ {
|
||||
resp, err := client.Get(baseURL + "/health")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
io.Copy(io.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode == 200 {
|
||||
success++
|
||||
}
|
||||
// 创建共享的 Transport,启用连接池复用
|
||||
transport := &http.Transport{
|
||||
MaxIdleConns: concurrency,
|
||||
MaxIdleConnsPerHost: concurrency,
|
||||
IdleConnTimeout: 30 * time.Second,
|
||||
DisableKeepAlives: false,
|
||||
}
|
||||
|
||||
results := make(chan int, concurrency)
|
||||
|
||||
for i := 0; i < concurrency; i++ {
|
||||
go func() {
|
||||
localSuccess := 0
|
||||
// 每个 goroutine 使用独立 Client,但共享 Transport(连接池)
|
||||
localClient := &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
Transport: transport,
|
||||
}
|
||||
for j := 0; j < requestsPerWorker; j++ {
|
||||
resp, err := localClient.Get(baseURL + "/health")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
io.Copy(io.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode == 200 {
|
||||
localSuccess++
|
||||
}
|
||||
}
|
||||
results <- localSuccess
|
||||
}()
|
||||
}
|
||||
|
||||
success := 0
|
||||
for i := 0; i < concurrency; i++ {
|
||||
success += <-results
|
||||
}
|
||||
|
||||
elapsed := time.Since(start).Seconds()
|
||||
fmt.Printf("\n [并发: %d, 总请求: %d, 成功: %d, 耗时: %.2fs]\n ", concurrency, totalRequests, success, elapsed)
|
||||
return float64(success) / elapsed
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user