I'm writing a go program which will make thousands of http.Get
requests, concurrently, using goroutines. This will be a long running process and I am going to add an admin feature to it that will list certain stats about the process.
I'm trying to figure out a clean way to calculate the number of requests per second I'm making. I've come up with a few possible solutions:
Store a counter and have a timer that executes every few seconds that calculates the requests/second, then resets the counter. I'm worried about doing this in a thread safe way. If I use a mutex before accessing this counter, will I kill my performance?
Keep a list of timestamps for every request successfully made, then I can walk backward in the list for all timestamps within the time period I care about. I'm worried about this list growing but maybe I can use a circular buffer.
- Somehow keep a running moving average of my requests / sec?
What would be the best way for me to calculate the number of http.Get
requests I'm making per second in my Go program?