To send 10000 requests to a website in 1 second, we can take advantage of Go's concurrency features. Specifically, we will use goroutines and channels to make concurrent HTTP requests.
Here's an example code that demonstrates this approach:
main.go1178 chars59 lines
In this code, we create a http.Client
with a custom transport that allows multiple idle connections and limits the maximum number of connections per host. We also create a sync.WaitGroup
to wait for all requests to complete.
We then loop over the number of requests we want to send, and call go func()
to create a new goroutine for each request. In each goroutine, we create a new HTTP request and send it using the http.Client
.
Once all requests are sent, we wait for them to complete using the sync.WaitGroup
.
Finally, we calculate the duration of the entire operation and print some statistics, such as the total number of requests sent and the requests per second.
gistlibby LogSnag