I would like to run two gatlingRun
tasks (created by gatling gradle plugin) with different parameters (on 2 environments) at the same time.
I know that new gradle provides Worker API, but this seems to be not applicable in this case.
I would like to run two gatlingRun
tasks (created by gatling gradle plugin) with different parameters (on 2 environments) at the same time.
I know that new gradle provides Worker API, but this seems to be not applicable in this case.
@M.Ricciuti 在 Worker API 能力上是错误的。
Gradle 的文档对此含糊其辞,但我询问并得到答案,Worker API 确实允许我们在同一个项目中并行运行多个任务。
这是一个工作示例,具有不同类别的任务:
import javax.inject.Inject
class Sleeping5 extends DefaultTask {
static class Sleeper5 implements Runnable {
String name
@Inject
public Sleeper5(String name) {
this.@name = name
}
@Override
void run() {
(1..50).each { int i ->
Thread.sleep(1000)
println "$name: $i"
}
}
}
private final WorkerExecutor workerExecutor
@Inject
public Sleeping5(WorkerExecutor workerExecutor) {
this.workerExecutor = workerExecutor
}
@TaskAction
void sleep() {
workerExecutor.submit(Sleeper5, new Action<WorkerConfiguration>() {
@Override
void execute(WorkerConfiguration config) {
config.isolationMode = IsolationMode.NONE
config.displayName = name
config.params = [name]
}
})
}
}
class Sleeping10 extends DefaultTask {
static class Sleeper10 implements Runnable {
String name
@Inject
public Sleeper10(String name) {
this.@name = name
}
@Override
void run() {
(1..70).each { int i ->
Thread.sleep(1000)
println "$name: $i"
}
}
}
private final WorkerExecutor workerExecutor
@Inject
public Sleeping10(WorkerExecutor workerExecutor) {
this.workerExecutor = workerExecutor
}
@TaskAction
void sleep() {
workerExecutor.submit(Sleeper10, new Action<WorkerConfiguration>() {
@Override
void execute(WorkerConfiguration config) {
config.isolationMode = IsolationMode.NONE
config.displayName = name
config.params = [name]
}
})
}
}
task(type: Sleeping5, 'sleep5')
task(type: Sleeping10, 'sleep10')
假设您有多核 CPU 或设置gradle.workers.max
属性,任务sleep5
和sleep10
并行运行。
但是,根据您的实际情况,它仍然不可行。
Worker API 应该从任务实现中使用,而GatlingRunTask没有使用它。
您或插件作者必须重写任务实现才能在内部使用 Worker API。
正如您所说,Gradle Worker API并不真正适用于您的情况,因为它支持并行处理,但在单个Task的上下文中,如文档所述:
Worker API 提供了将任务操作的执行分解为离散的工作单元然后并发和异步执行该工作的能力。
为了使不同的任务并行运行,您可以使用并行执行功能。但请注意,只有当它们属于不同的子项目(相同的多项目构建)时,您才能并行运行任务:
大多数构建包含多个项目,其中一些项目通常相互独立。然而,无论项目结构如何,Gradle 默认一次只运行一个任务(这将很快得到改进)。通过使用 --parallel 开关,您可以强制 Gradle 并行执行任务,只要这些任务位于不同的项目中。
如果您的构建脚本“仅”用作 Gatlin 负载测试的启动器,那么也许您可以将构建脚本实现为多项目构建,每个目标环境有一个子项目进行测试;然后您可以启用--parallel
选项以并行执行负载测试任务。