concurrentTest.go 558 B

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