在 c++ 中定期处理/发送数据
我正在用 C++ 处理文件中的行。
line1
line2
line3...
我从每一行构造一个 C++ 对象并将其放入队列中。 定期调度这些对象的最佳方法是什么?例如,每秒调度 100 个对象等?
编辑: 对象不必在间隔中均匀分布。只要我每秒发送 100 个对象,我就可以立即发送它们,然后等待第二秒结束。
I am processing lines from a file in C++.
line1
line2
line3...
From each line I construct a C++ object and put it in a queue.
What's the best way to dispatch these objects at regular intervals. For example, dispatch 100 objects per second etc?
Edit:
Objects don't have to be spaced evenly in the interval. As long as I send 100 objects per second, I can just send them immediately, then wait for the end of the second.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将逻辑编码到队列中。您的队列上有某种追加方法和 pop_front 方法。嗯... pop_front 方法可以更聪明一点。它可以限制工作的流失,这样它就不会发生得太快。
如有必要,您的工作人员可以告诉队列他们完成工作的速度,而不是他们开始工作的速度。
Code the logic into your queue. You have some sort of append method on your queue and a pop_front method. Well... The pop_front method can just be a bit smarter. It can throttle the passing out of work so it doesn't happen too quickly.
If necessary, your workers can tell the queue how quickly they're completing work as opposed to how quickly they're starting to do the work.