Skip to content

Commit

Permalink
Addressing bulk ingester stuck threads (#870) (#872)
Browse files Browse the repository at this point in the history
* signaling after successfully adding

* stress test unit test

* removed memory calc

Co-authored-by: Laura Trotta <[email protected]>
  • Loading branch information
github-actions[bot] and l-trotta authored Aug 26, 2024
1 parent f660a7e commit c8c062e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ public void add(BulkOperation operation, Context context) {
if (!canAddOperation()) {
flush();
}
else {
addCondition.signalIfReady();
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem;
import co.elastic.clients.elasticsearch.core.bulk.OperationType;
import co.elastic.clients.elasticsearch.end_to_end.RequestTest;
import co.elastic.clients.elasticsearch.indices.IndicesStatsResponse;
import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.json.SimpleJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
Expand Down Expand Up @@ -146,6 +147,50 @@ private void multiThreadTest(int maxOperations, int maxRequests, int numThreads,
assertEquals(expectedRequests, transport.requestsStarted.get());
}

@Test
public void multiThreadStressTest() throws InterruptedException, IOException {

String index = "bulk-ingester-stress-test";
ElasticsearchClient client = ElasticsearchTestServer.global().client();

// DISCLAIMER: this configuration is highly inefficient and only used here to showcase an extreme
// situation where the number of adding threads greatly exceeds the number of concurrent requests
// handled by the ingester. It's strongly recommended to always tweak maxConcurrentRequests accordingly.
BulkIngester<?> ingester = BulkIngester.of(b -> b
.client(client)
.globalSettings(s -> s.index(index))
.flushInterval(5, TimeUnit.SECONDS)
);

RequestTest.AppData appData = new RequestTest.AppData();
appData.setIntValue(42);
appData.setMsg("Some message");

ExecutorService executor = Executors.newFixedThreadPool(50);

for (int i = 0; i < 100000; i++) {
int ii = i;
Runnable thread = () -> {
int finalI = ii;
ingester.add(_1 -> _1
.create(_2 -> _2
.id(String.valueOf(finalI))
.document(appData)
));
};
executor.submit(thread);
}

executor.awaitTermination(10,TimeUnit.SECONDS);
ingester.close();

client.indices().refresh();

IndicesStatsResponse indexStats = client.indices().stats(g -> g.index(index));

assertTrue(indexStats.indices().get(index).primaries().docs().count()==100000);
}

@Test
public void sizeLimitTest() throws Exception {
TestTransport transport = new TestTransport();
Expand Down

0 comments on commit c8c062e

Please sign in to comment.