MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:mmatthews Date:September 15 2007 8:58pm
Subject:Connector/J commit: r6587 - in branches/branch_5_1/connector-j: . src/com/mysql/jdbc
View as plain text  
Modified:
   branches/branch_5_1/connector-j/CHANGES
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/Connection.java
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionProperties.java
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionPropertiesImpl.java
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
Log:
 Added "autoSlowLog" configuration property, overrides 
      "slowQueryThreshold*" properties, driver determines slow
      queries by those that are slower than 5 * stddev of the mean
      query time (outside the 96% percentile).

Externalized some utf-8 related connection property descriptions.

Modified: branches/branch_5_1/connector-j/CHANGES
===================================================================
--- branches/branch_5_1/connector-j/CHANGES	2007-09-12 04:03:37 UTC (rev 6586)
+++ branches/branch_5_1/connector-j/CHANGES	2007-09-15 20:58:27 UTC (rev 6587)
@@ -1,6 +1,12 @@
 # Changelog
 # $Id$
+nn-nn-07 - Version 5.1.4 
 
+    - Added "autoSlowLog" configuration property, overrides 
+      "slowQueryThreshold*" properties, driver determines slow
+      queries by those that are slower than 5 * stddev of the mean
+      query time (outside the 96% percentile).
+      
 09-07-07 - Version 5.1.3 RC
 
 	- Setting "useBlobToStoreUTF8OutsideBMP" to "true" tells the

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/Connection.java	2007-09-12 04:03:37 UTC (rev 6586)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/Connection.java	2007-09-15 20:58:27 UTC (rev 6587)
@@ -343,5 +343,9 @@
 	 */
 	public abstract boolean versionMeetsMinimum(int major, int minor,
 			int subminor) throws SQLException;
+	
+	public abstract void reportQueryTime(long millisOrNanos);
+	
+	public abstract boolean isAbonormallyLongQuery(long millisOrNanos);
 
 }
\ No newline at end of file

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java	2007-09-12 04:03:37 UTC (rev 6586)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java	2007-09-15 20:58:27 UTC (rev 6587)
@@ -166,6 +166,11 @@
 
 	private static final Map serverConfigByUrl = new HashMap();
 
+	private long queryTimeCount;
+	private double queryTimeSum;
+	private double queryTimeSumSquares;
+	private double queryTimeMean;
+	
 	private static Timer cancelTimer;
 	private static final Constructor JDBC_4_CONNECTION_CTOR;
 	
@@ -5259,4 +5264,22 @@
 	public void setStatementComment(String comment) {
 		this.statementComment = comment;
 	}
+	
+	public synchronized void reportQueryTime(long millisOrNanos) {
+		this.queryTimeCount++;
+		this.queryTimeSum += millisOrNanos;
+		this.queryTimeSumSquares += (millisOrNanos * millisOrNanos);
+		this.queryTimeMean = ((this.queryTimeMean * (this.queryTimeCount - 1)) + millisOrNanos)
+				/ this.queryTimeCount;
+	}
+	
+	public synchronized boolean isAbonormallyLongQuery(long millisOrNanos) {
+		if (this.queryTimeCount < 15) {
+			return false; // need a minimum amount for this to make sense
+		}
+		
+		double stddev = Math.sqrt((this.queryTimeSumSquares - ((this.queryTimeSum*this.queryTimeSum) / this.queryTimeCount)) / (this.queryTimeCount - 1));
+		
+		return millisOrNanos > (this.queryTimeMean + 5 * stddev);
+	}
 }

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionProperties.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionProperties.java	2007-09-12 04:03:37 UTC (rev 6586)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionProperties.java	2007-09-15 20:58:27 UTC (rev 6587)
@@ -1566,4 +1566,8 @@
     public abstract boolean getFunctionsNeverReturnBlobs();
 
     public abstract void setFunctionsNeverReturnBlobs(boolean flag);
