Bug #52475 Performance issue in Connector/NET procedure cache
Submitted: 30 Mar 2010 12:56 Modified: 22 Apr 2010 15:30
Reporter: Bogdan Degtyariov Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.2.x OS:Any
Assigned to: Bogdan Degtyariov CPU Architecture:Any
Tags: logging, String.Format

[30 Mar 2010 12:56] Bogdan Degtyariov
Description:
Procedure cache affects the Connector/NET performance by unnecessary calls of String.Format() related to debug logging. Even though the logging is disabled the string is being formatted in any case, which looks as wasting time for unnecessary work.

My tests showed up to 65% slow down.

Here is the function that is responsible for the problem:

public DataSet GetProcedure(MySqlConnection conn, string spName)
{
    int hash = spName.GetHashCode();

    DataSet ds = null;
    lock (procHash.SyncRoot)
    {
        ds = (DataSet)procHash[hash];
    }
    if (ds == null)
    {
        ds = AddNew(conn, spName);
#if !CF
        conn.PerfMonitor.AddHardProcedureQuery();
#endif
        /* !!!!!!!! SLOW DOWN !!!!!!!!! */
        MySqlTrace.LogInformation(conn.ServerThread,
            String.Format(Resources.HardProcQuery, spName));
    }
    else
    {
#if !CF
        conn.PerfMonitor.AddSoftProcedureQuery();
#endif
        /* !!!!!!!! SLOW DOWN !!!!!!!!! */
        MySqlTrace.LogInformation(conn.ServerThread,
            String.Format(Resources.SoftProcQuery, spName));
    }
    return ds;
} 

How to repeat:
Call a lightweight stored procedure 1M times.

Suggested fix:
if(conn.Settings.Logging)
  MySqlTrace.LogInformation(conn.ServerThread,
      String.Format(Resources.HardProcQuery, spName));
[15 Apr 2010 23:37] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/105775

843 Reggie Burnett	2010-04-15
      put back "misplaced" check for logging flag when writing out debug information inside procedure cache 
       (bug #52475)
[15 Apr 2010 23:42] Reggie Burnett
fixed in 6.2.4 and 6.3.2
[22 Apr 2010 15:30] Tony Bedford
An entry has been added to the 6.2.4 and 6.3.2 changelogs:

The procedure cache affected the MySQL Connector/NET performance, reducing it by around 65%. This was due to unnecessary calls of String.Format(), related to debug logging. Even though the logging was disabled the string was still being formatted, resulting in impaired performance.