<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="innodb-performance-spin_lock_polling">
      </a>
      17.8.8 Configuring Spin Lock Polling
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045162606960">
  </a>
  <a class="indexterm" name="idm46045162605888">
  </a>
  <a class="indexterm" name="idm46045162604816">
  </a>
  <p>
   <code class="literal">
    InnoDB
   </code>
   <a class="link" href="glossary.html#glos_mutex" title="mutex">
    mutexes
   </a>
   and
   <a class="link" href="glossary.html#glos_rw_lock" title="rw-lock">
    rw-locks
   </a>
   are typically
      reserved for short intervals. On a multi-core system, it can be
      more efficient for a thread to continuously check if it can
      acquire a mutex or rw-lock for a period of time before it sleeps.
      If the mutex or rw-lock becomes available during this period, the
      thread can continue immediately, in the same time slice. However,
      too-frequent polling of a shared object such as a mutex or rw-lock
      by multiple threads can cause
   <span class="quote">
    “
    <span class="quote">
     cache ping pong
    </span>
    ”
   </span>
   ,
      which results in processors invalidating portions of each
      other's cache.
   <code class="literal">
    InnoDB
   </code>
   minimizes this issue
      by forcing a random delay between polls to desynchronize polling
      activity. The random delay is implemented as a spin-wait loop.
  </p>
  <p>
   The duration of a spin-wait loop is determined by the number of
      PAUSE instructions that occur in the loop. That number is
      generated by randomly selecting an integer ranging from 0 up to
      but not including the
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_delay">
    <code class="literal">
     innodb_spin_wait_delay
    </code>
   </a>
   value, and
      multiplying that value by 50. For example, an integer is randomly
      selected from the following range for an
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_delay">
    <code class="literal">
     innodb_spin_wait_delay
    </code>
   </a>
   setting of
      6:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa5189075"><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">{0,1,2,3,4,5}</code></pre>
  </div>
  <p>
   The selected integer is multiplied by 50, resulting in one of six
      possible PAUSE instruction values:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa91577559"><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">{0,50,100,150,200,250}</code></pre>
  </div>
  <p>
   For that set of values, 250 is the maximum number of PAUSE
      instructions that can occur in a spin-wait loop. An
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_delay">
    <code class="literal">
     innodb_spin_wait_delay
    </code>
   </a>
   setting of
      5 results in a set of five possible values
   <code class="literal">
    {0,50,100,150,200}
   </code>
   , where 200 is the maximum
      number of PAUSE instructions, and so on. In this way, the
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_delay">
    <code class="literal">
     innodb_spin_wait_delay
    </code>
   </a>
   setting
      controls the maximum delay between spin lock polls.
  </p>
  <p>
   On a system where all processor cores share a fast cache memory,
      you might reduce the maximum delay or disable the busy loop
      altogether by setting
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_delay">
    <code class="literal">
     innodb_spin_wait_delay=0
    </code>
   </a>
   . On a
      system with multiple processor chips, the effect of cache
      invalidation can be more significant and you might increase the
      maximum delay.
  </p>
  <p>
   In the 100MHz Pentium era, an
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_delay">
    <code class="literal">
     innodb_spin_wait_delay
    </code>
   </a>
   unit was
      calibrated to be equivalent to one microsecond. That time
      equivalence did not hold, but PAUSE instruction duration remained
      fairly constant in terms of processor cycles relative to other CPU
      instructions until the introduction of the Skylake generation of
      processors, which have a comparatively longer PAUSE instruction.
      The
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_pause_multiplier">
    <code class="literal">
     innodb_spin_wait_pause_multiplier
    </code>
   </a>
   variable provides a way to account for differences in PAUSE
      instruction duration.
  </p>
  <p>
   The
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_pause_multiplier">
    <code class="literal">
     innodb_spin_wait_pause_multiplier
    </code>
   </a>
   variable controls the size of PAUSE instruction values. For
      example, assuming an
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_delay">
    <code class="literal">
     innodb_spin_wait_delay
    </code>
   </a>
   setting of
      6, decreasing the
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_pause_multiplier">
    <code class="literal">
     innodb_spin_wait_pause_multiplier
    </code>
   </a>
   value from 50 (the default and previously hardcoded value) to 5
      generates a set of smaller PAUSE instruction values:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa1226579"><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">{0,5,10,15,20,25}</code></pre>
  </div>
  <p>
   The ability to increase or decrease PAUSE instruction values
      permits fine tuning
   <code class="literal">
    InnoDB
   </code>
   for different
      processor architectures. Smaller PAUSE instruction values would be
      appropriate for processor architectures with a comparatively
      longer PAUSE instruction, for example.
  </p>
  <p>
   The
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_delay">
    <code class="literal">
     innodb_spin_wait_delay
    </code>
   </a>
   and
   <a class="link" href="innodb-parameters.html#sysvar_innodb_spin_wait_pause_multiplier">
    <code class="literal">
     innodb_spin_wait_pause_multiplier
    </code>
   </a>
   variables are dynamic. They can be specified in a MySQL option
      file or modified at runtime using a
   <a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment">
    <code class="literal">
     SET GLOBAL
    </code>
   </a>
   statement. Modifying the variables at runtime requires privileges
      sufficient to set global system variables. See
   <a class="xref" href="system-variable-privileges.html" title="7.1.9.1 System Variable Privileges">
    Section 7.1.9.1, “System Variable Privileges”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
