测试并发/并行执行
我目前正在为需求驱动的工作流程编写一个小型框架。 API 现在已经稳定,我正在努力改进测试。很容易证明计算是正确的(这是一个好的开始),但是,该框架的主要兴趣是并行启动子任务(在需要和可能时)。
有没有一种方法可以自动测试两段不同的代码是否以并行/并发的方式运行?我不喜欢依赖执行时间(加速)测量。
该框架是用 scala 编写的,并且很大程度上依赖于 Akka Futures。
编辑:
这是一个示例:
val foo = step {
//... defines an arbitrary task
}
// Runs 5 times the code inside step foo
val foos = repeat( 5 )( foo )
我想确保 foo
中的代码并行执行 5 次。
I'm currently writing a small framework for demand-driven workflows. The API is now stable and I am working on improving tests. It's easy to show that computations are correct (which is a good start), however, the main interest of the framework is to launch subtasks in parallel (when needed and possible).
Is there a way to test automatically that two different pieces of code do run in a parallel/concurrent fashion ? I prefer not relying on execution time (speed-up) measurments.
The framework is written in scala, and relies a lot on Akka Futures.
EDIT:
Here is an example:
val foo = step {
//... defines an arbitrary task
}
// Runs 5 times the code inside step foo
val foos = repeat( 5 )( foo )
I would like to be sure that the code inside foo
is executed 5 times in parallel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有找到一种方法可以在不更改任务的情况下执行此操作(即,当您需要测试两个特定任务并行运行时)。但如果你可以更改任务,只需向系统添加一个参与者即可。让每个任务在开始或结束工作时向该参与者发送消息。如果参与者连续收到两条
Starting
消息,则任务应该并行运行(或至少在不同的线程中)。I don't see a way to do this without changing tasks (i.e. when you need to test that two specific tasks run in parallel). But if you can change the tasks, just add an actor to the system. Make every task send messages to this actor when starting or ending work. If the actor receives two
Starting
messages in a row, the tasks should be running in parallel (or at least in different threads).这个测试对我来说没有任何意义。在少于 5 个核心的计算机上,您无法获得 5 的并行度。看起来您正在测试 Akka,我们已经在这样做了,所以只需放松并测试调度程序设置以验证它何时运行将具有所需的性能影响。
希望有帮助,
干杯,
√
This test does not make any sense to me. On a computer with less than 5 cores you cannot get a parallelism of 5. It seems like you are testing Akka, which we are already doing, so just relax and test the dispatcher settings to verify that when it will run it will have the desired effect.
Hope that helps,
Cheers,
√