java - Performance concrens with RabbitMQ in multi-threaded environemnt -


i have 2 simple test cases. in first 1 i'm reusing both connection , channel. in second 1 i'm reusing connection. reason having second 1 simulate channel per thread scenario in multi-threaded environment(this not same, can idea performance)

so first 1 can publish 70000 msg/sec , second can publish 1500 msg/sec.

  1. does mean channel creation costly in rabbitmq?
  2. can use channel pooling resolve this?

1st sample

public class send {  public static void main(string[] args) throws exception {      connectionfactory factory = new connectionfactory();     factory.sethost("localhost");     connection connection = factory.newconnection();     channel channel = connection.createchannel();     channel.exchangedeclare("myexchange", "direct", true);     channel.queuedeclare("myqueue", true, false, false, null);      (int = 0; < 1000000; i++) {         string message = "{\"id\" : \"56664f85-62e0-11e5-a74b-59530fbb6d8d\"" + + "}";         channel.basicpublish("", "myqueue", null, message.getbytes("utf-8"));     }      channel.close();     connection.close(); } 

2nd sample

public class send {  public static void main(string[] args) throws exception {      connectionfactory factory = new connectionfactory();     factory.sethost("localhost");     connection connection = factory.newconnection();      (int = 0; < 1000000; i++) {         channel channel = connection.createchannel();         channel.exchangedeclare("myexchange", "direct", true);         channel.queuedeclare("myqueue", true, false, false, null);         string message = "{\"id\" : \"56664f85-62e0-11e5-a74b-59530fbb6d8d\"" + + "}";         channel.basicpublish("", "myqueue", null, message.getbytes("utf-8"));         channel.close();     }      connection.close(); } 

i made simple test:

 final int perffor = 100000;         d1 = new date();         (int = 0; < perffor; i++) {             channel channel1 = connection.createchannel();             channel1.close();          }         d2 = new date();         seconds = (d2.gettime() - d1.gettime()) / 1000;         system.out.println("seconds-only-createdestroychannels: " + seconds);           final atomicinteger atomicinteger = new atomicinteger();         executorservice threadchannels = executors.newfixedthreadpool(1000);         final date dthread = new date();         (int = 0; < perffor; i++) {              threadchannels.submit(new runnable() {                 public void run() {                     channel channel1 = null;                     try {                         channel1 = connection.createchannel();                         channel1.close();                         if (atomicinteger.addandget(1) == perffor) {                             date d2 = new date();                             long seconds = (d2.gettime() - dthread.gettime()) / 1000;                             system.out.println("seconds-only-createdestroychannels multithreads: " + seconds);   ... 

i got results:

seconds-only-createdestroychannels: 84 seconds-only-createdestroychannels multithreads: 59 

so, don't think need create channels pool. should have channel thread, means start thread , create channel.

channel.exchangedeclare , channel.queuedeclare should called 1 time , not each publish.

you should consider increase connection number, 1.000.000 single connection seems bit unbalanced.

i suggest read this , this

rabbitmq has lot ways improve performance, , should consider environment , not channels .

hope helps


Comments