title: MySQL Insert Query Randomly Takes a Long Time
body: <p>I am using MySQL to manage session data for my PHP application. When testing the app, it is usually very quick and responsive. However, seemingly randomly the response will stall before finally completing after a few seconds. I have narrowed the problem down to the session write query which looks something like this:</p>
  
  <pre><code>INSERT INTO Session VALUES('lvg0p9peb1vd55tue9nvh460a7', '1275704013', '') ON DUPLICATE KEY UPDATE sessAccess='1275704013',sessData='';
  </code></pre>
  
  <p>The slow query log has this information:</p>
  
  <pre><code>Query_time: 0.524446  Lock_time: 0.000046 Rows_sent: 0  Rows_examined: 0
  </code></pre>
  
  <p>This happens about 1 out of every 10 times. The query usually only takes ~0.0044 sec.</p>
  
  <p>The table is InnoDB with about 60 rows. sessId is the primary key with a BTREE index.</p>
  
  <p>Since this is accessed on every page view, it is clearly not an acceptable execution time. Why is this happening?</p>
  
  <p><strong>Update:</strong> Table schema is: sessId:varchar(32), sessAccess:int(10), sessData:text</p>