ActiveMQ,一个主题上的多个使用者是否会降低生产者发送速率?
这里有一些配置: 非持久使用者、非持久消息、禁用的流控制、默认预取大小、optimizeAcknowledge=true、asynsend=true、使用jms连接ActiveMQ 比如说, 一个生产者,一个消费者ActiveMQ,一个主题上的多个使用者是否会降低生产者发送速率?,activemq,Activemq,这里有一些配置: 非持久使用者、非持久消息、禁用的流控制、默认预取大小、optimizeAcknowledge=true、asynsend=true、使用jms连接ActiveMQ 比如说, 一个生产者,一个消费者 Producer————Topic————consumer 生产者发送速率可达6k/s 但是,在这种情况下: 一个生产者三个消费者 /——consumer Producer——-Topic——-consumer \
Producer————Topic————consumer
生产者发送速率可达6k/s
但是,在这种情况下:
一个生产者三个消费者
/——consumer
Producer——-Topic——-consumer
\——consumer
生产者发送速率下降到4k/s
以下是我的一些关键代码:
发件人类别:
public class sender {
public Boolean durable=false;
public String clientID=null;
public Boolean transacted=false;
public int ackMode=Session.AUTO_ACKNOWLEDGE;
public int timeToLive=0;
public String queuename = "";
public int persistent = DeliveryMode.NON_PERSISTENT;
public Connection createConnection(String user,String pwd,String url) throws JMSException, Exception {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, pwd, url);
connectionFactory.setDispatchAsync(true);
//connectionFactory.setAlwaysSessionAsync(false);
Connection connection = connectionFactory.createConnection();
if (durable && clientID!=null) {
connection.setClientID(clientID);
}
connection.start();
return connection;
}
public Session createSession(Connection connection) throws Exception {
Session session = connection.createSession(transacted, ackMode);
return session;
}
public MessageProducer createProducer(Session session) throws JMSException {
Queue destination = session.createQueue(queuename);
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(persistent);
if( timeToLive!=0 )
producer.setTimeToLive(timeToLive);
return producer;
}
public void onMessage(Message message) {
//process message
}
}
主要方法:
public static void main(String[] args) throws JMSException, Exception {
// TODO Auto-generated method stub
sender s = new sender();
s.persistent = DeliveryMode.NON_PERSISTENT;
Connection c = s.createConnection("","","tcp://localhost:61616?jms.useAsyncSend=true");
Session sess = s.createSession(c);
Topic topic = sess.createTopic("topic.test");
MessageProducer mp = sess.createProducer(topic);
StringBuffer tmpsb=new StringBuffer();
for (int j=0;j<1024;j++)
{
tmpsb.append("0");
}
Message m = sess.createTextMessage(tmpsb.toString());
long pre=System.currentTimeMillis();
for (int i=0;i<10000;i++)
{
mp.send(m);
}
long post=System.currentTimeMillis();
mp.close();
System.out.println("sendtime:"+(post-pre));
System.out.println("sendrate:"+10000000/(float)(post-pre));
System.out.println("timenow:"+(post));
}
这里的接收方类代码隐藏了一些方法,例如createConnection、createSession或类似于发送方类的方法
主要方法:
public static void main(String[] args) throws JMSException, Exception {
// TODO Auto-generated method stub
receiver s = new receiver();
Connection c = s.createConnection("","","tcp://localhost:6151?jms.optimizeAcknowledge=true");
Session sess = s.createSession(c);
Topic destination = sess.createTopic("topic.test");
MessageConsumer consumer = sess.createConsumer(destination);
consumer.setMessageListener(new receiver());
}
每个消费者都处于一个独立的流程中。我运行了三个消费者和一个生产者,然后我得到了一个表现不佳的结果。有人知道我为什么会这样吗?正如@TimBish所说。
问题是“同一台计算机上的生产者、消费者和activemq服务器”。如果分开,问题将永远不会出现
严格地测试某些东西非常重要……我希望在连接上启用asyncsend。如果设置为false,则可能会产生影响。通常,对于非持久性消息,asyncsend为true。asyncsend已设置为'true'Already。您可以告诉我如何测量消息的速率。消费者是否持久?更多的配置和用例信息将help@TimBish在第一行,非持久性消费者中给出了一些配置。现在我想知道是否有人测试过ActiveMQ,并可以给出一些建议。
public static void main(String[] args) throws JMSException, Exception {
// TODO Auto-generated method stub
receiver s = new receiver();
Connection c = s.createConnection("","","tcp://localhost:6151?jms.optimizeAcknowledge=true");
Session sess = s.createSession(c);
Topic destination = sess.createTopic("topic.test");
MessageConsumer consumer = sess.createConsumer(destination);
consumer.setMessageListener(new receiver());
}