2

我正在使用 Gpars 线程池运行一组任务。任务执行时间变化很大,从几秒到 20 分钟不等。(这些是黄瓜功能文件 FWIW。)

幸运的是,features列表中的最后一个任务运行时间最长,所以当所有其他线程都完成时,整个进程会在那里执行 runtest('australian_government_rebate.feature') 25 分钟。

这意味着多线程没有兑现它的承诺。单线程测试需要 65 分钟才能运行,多线程测试需要 48 分钟。我希望30分钟或更长时间。

我的解决方案是按以前的执行时间对功能文件进行排序:

features = ...
features.sort { a, b -> b.executionTime() <=> a.executionTime() }
GParsPool.withPool(noOfCores) {
    features.eachParallel { feature ->
        runtest(feature)
    }
}

我的问题是:我可以保证这些功能将按照它们出现的顺序呈现给 GParsPoolfeatures吗?

4

2 回答 2

2

For cases like this one I'd recommend using dataflow tasks started from within a sequential for loop on a sorted collection of "features", instead of parallel collections:

PGroup group = ...
for(f in features) group.task {runtest(it)}

This would guarantee the startup order that you intend.

于 2015-05-02T05:11:14.777 回答
0

保证?不,但极有可能。我认为实际上看到你的方法是一个很好的方法,如果你的执行时间相差那么大。

于 2015-05-01T05:39:52.160 回答