I have an issue where sometimes I get this error:
[io.ver.cor.imp.BlockedThreadChecker] (vertx-blocked-thread-checker) Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 3084 ms, time limit is 2000 ms: io.vertx.core.VertxException: Thread blocked
I noticed that one of the most time-consuming tasks is my dynamoDB queries. My current implementation to query is like this:
DynamoDbClient dynamoDBSync;
public Uni<Fruit> getFruit(String name) {
return Uni.createFrom()
.item(dynamoDBSync.getItem(getRequest(name)).item());
}
public Uni<Void> transactionalWrite(TransactWriteItemsRequest transactWriteItemsRequest) {
return Uni.createFrom()
.item(dynamoDBSync.transactWriteItems(transactWriteItemsRequest))
.replaceWithVoid();
}
Then I notice that there are another form of DynamoDB client that is asynchronous from this documentation. So In my case the implementation would look like something like this
DynamoDbAsyncClient dynamoDBASync;
public Uni<Fruit> getFruit(String name) {
return Uni.createFrom()
.completionStage(dynamoDBASync.getItem(getRequest(name)))
.onItem().transform(resp -> Fruit.from(resp.item()));
}
public Uni<Void> transactionalWrite(TransactWriteItemsRequest transactWriteItemsRequest) {
return Uni.createFrom()
.completionStage(dynamoDBASync.transactWriteItems(transactWriteItemsRequest))
.replaceWithVoid();
}
However, after further research, it seems that the DynamoDbAsyncClient
might not help at all with my case because the current implementation should already be Asynchronous.
The question is, is it correct moving to DynamoDbAsyncClient
or should I search for another way to unblock my threads?
Edit: adding more dynamoDB implementation examples
I'm not sure how your current solution is Async if you're getting exceptions from a blocking thread. DynamoDB Async client uses non blocking IO and returns a future, so should not block threads.
However, your example uses a GetItem and no GetItem should take 2000ms. My suggestion would be to first address your client timeouts to ensure you fail fast and retry. There's no reason you should wait 2000ms on something that should return in less than 200ms.