Bug #43427 Don't limit table_cache_size as a function of max_connections
Submitted: 5 Mar 2009 17:17 Modified: 8 Mar 2009 16:01
Reporter: Mark Callaghan Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: General Severity:S5 (Performance)
Version:5.0 OS:Any
Assigned to: CPU Architecture:Any

[5 Mar 2009 17:17] Mark Callaghan
Description:
This code in mysqld.cc reduces the value of table_cache_size at startup to something less then the requested value as a function of max open files/connections. That assumes that each open table requires an open file descriptor. That assumption is storage-engine specific and is true for MyISAM. It is sometimes true for InnoDB (when file per table is used). There are serious performance consequences when this is done and the DBA has not noticed this and the server has a highly-concurrent workload with many tables.

------

    if (files < wanted_files)
    {
      if (!open_files_limit)
      {
        /*
          If we have requested too much file handles than we bring
          max_connections in supported bounds.
        */
        max_connections= (ulong) min(files-10-TABLE_OPEN_CACHE_MIN*2,
                                     max_connections);
        /*
          Decrease table_cache_size according to max_connections, but
          not below TABLE_OPEN_CACHE_MIN.  Outer min() ensures that we
          never increase table_cache_size automatically (that could
          happen if max_connections is decreased above).
        */
        table_cache_size= (ulong) min(max((files-10-max_connections)/2,
                                          TABLE_OPEN_CACHE_MIN),
                                      table_cache_size);    
        DBUG_PRINT("warning",
                   ("Changed limits: max_open_files: %u  max_connections: %ld  table_cache: %ld",
                    files, max_connections, table_cache_size));
        if (global_system_variables.log_warnings)
          sql_print_warning("Changed limits: max_open_files: %u  max_connections: %ld  table_cache: %ld",
                        files, max_connections, table_cache_size);

How to repeat:
na

Suggested fix:
na
[6 Mar 2009 9:24] Valeriy Kravchuk
As current behaviour is clearly intended, this is a request for a new feature.
[8 Mar 2009 16:01] Mark Callaghan
Yes, this is a feature request. MySQL started out as being very tolerant and 'fixing' things quietly. It would be nice to have a mode where it doesn't start or always raises errors instead. While this behavior is intended, the consequences are not. For this particular case, we had a large group of servers get very slow when the open file limit for the mysql user was smaller than we realized.