<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="connection-interfaces">
      </a>
      7.1.12.1 Connection Interfaces
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045261021648">
  </a>
  <a class="indexterm" name="idm46045261020160">
  </a>
  <a class="indexterm" name="idm46045261018672">
  </a>
  <a class="indexterm" name="idm46045261017584">
  </a>
  <a class="indexterm" name="idm46045261016496">
  </a>
  <a class="indexterm" name="idm46045261015424">
  </a>
  <a class="indexterm" name="idm46045261014352">
  </a>
  <p>
   This section describes aspects of how the MySQL server manages
        client connections.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="connection-interfaces.html#connection-interfaces-interfaces" title="Network Interfaces and Connection Manager Threads">
       Network Interfaces and Connection Manager Threads
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="connection-interfaces.html#connection-interfaces-thread-management" title="Client Connection Thread Management">
       Client Connection Thread Management
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="connection-interfaces.html#connection-interfaces-volume-management" title="Connection Volume Management">
       Connection Volume Management
      </a>
     </p>
    </li>
   </ul>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="connection-interfaces-interfaces">
       </a>
       Network Interfaces and Connection Manager Threads
      </h5>
     </div>
    </div>
   </div>
   <p>
    The server is capable of listening for client connections on
          multiple network interfaces. Connection manager threads handle
          client connection requests on the network interfaces that the
          server listens to:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       On all platforms, one manager thread handles TCP/IP
              connection requests.
      </p>
     </li>
     <li class="listitem">
      <p>
       On Unix, the same manager thread also handles Unix socket
              file connection requests.
      </p>
     </li>
     <li class="listitem">
      <p>
       On Windows, one manager thread handles shared-memory
              connection requests, and another handles named-pipe
              connection requests.
      </p>
     </li>
     <li class="listitem">
      <p>
       On all platforms, an additional network interface may be
              enabled to accept administrative TCP/IP connection
              requests. This interface can use the manager thread that
              handles
       <span class="quote">
        “
        <span class="quote">
         ordinary
        </span>
        ”
       </span>
       TCP/IP requests, or a
              separate thread.
      </p>
     </li>
    </ul>
   </div>
   <p>
    The server does not create threads to handle interfaces that
          it does not listen to. For example, a Windows server that does
          not have support for named-pipe connections enabled does not
          create a thread to handle them.
   </p>
   <p>
    Individual server plugins or components may implement their
          own connection interface:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       X Plugin enables MySQL Server to communicate with clients
              using X Protocol. See
       <a class="xref" href="x-plugin.html" title="22.5 X Plugin">
        Section 22.5, “X Plugin”
       </a>
       .
      </p>
     </li>
    </ul>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="connection-interfaces-thread-management">
       </a>
       Client Connection Thread Management
      </h5>
     </div>
    </div>
   </div>
   <p>
    Connection manager threads associate each client connection
          with a thread dedicated to it that handles authentication and
          request processing for that connection. Manager threads create
          a new thread when necessary but try to avoid doing so by
          consulting the thread cache first to see whether it contains a
          thread that can be used for the connection. When a connection
          ends, its thread is returned to the thread cache if the cache
          is not full.
   </p>
   <p>
    In this connection thread model, there are as many threads as
          there are clients currently connected, which has some
          disadvantages when server workload must scale to handle large
          numbers of connections. For example, thread creation and
          disposal becomes expensive. Also, each thread requires server
          and kernel resources, such as stack space. To accommodate a
          large number of simultaneous connections, the stack size per
          thread must be kept small, leading to a situation where it is
          either too small or the server consumes large amounts of
          memory. Exhaustion of other resources can occur as well, and
          scheduling overhead can become significant.
   </p>
   <p>
    MySQL Enterprise Edition includes a thread pool plugin that provides an
          alternative thread-handling model designed to reduce overhead
          and improve performance. It implements a thread pool that
          increases server performance by efficiently managing statement
          execution threads for large numbers of client connections. See
    <a class="xref" href="thread-pool.html" title="7.6.3 MySQL Enterprise Thread Pool">
     Section 7.6.3, “MySQL Enterprise Thread Pool”
    </a>
    .
   </p>
   <p>
    To control and monitor how the server manages threads that
          handle client connections, several system and status variables
          are relevant. (See
    <a class="xref" href="server-system-variables.html" title="7.1.8 Server System Variables">
     Section 7.1.8, “Server System Variables”
    </a>
    ,
          and
    <a class="xref" href="server-status-variables.html" title="7.1.10 Server Status Variables">
     Section 7.1.10, “Server Status Variables”
    </a>
    .)
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       The
       <a class="link" href="server-system-variables.html#sysvar_thread_cache_size">
        <code class="literal">
         thread_cache_size
        </code>
       </a>
       system variable determines the thread cache size. By
              default, the server autosizes the value at startup, but it
              can be set explicitly to override this default. A value of
              0 disables caching, which causes a thread to be set up for
              each new connection and disposed of when the connection
              terminates. To enable
       <em class="replaceable">
        <code>
         N
        </code>
       </em>
       inactive connection threads to be cached, set
       <a class="link" href="server-system-variables.html#sysvar_thread_cache_size">
        <code class="literal">
         thread_cache_size
        </code>
       </a>
       to
       <em class="replaceable">
        <code>
         N
        </code>
       </em>
       at server startup or at
              runtime. A connection thread becomes inactive when the
              client connection with which it was associated terminates.
      </p>
     </li>
     <li class="listitem">
      <p>
       To monitor the number of threads in the cache and how many
              threads have been created because a thread could not be
              taken from the cache, check the
       <a class="link" href="server-status-variables.html#statvar_Threads_cached">
        <code class="literal">
         Threads_cached
        </code>
       </a>
       and
       <a class="link" href="server-status-variables.html#statvar_Threads_created">
        <code class="literal">
         Threads_created
        </code>
       </a>
       status
              variables.
      </p>
     </li>
     <li class="listitem">
      <p>
       When the thread stack is too small, this limits the
              complexity of the SQL statements the server can handle,
              the recursion depth of stored procedures, and other
              memory-consuming actions. To set a stack size of
       <em class="replaceable">
        <code>
         N
        </code>
       </em>
       bytes for each thread, start
              the server with
       <a class="link" href="server-system-variables.html#sysvar_thread_stack">
        <code class="literal">
         thread_stack
        </code>
       </a>
       set to
       <em class="replaceable">
        <code>
         N
        </code>
       </em>
       .
      </p>
     </li>
    </ul>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="connection-interfaces-volume-management">
       </a>
       Connection Volume Management
      </h5>
     </div>
    </div>
   </div>
   <p>
    To control the maximum number of clients the server permits to
          connect simultaneously, set the
    <a class="link" href="server-system-variables.html#sysvar_max_connections">
     <code class="literal">
      max_connections
     </code>
    </a>
    system
          variable at server startup or at runtime. It may be necessary
          to increase
    <a class="link" href="server-system-variables.html#sysvar_max_connections">
     <code class="literal">
      max_connections
     </code>
    </a>
    if more clients attempt to connect simultaneously then the
          server is configured to handle (see
    <a class="xref" href="too-many-connections.html" title="B.3.2.5 Too many connections">
     Section B.3.2.5, “Too many connections”
    </a>
    ). If the server refuses
          a connection because the
    <a class="link" href="server-system-variables.html#sysvar_max_connections">
     <code class="literal">
      max_connections
     </code>
    </a>
    limit is
          reached, it increments the
    <a class="link" href="server-status-variables.html#statvar_Connection_errors_max_connections">
     <code class="literal">
      Connection_errors_max_connections
     </code>
    </a>
    status variable.
   </p>
   <p>
    <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
     <span class="command">
      <strong>
       mysqld
      </strong>
     </span>
    </a>
    actually permits
    <a class="link" href="server-system-variables.html#sysvar_max_connections">
     <code class="literal">
      max_connections
     </code>
    </a>
    + 1 client connections. The extra connection is reserved for
          use by accounts that have the
    <a class="link" href="privileges-provided.html#priv_connection-admin">
     <code class="literal">
      CONNECTION_ADMIN
     </code>
    </a>
    privilege (or
          the deprecated
    <a class="link" href="privileges-provided.html#priv_super">
     <code class="literal">
      SUPER
     </code>
    </a>
    privilege). By granting the privilege to administrators and
          not to normal users (who should not need it), an administrator
          can connect to the server and use
    <a class="link" href="show-processlist.html" title="15.7.7.31 SHOW PROCESSLIST Statement">
     <code class="literal">
      SHOW
          PROCESSLIST
     </code>
    </a>
    to diagnose problems even if the maximum
          number of unprivileged clients are connected. See
    <a class="xref" href="show-processlist.html" title="15.7.7.31 SHOW PROCESSLIST Statement">
     Section 15.7.7.31, “SHOW PROCESSLIST Statement”
    </a>
    .
   </p>
   <p>
    The server also permits administrative connections on an
          administrative network interface, which you can set up using a
          dedicated IP address and port. See
    <a class="xref" href="administrative-connection-interface.html" title="7.1.12.2 Administrative Connection Management">
     Section 7.1.12.2, “Administrative Connection Management”
    </a>
    .
   </p>
   <p>
    The Group Replication plugin interacts with MySQL Server using
          internal sessions to perform SQL API operations. Group
          Replication's internal sessions are handled separately from
          client connections, so they do not count towards the
    <a class="link" href="server-system-variables.html#sysvar_max_connections">
     <code class="literal">
      max_connections
     </code>
    </a>
    limit and are
          not refused if the server has reached this limit.
   </p>
   <p>
    The maximum number of client connections MySQL supports (that
          is, the maximum value to which
    <a class="link" href="server-system-variables.html#sysvar_max_connections">
     <code class="literal">
      max_connections
     </code>
    </a>
    can be set)
          depends on several factors:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       The quality of the thread library on a given platform.
      </p>
     </li>
     <li class="listitem">
      <p>
       The amount of RAM available.
      </p>
     </li>
     <li class="listitem">
      <p>
       The amount of RAM is used for each connection.
      </p>
     </li>
     <li class="listitem">
      <p>
       The workload from each connection.
      </p>
     </li>
     <li class="listitem">
      <p>
       The desired response time.
      </p>
     </li>
     <li class="listitem">
      <p>
       The number of file descriptors available.
      </p>
     </li>
    </ul>
   </div>
   <p>
    Linux or Solaris should be able to support at least 500 to
          1000 simultaneous connections routinely and as many as 10,000
          connections if you have many gigabytes of RAM available and
          the workload from each is low or the response time target
          undemanding.
   </p>
   <p>
    Increasing the
    <a class="link" href="server-system-variables.html#sysvar_max_connections">
     <code class="literal">
      max_connections
     </code>
    </a>
    value
          increases the number of file descriptors that
    <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
     <span class="command">
      <strong>
       mysqld
      </strong>
     </span>
    </a>
    requires. If the required number of
          descriptors are not available, the server reduces the value of
    <a class="link" href="server-system-variables.html#sysvar_max_connections">
     <code class="literal">
      max_connections
     </code>
    </a>
    . For comments
          on file descriptor limits, see
    <a class="xref" href="table-cache.html" title="10.4.3.1 How MySQL Opens and Closes Tables">
     Section 10.4.3.1, “How MySQL Opens and Closes Tables”
    </a>
    .
   </p>
   <p>
    Increasing the
    <a class="link" href="server-system-variables.html#sysvar_open_files_limit">
     <code class="literal">
      open_files_limit
     </code>
    </a>
    system
          variable may be necessary, which may also require raising the
          operating system limit on how many file descriptors can be
          used by MySQL. Consult your operating system documentation to
          determine whether it is possible to increase the limit and how
          to do so. See also
    <a class="xref" href="not-enough-file-handles.html" title="B.3.2.16 File Not Found and Similar Errors">
     Section B.3.2.16, “File Not Found and Similar Errors”
    </a>
    .
   </p>
  </div>
 </div>
 <br/>
</div>
