我们有一个使用第三方工具来管理连接池的独立Java应用程序,该应用程序在v6_client + v6_server设置中为我们工作了很长时间。
现在我们正在尝试从v6迁移到v9(是的,我们参加聚会很晚了.....),发现v9_client与v6_server的连接一直在中断,这意味着:
我们查看了v9_client(XAQCF)的可调参数的完整列表 https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.0.0/com.ibm.mq.ref.dev.doc/q111800_.html中的“专栏”中,仅列出了我们在v6_client中未使用的两个潜在新配置,即 SHARECONVALLOWED 和 PROVIDERVERSION 。不幸的是,两者都没有帮助我们。
只是想知道其他人是否也有类似的经验并且可以分享一些见解。我们尝试了v9_server + v9_client,但没有看到任何类似的问题,因此这也可能是我们最终的解决方案。
顺便说一句,WMQ托管在linux(RedHat)上,我们仅在客户端使用MQXAQueueConnectionFactory的产品(jms的ibm mq类)。
谢谢。
其他详细信息/更新。
[update-1]
-[playgrond设置]
v9_client jar:
javax.jms-api-2.0.jar
com.ibm.mq.allclient(-9.0.0.[1/5]).jar
v6_client jar: 除外,在v9_client jars中,在eclipse类路径中引入了以下jars
com.ibm.dhbcore-1.0.jar
com.ibm.mq.pcf-6.0.3.jar
com.ibm.mqjms-6.0.2.2.jar
com.ibm.mq-6.0.2.2.jar
com.ibm.mqetclient-6.0.2.2.jar
connector.jar
jta-1.1.jar
测试代码-单线程:
import javax.jms.*;
import com.ibm.mq.jms.*;
import com.ibm.msg.client.wmq.WMQConstants;
public class MQSeries_simpleAuditQ {
private static String queueManager = "QM.RCTQ.ALL.01";
private static String host = "localhost";
private static int port = 26005;
public static void main(String[] args) throws JMSException {
MQXAQueueConnectionFactory queueFactory= new MQXAQueueConnectionFactory();
System.out.println("\n\n\n*******************\nqueueFactory implementation version: " +
queueFactory.getClass().getPackage().getImplementationVersion() + "*****************\n\n\n");
queueFactory.setHostName(host);
queueFactory.setPort(port);
queueFactory.setQueueManager(queueManager);
queueFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
if (queueFactory.getClass().getPackage().getImplementationVersion().split("\\.")[0].equals("9")) {
queueFactory.setProviderVersion("6");
//queueFactory.setShareConvAllowed(WMQConstants.WMQ_SHARE_CONV_ALLOWED_YES);
}
XASession xaSession;
javax.jms.QueueConnection xaQueueConnection;
try {
// Obtain a QueueConnection
System.out.println("Creating Connection...");
xaQueueConnection = (QueueConnection)queueFactory.createXAConnection(" ", "");
xaQueueConnection.start();
for (int counter=0; counter<2; counter++) {
try {
xaSession = ((XAConnection)xaQueueConnection).createXASession();
xaSession.close();
} catch (Exception ex) {
System.out.println(ex);
}
}
System.out.println("Closing connection.... ");
xaQueueConnection.close();
} catch (Exception e) {
System.out.println("Error processing " + e.getMessage());
}
}
}
-[观察] v6_client仅创建并关闭一个套接字,而v9_client(均为9.0.0。[1/5]):
xaQueueConnection = (QueueConnection)queueFactory.createXAConnection(" ", "");
之后创建并关闭xaSession = ((XAConnection)xaQueueConnection).createXASession();
之后创建,并在xaSession.close();
之后关闭我天真希望套接字保持打开状态,直到xaQueueConnection.close()
。
[update-2]
对v9_server + v9_client使用queueFactory.setProviderVersion("9");
和queueFactory.setShareConvAllowed(WMQConstants.WMQ_SHARE_CONV_ALLOWED_YES);
,在v6_server + v9_client中看不到相同的常量套接字关闭问题,这是个好消息。
MCAUSER
通道的属性上的 [update-3] SVRCONN
。在v9_server上相同(与相同的v9_client连接时,不会出现相同的套接字关闭问题)。
display channel (SYSTEM.ADMIN.SVRCONN)
MCAUSER(mqm)
display channel (SYSTEM.AUTO.SVRCONN)
MCAUSER( )
display channel (SYSTEM.DEF.SVRCONN)
MCAUSER( )
[update-4]
我尝试将MCAUSER()设置为mqm
,然后从客户端使用(空白)和
mqm
,两者都可以创建连接,但是仍然看到相同的意外套接字关闭使用v9_client + v6_user。更新MCAUSER()之后,我总是添加refresh security
,然后重新启动qmgr。
在使用空白用户创建连接之前,我还尝试在eclipse中将系统变量设置为空白,这也没有帮助。
[update-5]
我们的讨论仅限于v9_client + v9_server。下面的异步测试代码使用有限数量的现有连接生成大量的xasession创建/关闭请求。使用SHARECNV(1)还会导致无法承受的高TIME_WAIT计数,但是使用大于1的SHARECNV(例如10)可能会带来额外的性能损失……
异步测试代码
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import javax.jms.*;
import com.ibm.mq.jms.*;
import com.ibm.msg.client.wmq.WMQConstants;
public class MQSeries_simpleAuditQ_Async_v9 {
private static String queueManager = "QM.ALPQ.ALL.01";
private static int port = 26010;
private static String host = "localhost";
private static int connCount = 20;
private static int amp = 100;
private static ExecutorService amplifier = Executors.newFixedThreadPool(amp);
public static void main(String[] args) throws JMSException {
MQXAQueueConnectionFactory queueFactory= new MQXAQueueConnectionFactory();
System.out.println("\n\n\n*******************\nqueueFactory implementation version: " +
queueFactory.getClass().getPackage().getImplementationVersion() + "*****************\n\n\n");
queueFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
if (queueFactory.getClass().getPackage().getImplementationVersion().split("\\.")[0].equals("9")) {
queueFactory.setProviderVersion("9");
queueFactory.setShareConvAllowed(WMQConstants.WMQ_SHARE_CONV_ALLOWED_YES);
}
queueFactory.setHostName(host);
queueFactory.setPort(port);
queueFactory.setQueueManager(queueManager);
//queueFactory.setChannel("");
ArrayList<QueueConnection> xaQueueConnections = new ArrayList<QueueConnection>();
try {
// Obtain a QueueConnection
System.out.println("Creating Connection...");
//System.setProperty("user.name", "mqm");
//System.out.println("system username: " + System.getProperty("user.name"));
for (int ct=0; ct<connCount; ct++) {
// xaQueueConnection instance of MQXAQueueConnection
QueueConnection xaQueueConnection = (QueueConnection)queueFactory.createXAConnection(" ", "");
xaQueueConnection.start();
xaQueueConnections.add(xaQueueConnection);
}
ArrayList<Double> totalElapsedTimeRecord = new ArrayList<Double>();
ArrayList<FutureTask<Double>> taskBuffer = new ArrayList<FutureTask<Double>>();
for (int loop=0; loop <= 10; loop++) {
try {
for (int i=0; i<amp; i++) {
int idx = (int)(Math.random()*((connCount)));
System.out.println("Using connection: " + idx);
FutureTask<Double> xaSessionPoker = new FutureTask<Double>(new XASessionPoker(xaQueueConnections.get(idx)));
amplifier.submit(xaSessionPoker);
taskBuffer.add(xaSessionPoker);
}
System.out.println("loop " + loop + " completed");
} catch (Exception ex) {
System.out.println(ex);
}
}
for (FutureTask<Double> xaSessionPoker : taskBuffer) {
totalElapsedTimeRecord.add(xaSessionPoker.get());
}
System.out.println("Average xaSession poking time: " + calcAverage(totalElapsedTimeRecord));
System.out.println("Closing connections.... ");
for (QueueConnection xaQueueConnection : xaQueueConnections) {
xaQueueConnection.close();
}
} catch (Exception e) {
System.out.println("Error processing " + e.getMessage());
}
amplifier.shutdown();
}
private static double calcAverage(ArrayList<Double> myArr) {
double sum = 0;
for (Double val : myArr) {
sum += val;
}
return sum/myArr.size();
}
// create and close session through QueueConnection object passed in.
private static class XASessionPoker implements Callable<Double> {
// conn instance of MQXAQueueConnection. ref. QueueProviderService
private QueueConnection conn;
XASessionPoker(QueueConnection conn) {
this.conn = conn;
}
@Override
public Double call() throws Exception {
XASession xaSession;
double elapsed = 0;
try {
final long start = System.currentTimeMillis();
// ref. DualSessionWrapper
// xaSession instance of MQXAQueueSession
xaSession = ((XAConnection) conn).createXASession();
xaSession.close();
final long end = System.currentTimeMillis();
elapsed = (end - start) / 1000.0;
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(e);
}
return elapsed;
}
}
}
答案 0 :(得分:1)
我们发现根本原因是no more session pooling
+ bitronix TM doesn't offer session pooling across TX
的组合。具体来说(在我们的示例中),bitronix管理JmsPooledConnection
池,但是每次使用(xa)会话(在JmsPooledConnection
下),都会创建一个新套接字(createXASession()
)并关闭({ {1}}。
一种解决方案是将jms xaSession.close()
用connection
池包装,类似于https://github.com/messaginghub/pooled-jms/tree/master/pooled-jms/src/main/java/org/messaginghub/pooled/jms
http://bjansen.github.io/java/2018/03/04/high-performance-mq-jms.html还表明Spring (xa)session
运作良好,这听起来像第一种解决方案的特殊情况。