1234567891011121314151617181920212223242526272829303132 |
- package user
- import (
- "log"
- "sfis/service"
- "strconv"
- "sync"
- "github.com/gin-gonic/gin"
- )
- //并发测试
- func concurrentTest(c *gin.Context) {
- count, _ := strconv.Atoi(c.PostForm("count"))
- appid := c.PostForm("appid")
- productId, _ := strconv.Atoi(c.PostForm("productId"))
- var wg = sync.WaitGroup{}
- pool := make(chan bool, 100000)
- for i := 0; i < count; i++ {
- wg.Add(1)
- pool <- true
- log.Println(i)
- go func(i int) {
- defer func() {
- wg.Done()
- <-pool
- }()
- service.GetConcurrentData(appid, productId, c)
- }(i)
- }
- wg.Wait()
- }
|