messaginghub / pooled-jms

A JMS Connection pool for messaging applications supporting JMS 1.1 and 2.0 and Jakarta JMS clients
Apache License 2.0
50 stars 24 forks source link

Question: is it icorrect that one session per message in an XA transaction is opened? #36

Closed turing85 closed 7 months ago

turing85 commented 7 months ago

Hello!

This is no(t yet an) issue, but more of a question.

Technical setup

We are using:

to write multiple messages to a queue within an XA transaction. Our backing messaging system is an ActiveMQ Artemis. As driver, we use

Observed behaviour

We had an issue where the pool started to block after 500 messages have been sent in a singular XA transaction. We were able to prevent this issue by setting quarkus.pooled-jms.max-sessions-per-connection (which defaults to 500) to -1 (which is then used to configure the maxSessionsPerConnection on the JmsPoolConnectionFactory here (github.com)).

This indicates that the pool is opening a separate session per message sent in the XA transaction.

Reproducer

We wrote a reproducer which can be found here (github.com). We can execute

./mvnw clean quarkus:dev

to start the reproducer. It will write 1000 messages to the queue on application startup.


Note

To run the reproducer:

is needed.


Questions

tabish121 commented 7 months ago

This is not something that the JMS pool controls so there isn't much that can be done from this level. I'd recommend contacting the Quarkus support channels for help. The pool simply opens a session when asked and does not open a session itself for sending messages.

turing85 commented 7 months ago

What about the other question wrt. maxSessionsPerConnection?

tabish121 commented 7 months ago

You basically already answered that for yourself. Allowing unlimited growth in the sessions leads to unlimited growth in memory consumption and likely eventual performance issues. The solution is to figure out why the orchestrating software is doing this. The pool, when asked to create a session, will create a session until the limit is hit. The other thing to look into is why those sessions aren't being closed by the software that asked for them, is it leaking sessions?

turing85 commented 7 months ago

I don't think the sessions can be closed as long as the XA-transaction is not committed. I can see in the narayana logs that the sessions are closed when the transaction is committed.

Wrt. the orchestration... camel says "we are just calling spring". Spring says "we are just calling the pool". So... yeah...

tabish121 commented 7 months ago

The question would be why are messages piling up in a single transaction, that's not something the pool has control over, nor does it control who can call it to create a session. The source is open, you are free to look at the implementation so see how things work in this area and how simple they are in terms of what the pool does here.