czwartek, czerwca 05, 2014

EMS: 40 sessions in 1 connection or 40 connection with 1 session

final TibjmsQueueConnectionFactory cf = new TibjmsQueueConnectionFactory();
cf.setServerUrl("tcp://localhost:7222");
cf.setUserName("admin");
cf.setUserPassword("Adm1n");

final QueueConnection qc = cf.createQueueConnection();
QueueSession qs = qc.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
QueueSender qsnd = qs.createSender(qs.createQueue("1n_n1"));
qc.start();

final AtomicInteger toDo = new AtomicInteger(0);
final AtomicInteger[] sum = new AtomicInteger[2];

int[] sessionPerConnIters = { 1, 0 };

for (final int mode : sessionPerConnIters) {
sum[mode] = new AtomicInteger(0);
for (int i=0; i < 100; i++) {
TextMessage msg = qs.createTextMessage(MESSAGE);
msg.setIntProperty("TEST", 1);
qsnd.send(msg);
}
toDo.set(100);
final CyclicBarrier cb = new CyclicBarrier(41);
for (int i=0; i < 40; i++) {
new Thread() {
public void run() {
try {
QueueConnection _qc = (mode == 1) ? cf.createQueueConnection() : qc;
_qc.start();
QueueSession _qs = _qc.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
QueueReceiver _qr = _qs.createReceiver(_qs.createQueue("1n_n1"), "TEST=1");

long t1 = System.currentTimeMillis();

while (toDo.get() > 0) {
TextMessage m = (TextMessage) _qr.receive(100);
long t2 = System.currentTimeMillis();
if (m!=null) {
if (mode == 1)
System.out.println("Message recv time = "+(t2-t1)+" ms");
else
System.err.println("Message recv time = "+(t2-t1)+" ms");
sum[mode].addAndGet((int) (t2-t1));
m.acknowledge();
toDo.decrementAndGet();
t1 = t2;
}
}
cb.await();
_qs.close();
if (mode == 1)
_qc.close();
}
catch (Exception exc) {
exc.printStackTrace();
}
}
}.start();
}
cb.await();
}
qc.close();
for (int i=0; i < sum.length; i++) {
System.out.println("Full time of all threads: "+sum[i].get()+", sessionPerConn="+sessionPerConnIters[i]);
}
}

Full time of all threads: 46554, sessionPerConn=1
Full time of all threads: 53262, sessionPerConn=0
20 threads, 4MB

Full time of all threads: 262, sessionPerConn=1
Full time of all threads: 403, sessionPerConn=0
20 threads, 4KB

Full time of all threads: 79, sessionPerConn=1
Full time of all threads: 72, sessionPerConn=0
 5 threads, 4KB

--
Full time of all threads: 14866, sessionPerConn=1 Full time of all threads: 26016, sessionPerConn=0 20, 1MB Full time of all threads: 6486, sessionPerConn=1 Full time of all threads: 9073, sessionPerConn=0 15, 1MB Full time of all threads: 4181, sessionPerConn=1 Full time of all threads: 6366, sessionPerConn=0 10, 1MB Full time of all threads: 2249, sessionPerConn=1 Full time of all threads: 2646, sessionPerConn=0 5, 1MB Full time of all threads: 1870, sessionPerConn=1 Full time of all threads: 2093, sessionPerConn=0 4, 1MB Full time of all threads: 1391, sessionPerConn=1 Full time of all threads: 1246, sessionPerConn=0 3, 1MB --- Full time of all threads: 192, sessionPerConn=1 Full time of all threads: 251, sessionPerConn=0 20, 1KB Full time of all threads: 181, sessionPerConn=1 Full time of all threads: 165, sessionPerConn=0 15, 1KB Full time of all threads: 163, sessionPerConn=1 Full time of all threads: 137, sessionPerConn=0 10, 1KB
--
Conclusion: When using above 20 sessions per connection 1:1 connection/session model is faster than 1:n approach.

0 komentarze: