Bug #52534 Significant performance regression using load-balanced connections
Submitted: 1 Apr 2010 17:49 Modified: 22 Apr 2010 10:20
Reporter: Todd Farmer (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:5.1-bzr OS:Any
Assigned to: Todd Farmer CPU Architecture:Any

[1 Apr 2010 17:49] Todd Farmer
Description:
There is a performance regression of roughly 25% between r906 and r907, which appears to be caused by pushing the Proxy down to the I/O layer.  Specifically, it appears to be a regression caused by the code implemented in BUG#51643.

Using test case provided, for r906:

Mean TPS: 2909.837792987103 

For r907:

Mean TPS: 2252.1763514319264

How to repeat:
	public static void main(String[] args) {
	    Connection con = null;
	    String URL = "localhost:3306,localhost:3309,localhost:3310/test";
	    String sqlUser = "root";
	    String sqlPasswd = "";
	    int iterations = 10000;
	    int studies = 10;
	    double totalTPS = 0.0;
	    double totalDuration = 0.0;
	    
	    try {
	    	
	    	for(int j = 0; j < studies; j++){
	        Class.forName("com.mysql.jdbc.Driver");
	        String url =
	              "jdbc:mysql:loadbalance://" +  URL ;
	        long start = System.currentTimeMillis();
	        con = DriverManager.getConnection(url,sqlUser, sqlPasswd);
	        con.setAutoCommit(false);

	        for(int i = 0; i < iterations; i++){
	        	con.createStatement().execute("SELECT 1");
	        	con.commit();
	        }
	        long duration = System.currentTimeMillis() - start;
	        System.out.println("Transactions per second:  " + iterations / (duration /  1000.0));
	        System.out.println("Duration:  " + (duration /  1000.0));
	        totalTPS += iterations / (duration /  1000.0);
	        totalDuration += (duration /  1000.0);
	    	}
	        System.out.println("Driver Version:  " + con.getMetaData().getDriverVersion());
	    	
	    	System.out.println("Mean TPS: " + totalTPS / studies );
	        
	      }catch( Exception e ) {
	         e.printStackTrace();
	      } finally {
	    	  try{
	    		  if(con != null){
	    			  con.close();
	    		  }
	    	  } catch (SQLException e){
	    		  e.printStackTrace();
	    	  }
	    	  
	      }

	}

Suggested fix:
Find more efficient way to proxy necessary operations.
[7 Apr 2010 15:16] Todd Farmer
Fixed and merged with upstream changes as r918.  Using same test:

Mean TPS: 2901.7807799871453
[22 Apr 2010 10:20] Tony Bedford
An entry has been added to the 5.1.13 changelog:

There was a performance regression of roughly 25% between r906 and r907, which appeared to be caused by pushing the Proxy down to the I/O layer.