+    
+	public abstract boolean getAutoSlowLog();
+
+	public abstract void setAutoSlowLog(boolean flag);
 }

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionPropertiesImpl.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionPropertiesImpl.java	2007-09-12 04:03:37 UTC (rev 6586)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionPropertiesImpl.java	2007-09-15 20:58:27 UTC (rev 6587)
@@ -755,16 +755,19 @@
 			Messages.getString("ConnectionProperties.blobSendChunkSize"), //$NON-NLS-1$
 			"3.1.9", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); //$NON-NLS-1$
 	
+	private BooleanConnectionProperty autoSlowLog = new BooleanConnectionProperty(
+			"autoSlowLog", true,
+			Messages.getString("ConnectionProperties.autoSlowLog"),
+			"5.1.4", DEBUGING_PROFILING_CATEGORY, Integer.MIN_VALUE);
+	
 	private BooleanConnectionProperty blobsAreStrings = new BooleanConnectionProperty(
             "blobsAreStrings", false,
-            "Should the driver always treat BLOBs as Strings - specifically to work around dubious metadata "
-            + "returned by the server for GROUP BY clauses?",
+            Messages.getString("ConnectionProperties.blobsAreStrings"),
             "5.0.8", MISC_CATEGORY, Integer.MIN_VALUE);
 
 	private BooleanConnectionProperty functionsNeverReturnBlobs = new BooleanConnectionProperty(
             "functionsNeverReturnBlobs", false,
-            "Should the driver always treat data from functions returning BLOBs as Strings - specifically to work around dubious metadata "
-            + "returned by the server for GROUP BY clauses?",
+            Messages.getString("ConnectionProperties.functionsNeverReturnBlobs"),
             "5.0.8", MISC_CATEGORY, Integer.MIN_VALUE);
 			
 	private BooleanConnectionProperty cacheCallableStatements = new BooleanConnectionProperty(
@@ -4256,4 +4259,12 @@
     public void setFunctionsNeverReturnBlobs(boolean flag) {
         this.functionsNeverReturnBlobs.setValue(flag);
     }
+
+	public boolean getAutoSlowLog() {
+		return this.autoSlowLog.getValueAsBoolean();
+	}
+
+	public void setAutoSlowLog(boolean flag) {
+		this.autoSlowLog.setValue(flag);
+	}
 }

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties	2007-09-12 04:03:37 UTC (rev 6586)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties	2007-09-15 20:58:27 UTC (rev 6587)
@@ -447,6 +447,9 @@
 ConnectionProperties.autoGenerateTestcaseScript=Should the driver dump the SQL it is executing, including server-side prepared statements to STDERR?
 ConnectionProperties.autoReconnect=Should the driver try to re-establish stale and/or dead connections? If enabled the driver will throw an exception for a queries issued on a stale or dead connection, which belong to the current transaction, but will attempt reconnect before the next query issued on the connection in a new transaction. The use of this feature is not recommended, because it has side effects related to session state and data consistency when applications don't handle SQLExceptions properly, and is only designed to be used when you are unable to configure your application to handle SQLExceptions resulting from dead and stale connections properly. Alternatively, investigate setting the MySQL server variable "wait_timeout" to some high value rather than the default of 8 hours.
 ConnectionProperties.autoReconnectForPools=Use a reconnection strategy appropriate for connection pools (defaults to 'false')
+ConnectionProperties.autoSlowLog=Instead of using slowQueryThreshold* to determine if a query is slow enough to be logged, maintain statistics that allow the driver to determine queries that are outside the 99th percentile?
+ConnectionProperties.blobsAreStrings=Should the driver always treat BLOBs as Strings - specifically to work around dubious metadata returned by the server for GROUP BY clauses?
+ConnectionProperties.functionsNeverReturnBlobs=Should the driver always treat data from functions returning BLOBs as Strings - specifically to work around dubious metadata returned by the server for GROUP BY clauses?
 ConnectionProperties.blobSendChunkSize=Chunk to use when sending BLOB/CLOBs via ServerPreparedStatements
 ConnectionProperties.cacheCallableStatements=Should the driver cache the parsing stage of CallableStatements
 ConnectionProperties.cachePrepStmts=Should the driver cache the parsing stage of PreparedStatements of client-side prepared statements, the "check" for suitability of server-side prepared and server-side prepared statements themselves?

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java	2007-09-12 04:03:37 UTC (rev 6586)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java	2007-09-15 20:58:27 UTC (rev 6587)
@@ -257,6 +257,8 @@
             this.packetDebugRingBuffer = new LinkedList();
         }
 
