title: how to run 10000 goroutines in parallel where each routine calls an api?
body: <p>I have the following code, where I am trying to call an api 10000 times but i am getting errors:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
  
      "net/http"
      "runtime"
      "sync"
      "time"
  )
  
  func main() {
  
      nCPU := runtime.NumCPU()
      runtime.GOMAXPROCS(nCPU)
  
      var wg sync.WaitGroup
      totalRequests := 100000
      wg.Add(totalRequests)
  
      fmt.Println("Starting Go Routines")
  
      start := time.Now()
      total := 0
  
      for i := 0; i &lt; totalRequests; i++ {
  
          go func(current int) {
              defer wg.Done()
  
              startFunc := time.Now()
              _, err := http.Get("http://127.0.0.1:8080/event/list")
              // resp, err := http.Get("https://graph.facebook.com/v2.4/me" + "?fields=id%2Cname&amp;access_token=" + "CAACEdEose0cBAEpQvcsvVMQu5oZCyyDjcEPQi9yCdiXimm4F0AYexGHPZAJHgpyrFOJN5X1VMcicNJjlkaCquUqHMZAfRrtxx6K9cRIROrA0OmbqAqCcg8ZA3qJZCHCl68I1n4LtFb5qxPcotlP5ne5PBakK0OUa7sc6FAOWwByOnFtNZBpIe8XDeM4YFa33sDfftVUpZCoBgZDZD")
  
              if err != nil {
                  fmt.Println(err)
              }
              // defer resp.Body.Close()
              elapsedFunc := time.Since(startFunc)
              fmt.Println("The request (", current, ") took", elapsedFunc, "No of requests completed", total)
              total++
  
          }(i)
  
      }
  
      wg.Wait()
      elapsed := time.Since(start)
      fmt.Println("\nThe total time with cores", elapsed)
      fmt.Println("\nTerminating Program")
  }
  </code></pre>
  
  <p>The errors I am getting:</p>
  
  <pre><code>Get http://127.0.0.1:8080/event/list: dial tcp 127.0.0.1:8080: socket: too many open files
  The request ( 5390 ) took 1.619876633s No of requests completed 2781
  Get http://127.0.0.1:8080/event/list: dial tcp 127.0.0.1:8080: socket: too many open files
  The request ( 7348 ) took 650.609825ms No of requests completed 1445
  </code></pre>