Cody Dunn
Cody Dunn

Reputation: 11

Quarkus with Hibernate Reactive and Kafka bad performance

We have a quarkus application that reads messages from a kafka topic, does minor process validations (but some involve call to database), and writes in a different topic. We're using a imperative and synchrnous approach and read that to achieve better performance we should use functional and assynchrounous code.

But after refactoring, and now using Hibernate Reactive and Mutiny. We got really bad performance comparing to the one that we already have.

Consumer/Producer

@ApplicationScoped
public class TransactionsConsumer {
  private static final String ACKNOWLEDGE_RECEIVED = "Acknowledge received";
  @Inject
  TransactionService transactionService;

  Logger logger = LoggerFactory.getLogger(TransactionsConsumer.class);

  @Incoming("requestsPayments")
  @Outgoing("acks")
  public Uni<Message<ResponseVO>> savePaymentsReactive(Message<Transaction> transactionMessage) {
    transactionMessage.ack();

    return transactionService.processEvent(transactionMessage).onItem()
        .invoke(response -> logger.info(ACKNOWLEDGE_RECEIVED));
  }
}

This is how we write/read from DB:

    private Uni<Account> findAccountById(Long id) {
        return sessionFactory.withTransaction(session -> session.find(Account.class, id));
    }


    public Uni<Account> storeAccount(Account account) {
        return sessionFactory.withTransaction(session -> session.persist(account))
                .onItem().transform(ignored -> account);
    }

    public Uni<Account> updateAccount(Account account) {
        return sessionFactory.withTransaction(session -> session.merge(account))
                .onItem().transform(ignored -> account);
    }

Can someone help? We read a lot about the good performance of this approach, but we're getting really bad results with it comparing with the traditional approach.

We were expecting an amazing performance.

Upvotes: 1

Views: 363

Answers (1)

Timm
Timm

Reputation: 139

My guess is that you are not using reactive transactions with reactive approach, is it correct? https://es.quarkus.io/blog/reactive-crud-performance-case-study/

Upvotes: 0

Related Questions