简体   繁体   English

JMS事务-开销-如有可能,如何避免呢?

[英]JMS Transactions - overhead - how to avoid it, if possible?

In our application, we receive messages from JMS Topic. 在我们的应用程序中,我们从JMS Topic接收消息。

  • First I want to know if the JMS follows FIFO policy. 首先,我想知道JMS是否遵循FIFO策略。 If not, how can an application decide which is the latest message? 如果不是,应用程序如何确定最新消息?

We consume messages ( durable subscriber and JMS session is transacted, lot of overhead ) because messages are retained at the JMS server until the transaction commits/ends. 我们消耗消息(持久的订户和JMS会话被处理,开销很大),因为消息保留在JMS服务器上,直到事务提交/结束。 The reason we specified transaction is 我们指定交易的原因是

  • We are using a caching ( hibernate ) technology and a transaction to use it. 我们正在使用缓存(休眠)技术和使用它的事务。 So, we are using two transactions, one is JMS tx and one is caching-technology tx. 因此,我们正在使用两个事务,一个是JMS tx,一个是缓存技术tx。 When we consume the message and we want all or nothing to happen until the message is committed and acknowledgement is sent to JMS. 当我们使用该消息时,我们希望在消息提交并将确认发送到JMS之前不发生任何事情。 caching tx will commit first and then immediately JMS tx will commit next and message is acknowledged, otherwise, both the tx's will be rolledback and the message will be replayed. 缓存tx将首先提交,然后立即JMS tx将再次提交并确认消息,否则,两个tx都将回滚并重播该消息。 We are currently replaying the messages 3 times, and then if the exception still occurs, then we are sending the message to non-processable queue. 当前,我们将消息重播3次,然后,如果仍然发生异常,则将消息发送到不可处理的队列。

  • This works fine until lot of messages come at the same time to the JMS and needs to be processed by our system at the same time. 在许多消息同时发送到JMS并需要由我们的系统同时处理之前,这种方法可以正常工作。

  • I would like to know what did you do when you encountered such scenario. 我想知道您遇到这种情况时做了什么。 Because, maintaining a durable subscription and a transacted session is a significant overhead over the JMS server and would drain the performance of the server. 因为,维护持久预订和事务处理会话是JMS服务器上的一大笔开销,并且会耗尽服务器的性能。

Message ordering for topics is not specified in the JMS spec so the official answer to that is that it is JMS implementation specific. JMS规范中未指定主题的消息排序,因此对此的官方答案是特定于JMS实现。 Having said that, unless specifically overridden to do something else, I imagine that messages would be delivered in FIFO order. 话虽这么说,除非特别重写以执行其他操作,否则我认为消息将以FIFO顺序传递。

For the transactions, I suggest you look into implementing two phase commit XA transactions so you do not need two separate transactions. 对于事务,建议您考虑实施两个阶段的提交XA事务,因此您不需要两个单独的事务。 If your cache implementation supports XA, the JMS and Cache(and DB) transactions would be one and the same. 如果您的缓存实现支持XA,则JMS和Cache(和DB)事务将是相同的。

Generally I have found that for these types of transacted messages, if you must used transacted messages, the best way to squeeze performance out is to process as many messages in one transaction as you can: 通常,我发现对于这些类型的事务处理消息,如果必须使用事务处理消息,则降低性能的最佳方法是在一个事务中处理尽可能多的消息:

  1. Start a transaction 开始交易
  2. Retrieve n messages (or all of them until there is a timeout) 检索n条消息(或所有消息,直到出现超时)
  3. Process the messages 处理消息
  4. Commit the transaction. 提交交易。
  5. Go To 1. 转到1。

Another way to kill 2 birds with 1 stone is to skip the processing of the message during retrieval and simply write the retrieved messages to a transacted data store. 用一颗石头杀死两只鸟的另一种方法是在检索过程中跳过对消息的处理,而只是将检索到的消息写入事务处理的数据存储中。 Then have a separate thread retrieve the messages from the store (in timestamp order) and process them (separate thread - = separate transaction). 然后,有一个单独的线程(按时间戳顺序)从存储中检索消息并进行处理(单独的线程-=单独的事务)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM