- 将初始化连接池的并发方式改为waitgroup控制的goroutine池 - 调整文件处理时的channel缓冲区大小从100增加到200 - 移除不必要的sync.WaitGroup变量声明 - 修改进度计算逻辑,确保上传完成时进度显示为100% - 添加对processLines函数的功能注释 - 优化上下文取消时的资源清理流程,及时关闭channel
This commit is contained in:
+19
-10
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -28,17 +29,25 @@ func init() {
|
||||
|
||||
// InitConn 创建连接池
|
||||
func InitConn() {
|
||||
for i := 0; i < 200; i++ {
|
||||
resp, err := httpClient.Get(config.APPConfig.Url + "/api/test")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
io.Copy(io.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
}()
|
||||
wg := &sync.WaitGroup{}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
wg.Go(func() {
|
||||
for i := 0; i < 50; i++ {
|
||||
resp, err := httpClient.Get(config.APPConfig.Url + "/api/test")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
io.Copy(io.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
}()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func UploadDataToServer(ctx context.Context, data string) error {
|
||||
|
||||
Reference in New Issue
Block a user