dongsuo9982 2015-08-09 15:18
浏览 165

如何计算每秒的传出请求数?

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:

  1. 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?

  2. 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.

  3. 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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)