Performance Comparison: v5.1.x vs v6.x

Benchmarked on MongoDB 8.2, 3-node replica set, January 2026


Executive Summary

Aspectv5.1.x → v6.xImprovement
Connection PoolGlobal lock → Per-host locking+38% throughput
MessagingImproved threading & lock handlingBetter under load
$in QueriesSame (MongoDB indexed)~8% faster
SSL/TLSNot available → Full support✅ New feature

Real Benchmark Results

v5.1.9 vs v6.x (MongoDB Cluster)

Benchmarkv5.1.9v6.xImprovement
Connection Pool (20 threads × 100 ops)22,869 ops/sec31,642 ops/sec+38%
Messaging (500 msgs, default settings)10 msgs/sec*21 msgs/sec+110%
$in Query (500 values, indexed)3.40 ms3.14 ms+8%
Bulk Writes (10K docs)43,544 docs/sec38,219 docs/sec-12%**

*v5 messaging hit timeout (345/500 received) — may indicate stability issues under load. **Bulk write difference under investigation.

Messaging Performance by Backend

BackendThroughputLatencyvs MongoDB
MongoDB (3-node replica set)89 msgs/sec11.28 ms1x
MorphiumServer223 msgs/sec4.47 ms2.5x faster
InMemory Driver (direct)281 msgs/sec3.56 ms3.2x faster

Key insight: MorphiumServer is 2.5x faster than real MongoDB for messaging tests!

$in Query: Indexed vs Non-Indexed

FieldMongoDBInMemory
Indexed (counter, 500 values)5.52 ms81.30 ms
Non-indexed (category, 50 values)10.39 ms16.60 ms

MongoDB indexes make a huge difference. InMemory shows O(n×m) behavior without indexes.


Architecture Improvements

PooledDriver: Per-Host Locking

v5.1.x:

// Global synchronized blocks - all hosts blocked
private synchronized MongoConnection borrowConnection(String host) {
    synchronized (connectionPool) { ... }
}

v6.x:

// Per-host isolation with modern concurrency
private final Map<String, Host> hosts = new ConcurrentHashMap<>();

class Host {
    private final BlockingQueue<ConnectionContainer> pool;
    private final AtomicInteger borrowedConnections;
}

Result: Operations on different hosts don't block each other.

Messaging Improvements

Both v5 and v6 use ChangeStream, but v6 has:

  • Better thread pool management — Configurable core/max sizes
  • Improved resume token handling — More reliable after disconnects
  • Lock optimizations — Less contention in message processing
  • Java 21 threading — Ready for virtual threads

Result: Better throughput with optimized settings.


MorphiumServer for Testing

MorphiumServer provides a MongoDB-compatible server backed by InMemoryDriver:

FeatureBenefit
No MongoDB requiredCI/CD without Docker
2.5x faster messagingFaster test suites
Full wire protocolDrop-in replacement
Clustering supportTest replica set scenarios

Quick Start

# Start server
mvn exec:java -Dexec.mainClass="de.caluga.morphium.server.MorphiumServerCLI" \
    -Dexec.args="-p 17017"

# Connect Morphium
MorphiumConfig cfg = new MorphiumConfig();
cfg.addHostToSeed("localhost:17017");
cfg.setDatabase("test");
Morphium m = new Morphium(cfg);

InMemory vs MongoDB: When to Use What

Use CaseRecommendation
Unit testsInMemory Driver (fastest)
Integration testsMorphiumServer (realistic + fast)
Load testingReal MongoDB (production-like)
CI/CD pipelinesMorphiumServer (no dependencies)

InMemory Driver Limitations

  • No real indexes (full collection scan)
  • $in queries are O(n×m) not O(n+m)
  • No persistence across restarts

Tuning Messaging Performance

Default settings are conservative. For high-throughput:

// Optimized settings
SingleCollectionMessaging messaging = new SingleCollectionMessaging(
    morphium,
    10,      // pause: 10ms (default: 100ms)
    true,    // multithreaded
    100      // windowSize (default: 10)
);
SettingDefaultOptimizedEffect
pause100ms10msLower latency
multithreadedfalsetrueParallel processing
windowSize10100Batch efficiency

Migration Checklist

Upgrading from v5.1.x to v6.x:

  • [ ] Java 21 required
  • [ ] Update MessagingSingleCollectionMessaging
  • [ ] Review messaging settings for optimal performance
  • [ ] Enable SSL/TLS for production (new in v6!)
  • [ ] Consider MorphiumServer for tests

See Migration Guide v5→v6 for details.


Benchmarks run on Mac Studio M2 Ultra, MongoDB 8.2.4, Morphium 6.1.8-SNAPSHOT

← Back to Documentation Hub