<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="performance-schema-memory-model">
      </a>
      29.17 The Performance Schema Memory-Allocation Model
     </h2>
    </div>
   </div>
  </div>
  <p>
   The Performance Schema uses this memory allocation model:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      May allocate memory at server startup
     </p>
    </li>
    <li class="listitem">
     <p>
      May allocate additional memory during server operation
     </p>
    </li>
    <li class="listitem">
     <p>
      Never free memory during server operation (although it might
          be recycled)
     </p>
    </li>
    <li class="listitem">
     <p>
      Free all memory used at shutdown
     </p>
    </li>
   </ul>
  </div>
  <p>
   The result is to relax memory constraints so that the Performance
      Schema can be used with less configuration, and to decrease the
      memory footprint so that consumption scales with server load.
      Memory used depends on the load actually seen, not the load
      estimated or explicitly configured for.
  </p>
  <p>
   Several Performance Schema sizing parameters are autoscaled and
      need not be configured explicitly unless you want to establish an
      explicit limit on memory allocation:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-none"><div class="docs-select-all right" id="sa43847526"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-none">performance_schema_accounts_size
performance_schema_hosts_size
performance_schema_max_cond_instances
performance_schema_max_file_instances
performance_schema_max_index_stat
performance_schema_max_metadata_locks
performance_schema_max_mutex_instances
performance_schema_max_prepared_statements_instances
performance_schema_max_program_instances
performance_schema_max_rwlock_instances
performance_schema_max_socket_instances
performance_schema_max_table_handles
performance_schema_max_table_instances
performance_schema_max_table_lock_stat
performance_schema_max_thread_instances
performance_schema_users_size</code></pre>
  </div>
  <p>
   For an autoscaled parameter, configuration works like this:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      With the value set to -1 (the default), the parameter is
          autoscaled:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         The corresponding internal buffer is empty initially and
              no memory is allocated.
        </p>
       </li>
       <li class="listitem">
        <p>
         As the Performance Schema collects data, memory is
              allocated in the corresponding buffer. The buffer size is
              unbounded, and may grow with the load.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <p>
      With the value set to 0:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         The corresponding internal buffer is empty initially and
              no memory is allocated.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <p>
      With the value set to
      <em class="replaceable">
       <code>
        N
       </code>
      </em>
      &gt; 0:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         The corresponding internal buffer is empty initially and
              no memory is allocated.
        </p>
       </li>
       <li class="listitem">
        <p>
         As the Performance Schema collects data, memory is
              allocated in the corresponding buffer, until the buffer
              size reaches
         <em class="replaceable">
          <code>
           N
          </code>
         </em>
         .
        </p>
       </li>
       <li class="listitem">
        <p>
         Once the buffer size reaches
         <em class="replaceable">
          <code>
           N
          </code>
         </em>
         ,
              no more memory is allocated. Data collected by the
              Performance Schema for this buffer is lost, and any
              corresponding
         <span class="quote">
          “
          <span class="quote">
           lost instance
          </span>
          ”
         </span>
         counters are
              incremented.
        </p>
       </li>
      </ul>
     </div>
    </li>
   </ul>
  </div>
  <p>
   To see how much memory the Performance Schema is using, check the
      instruments designed for that purpose. The Performance Schema
      allocates memory internally and associates each buffer with a
      dedicated instrument so that memory consumption can be traced to
      individual buffers. Instruments named with the prefix
   <code class="literal">
    memory/performance_schema/
   </code>
   expose how much
      memory is allocated for these internal buffers. The buffers are
      global to the server, so the instruments are displayed only in the
   <a class="link" href="performance-schema-memory-summary-tables.html" title="29.12.20.10 Memory Summary Tables">
    <code class="literal">
     memory_summary_global_by_event_name
    </code>
   </a>
   table, and not in other
   <code class="literal">
    memory_summary_by_
    <em class="replaceable">
     <code>
      xxx
     </code>
    </em>
    _by_event_name
   </code>
   tables.
  </p>
  <p>
   This query shows the information associated with the memory
      instruments:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa19424362"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>memory_summary_global_by_event_name
<span class="token keyword">WHERE</span> EVENT_NAME <span class="token operator">LIKE</span> <span class="token string">'memory/performance_schema/%'</span><span class="token punctuation">;</span></code></pre>
  </div>
 </div>
 <br/>
</div>
