<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Does the JBM bridge uses a connection pool?
</h3>
<span style="margin-bottom: 10px;">
    reply from <a href="http://community.jboss.org/people/atijms">arjan tijms</a> in <i>JBoss Messaging</i> - <a href="http://community.jboss.org/message/549953#549953">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><blockquote class="jive-quote"><p>henk de boer wrote:</p><br/><p><span>According to an article written by Tim Fox (</span><a class="" href="http://community.jboss.org/wiki/ShouldIcacheJMSconnectionsandJMSsessions">http://community.jboss.org/wiki/ShouldIcacheJMSconnectionsandJMSsessions</a><span>) my performance "</span><em>*will suck*"</em>, if I don't use a connection pool.</p></blockquote><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I was struggeling with the same thing, and as it appears the Bridge doesn't use a connection pool, but uses a different kind of pattern so it actually doesn't really need one. This pattern is not unlike e.g. a request queue for AJAX requests in JSF 2 and RichFaces, where instead of letting each part of the code sent something on its own (with or without a connection pool), all requests are collected in a single queue and sent out in batches by a single thread.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>In fact, in our own software I have implemented the exact same pattern. We have tens to hundreds of small write requests per second, and originally we let each thread where the write request originated write to a DB directly. Of course there was a connection pool in between (for JDBC these are actually easy and actually work <span> ;) </span>). This didn't scale very well, even though a connection pool was thus used.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>So I rebuild the architecture to let all threads post their write requests to a single queue, which is read by 3 threads having a single fixed connection each to the DB, via which they sent the write requests in batches. (in case of many cores in both the client and DB and having sufficiently fast storage in the DB, we found 3 consumers for this queue to work more optimally than 1).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I scanned through the org.jboss.jms.server.bridge.Bridge code and found it basically does the following (omitting details about xa/non-xa, username/no username, etc):</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ol><li>Get source and target destinations from JNDI</li><li>Get source connection factory from JNDI<ol><li>Create connection</li><li>Create session</li><li>Create consumer(sourceDestination)</li></ol></li><li>Get target connection factory from (remote) JNDI<ol><li>Create connection</li><li>Create session</li><li>Create producer(null)</li></ol></li><li>consumer.setMessageListener(SourceListener)</li><li>SourceListener onMessage:<ol><li>Get global lock</li><li>Put message in list</li><li>If batch size reached<ol><li>For each message in list<ol><li>producer.send(targetDestination, message)</li></ol></li></ol></li></ol></li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>That's basically it. Apart from a very small hack to optimize forward_mode_xa if the source is jboss messaging, it's all just the pure and simple JMS API that's being used by the bridge. No JBoss internal magic and no JCA pools for remote connections.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Nevertheless, even in this case where the bridge uses a single fixed connection, it might be handy to have a connection pool anyway. Namely, such a pool could take care of validating that connections are still valid and destroy a connection and reconnect if needed.</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/549953#549953">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Messaging at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>