MongoDB Java Driver Sync & Async
<p>I am currently performing some benchmarks on my application using Vert.x and I am trying to compare results when I use the mongo java sync or async driver.</p>

<p>And to my surprise, the results seems to be far better with the sync driver, because it uses really few mongodb connections compared to the async one. As a consequence, the mongo requests are slower and mongo always finished by crashing with async driver.</p>

<p>Is this normal that the async driver open so many connections compared to the sync one ? If yes, do we need to install mongo as a replica set to better scale with async driver ?</p>

<p>For example, here are results of test with wrk with 200 connections in 30 seconds with 16 threads.</p>

<p>With Sync driver:</p>

<pre><code>~ • wrk -t16 -c200 -d30s http://localhost:8080/f0e7a0f5/status
    Running 30s test @ http://localhost:8080/f0e7a0f5/status
    16 threads and 200 connections
    Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   131.90ms   42.75ms 567.64ms   78.19%
    Req/Sec    92.61     21.28   171.00     66.36%
    43997 requests in 30.10s, 3.23MB read
    Socket errors: connect 0, read 55, write 0, timeout 0
    Requests/sec:   1461.89
    Transfer/sec:    109.93KB
</code></pre>

<p>With Async driver (mongodb crashes) :</p>

<pre><code>~ • wrk -t16 -c200 -d30s http://localhost:8080/f0e7a0f5/status
    Running 30s test @ http://localhost:8080/f0e7a0f5/status
    16 threads and 200 connections
    Thread Stats   Avg      Stdev     Max   +/- Stdev
     Latency   424.87ms  205.89ms   1.38s    73.84%
     Req/Sec    31.68     20.04   118.00     64.01%
    13597 requests in 30.11s, 1.00MB read
    Socket errors: connect 0, read 31, write 0, timeout 0
    Requests/sec:    451.65
    Transfer/sec:     33.96KB
</code></pre>

<ul>
<li>MongoDB 3.2.7 WiredTiger</li>
<li>Mongo Java Driver 3.2.2</li>
<li>Vertx 3.3.1</li>
<li>Mac OS X El Capitan 2.5 Ghz I7 16 Go RAM</li>
</ul>

<p><strong>UPDATE 1</strong> : I solved the mongodb crash problem on my local machine by configuring files and process limits : <a href="https://unix.stackexchange.com/questions/108174/how-to-persist-ulimit-settings-in-osx-mavericks">https://unix.stackexchange.com/questions/108174/how-to-persist-ulimit-settings-in-osx-mavericks</a>
However, I still have many opened connections with the async driver, which slow my application.</p>

<p><strong>UPDATE 2</strong> : Here is some code with the async driver. 
The verticle : <a href="http://pastebin.com/SygKuDhg" rel="nofollow noreferrer">http://pastebin.com/SygKuDhg</a></p>

<p>The config :</p>

<pre><code>"mongo-platform" : {
        "pool_name": "mongo-platform",
        "host": "localhost",
        "port": 27017,
        "db_name": "mongo_platform",
        "maxPoolSize": 250,
        "minPoolSize": 20,
        "useObjectId": true
    }
</code></pre>

<p><strong>UPDATE 3</strong>: And here is the code for the sync driver</p>

<p><a href="http://pastebin.com/FJ7JeSPU" rel="nofollow noreferrer">http://pastebin.com/FJ7JeSPU</a></p>

<p>I use Jongo as a wrapper of the java sync driver and vertx-hk2 for dependency injection into my REST verticle.</p>