concurrentTest.go 597 B

12345678910111213141516171819202122232425262728293031323334
  1. package user
  2. import (
  3. "log"
  4. "sfis/model/response"
  5. "sfis/service"
  6. "strconv"
  7. "sync"
  8. "github.com/gin-gonic/gin"
  9. )
  10. //并发测试
  11. func concurrentTest(c *gin.Context) {
  12. count, _ := strconv.Atoi(c.PostForm("count"))
  13. appid := c.PostForm("appid")
  14. productId, _ := strconv.Atoi(c.PostForm("productId"))
  15. var wg = sync.WaitGroup{}
  16. pool := make(chan bool, 100000)
  17. for i := 0; i < count; i++ {
  18. wg.Add(1)
  19. pool <- true
  20. log.Println(i)
  21. go func(i int) {
  22. defer func() {
  23. wg.Done()
  24. <-pool
  25. }()
  26. service.GetConcurrentData(appid, productId, c)
  27. }(i)
  28. }
  29. wg.Wait()
  30. response.Ok(c)
  31. }