Skip to content

Commit 3bbe027

Browse files
committed
ESQL: Small speed up in MultiClusterSpecIT
Speeds up `MultiClusterSpecIT` a tiny bit by running things like index creation in parallel in both clusters. Drops the runtime of a single test from 33 seconds to 27.5 for me locally. We can certainly speed this up more by parallelizing index creation and/or creating only the index we need.
1 parent 5e7159e commit 3bbe027

File tree

1 file changed

+42
-4
lines changed
  • x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq

1 file changed

+42
-4
lines changed

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.Version;
1616
import org.elasticsearch.client.Request;
1717
import org.elasticsearch.client.Response;
18+
import org.elasticsearch.client.ResponseListener;
1819
import org.elasticsearch.client.RestClient;
1920
import org.elasticsearch.common.settings.Settings;
2021
import org.elasticsearch.core.IOUtils;
@@ -40,6 +41,8 @@
4041
import java.util.Locale;
4142
import java.util.Optional;
4243
import java.util.Set;
44+
import java.util.concurrent.CompletableFuture;
45+
import java.util.concurrent.ExecutionException;
4346
import java.util.regex.Pattern;
4447
import java.util.stream.Collectors;
4548

@@ -248,10 +251,7 @@ static RestClient twoClients(RestClient localClient, RestClient remoteClient) th
248251
return bulkClient.performRequest(request);
249252
} else {
250253
Request[] clones = cloneRequests(request, 2);
251-
Response resp1 = remoteClient.performRequest(clones[0]);
252-
Response resp2 = localClient.performRequest(clones[1]);
253-
assertEquals(resp1.getStatusLine().getStatusCode(), resp2.getStatusLine().getStatusCode());
254-
return resp2;
254+
return runInParallel(localClient, remoteClient, clones);
255255
}
256256
});
257257
doAnswer(invocation -> {
@@ -286,6 +286,44 @@ static Request[] cloneRequests(Request orig, int numClones) throws IOException {
286286
return clones;
287287
}
288288

289+
/**
290+
* Run {@link #cloneRequests cloned} requests in parallel.
291+
*/
292+
static Response runInParallel(RestClient localClient, RestClient remoteClient, Request[] clones) throws Throwable {
293+
CompletableFuture<Response> remoteResponse = new CompletableFuture<>();
294+
CompletableFuture<Response> localResponse = new CompletableFuture<>();
295+
remoteClient.performRequestAsync(clones[0], new ResponseListener() {
296+
@Override
297+
public void onSuccess(Response response) {
298+
remoteResponse.complete(response);
299+
}
300+
301+
@Override
302+
public void onFailure(Exception exception) {
303+
remoteResponse.completeExceptionally(exception);
304+
}
305+
});
306+
localClient.performRequestAsync(clones[1], new ResponseListener() {
307+
@Override
308+
public void onSuccess(Response response) {
309+
localResponse.complete(response);
310+
}
311+
312+
@Override
313+
public void onFailure(Exception exception) {
314+
localResponse.completeExceptionally(exception);
315+
}
316+
});
317+
try {
318+
Response remote = remoteResponse.get();
319+
Response local = localResponse.get();
320+
assertEquals(remote.getStatusLine().getStatusCode(), local.getStatusLine().getStatusCode());
321+
return local;
322+
} catch (ExecutionException e) {
323+
throw e.getCause();
324+
}
325+
}
326+
289327
/**
290328
* Convert FROM employees ... => FROM *:employees,employees
291329
*/

0 commit comments

Comments
 (0)