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 is wrong on Worker API abilities.
Gradle's documentation is vague on this, but I asked and got the answer that Worker API really allows us to run several tasks in parallel in the same project.
This is a working example, with tasks of different classes:
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')
Assuming you have multi-core CPU or set gradle.workers.max
property, tasks sleep5
and sleep10
run in parallel.
But, on your actual case, it is still not feasible.
Worker API should be used from task implementation, and GatlingRunTask is not using it.
You or plugin author have to rewrite task implementation to use Worker API inside.
Like you said, Gradle Worker API is not really applicable in your case because it enables parallel processing, but in the context of a single Task, as the documentation states:
The Worker API provides the ability to break up the execution of a task action into discrete units of work and then to execute that work concurrently and asynchronously.
In order to make different tasks run in parallel, you could maybe use Parallel execution feature. But note that you can run tasks in parallel only if when they belong to different sub-projects (of a same multi-project build):
Most builds consist of more than one project and some of those projects are usually independent of one another. Yet Gradle will only run one task at a time by default, regardless of the project structure (this will be improved soon). By using the --parallel switch, you can force Gradle to execute tasks in parallel as long as those tasks are in different projects.
If your build script is used "only" as a launcher for Gatlin load tests, then maybe you can implement your build script as a multi-projects build, with one sub-project per target environment to test; then you could enable the --parallel
option to execute the load test tasks in parallel.