Why do spring/hibernate read-only database transactions run slower than read-write?
<p>I've been doing some research around the performance of read-only versus read-write database transactions.  The MySQL server is remote across a slow VPN link so it's easy for me to see differences between the transaction types.  This is with connection pooling which I know is working based on comparing 1st versus 2nd JDBC calls.</p>
<p>When I configure the Spring AOP to use a read-only transaction on my DAO call, the calls are 30-40% <em>slower</em> compared to read-write:</p>
<pre><code>&lt;!-- slower --&gt;
&lt;tx:method name=&quot;find*&quot; read-only=&quot;true&quot; propagation=&quot;REQUIRED&quot; /&gt;
...
// slower
@Transaction(readOnly = true)
</code></pre>
<p>Versus:</p>
<pre><code>&lt;!-- faster --&gt;
&lt;tx:method name=&quot;find*&quot; read-only=&quot;false&quot; propagation=&quot;REQUIRED&quot; /&gt;
...
// faster
@Transaction
</code></pre>
<p>Looking at tcpdump, it seems like the read-only transaction is doing more back and forth talking to MySQL.  Here's the <a href="http://pastebin.com/1u2Vh0au" rel="nofollow noreferrer">read-only dump</a> versus <a href="http://pastebin.com/Trc0jRqM" rel="nofollow noreferrer">read-write</a>.</p>
<ol>
<li><p>Can anyone explain why the read-only calls are taking longer?  Is this expected?</p>
</li>
<li><p>Is there anything I'm doing wrong or anything that I can do to improve their speed aside from improving the network?  Just found this awesome post with some <a href="http://blog.cyclopsgroup.org/2011/03/1300ms-to-160ms-tune-springhibernate-on.html" rel="nofollow noreferrer">good performance recommendations</a>.  Any other comments?</p>
</li>
</ol>
<p>Thanks much.</p>