+        this.useAutoSlowLog = this.connection.getAutoSlowLog();
+        
         this.useBufferRowSizeThreshold = useBufferRowSizeThreshold;
         this.useDirectRowUnpack = this.connection.getUseDirectRowUnpack();
 
@@ -1861,6 +1863,7 @@
     }
 
     private int statementExecutionDepth = 0;
+	private boolean useAutoSlowLog;
 
     /**
      * Send a query stored in a packet directly to the server.
@@ -1990,10 +1993,23 @@
 
 	    		if (this.profileSql) {
 	    			shouldExtractQuery = true;
-	    		} else if (this.logSlowQueries &&
-	    				((queryEndTime - queryStartTime) > this.connection.getSlowQueryThresholdMillis())) {
-	    			shouldExtractQuery = true;
-	    			queryWasSlow = true;
+	    		} else if (this.logSlowQueries) {
+	    			long queryTime = queryEndTime - queryStartTime;
+	    			
+	    			boolean logSlow = false;
+	    			
+	    			if (this.useAutoSlowLog) {
+	    				logSlow = queryTime > this.connection.getSlowQueryThresholdMillis();
+	    			} else {
+	    				logSlow = this.connection.isAbonormallyLongQuery(queryTime);
+	    				
+	    				this.connection.reportQueryTime(queryTime);
+	    			}
+	    			
+	    			if (logSlow) {
+	    				shouldExtractQuery = true;
+	    				queryWasSlow = true;
+	    			}
 	    		}
 
 	    		if (shouldExtractQuery) {

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java	2007-09-12 04:03:37 UTC (rev 6586)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java	2007-09-15 20:58:27 UTC (rev 6587)
@@ -360,6 +360,7 @@
 				!this.connection.versionMeetsMinimum(4, 1, 10);
 		}
 		
+		this.useAutoSlowLog = this.connection.getAutoSlowLog();
 		this.useTrueBoolean = this.connection.versionMeetsMinimum(3, 21, 23);
 		this.hasLimitClause = (StringUtils.indexOfIgnoreCase(sql, "LIMIT") != -1); //$NON-NLS-1$
 		this.firstCharOfStmt = StringUtils.firstNonWsCharUc(sql);
@@ -523,6 +524,8 @@
 
 	protected boolean isCached = false;
 
+	private boolean useAutoSlowLog;
+
 	protected void setClosed(boolean flag) {
 		this.isClosed = flag;
 	}
@@ -1281,9 +1284,17 @@
 				if (logSlowQueries || gatherPerformanceMetrics) {
 					long elapsedTime = queryEndTime - begin;
 
-					if (logSlowQueries
-							&& (elapsedTime >= mysql.getSlowQueryThreshold())) {
-						queryWasSlow = true;
+					if (logSlowQueries) {
+		    			if (this.useAutoSlowLog) {
+		    				queryWasSlow = elapsedTime > this.connection.getSlowQueryThresholdMillis();
+		    			} else {
+		    				queryWasSlow = this.connection.isAbonormallyLongQuery(elapsedTime);
+		    				
+		    				this.connection.reportQueryTime(elapsedTime);
+		    			}
+					}
+
+					if (queryWasSlow) {
 						
 						StringBuffer mesgBuf = new StringBuffer(
 								48 + this.originalSql.length());

Thread
Connector/J commit: r6587 - in branches/branch_5_1/connector-j: . src/com/mysql/jdbcmmatthews15 Sep