What No One Told You About WiredTiger Configuration (and How It’s Devouring Your RAM)

RAM

Did you ever get that chill down your spine while monitoring your database server’s memory usage? That feeling that, no matter what you do, MongoDB insists on devouring more and more RAM, leaving your critical resources on the verge of collapse? If the answer is yes, you’re not alone. The struggle against resource consumption is a constant battle in the world of data management, and one of the most subtle and dangerous villains in this story has a name: WiredTiger.

Many IT managers, DBAs, and DevOps professionals focus on obvious optimizations, like indexes and queries. However, what most ignore is that a simple misconfiguration in WiredTiger—MongoDB’s powerful default storage engine—could be causing a silent and devastating memory leak, compromising performance, availability, and, ultimately, the financial health of your operation. This article, brought to you by HTI Tecnologia, Brazil’s leading specialist in 24/7 database support, will reveal what no one told you about configuring this engine.

Get ready. What you’re about to read might completely change how you view your database administration and, more importantly, save your project from imminent collapse.

Unraveling the WiredTiger Enigma: It’s Not Magic, It’s Engineering (and Misunderstanding)

WiredTiger is an incredibly sophisticated storage engine, designed to offer high performance and concurrency in mission-critical environments. It uses an internal cache system to manage data and indexes in RAM, which is fundamental for fast operations. The catch? Its default configuration, or a mistaken manual setup, can be a deadly trap.

Most IT professionals believe WiredTiger behaves predictably, but it hides complexities that can be fatal. The default configuration storage.wiredTiger.engineConfig.cacheSizeGB is the starting point, but just tweaking this parameter is like trying to swim in the ocean with a river map. A series of other variables, interdependencies, and best practices are ignored, and that’s when your server’s RAM starts to be mercilessly consumed.

At HTI Tecnologia, we’ve encountered scenarios where large companies lose millions in revenue due to application slowdowns, and the culprit was, most of the time, hidden in the guts of a poorly optimized WiredTiger configuration.

# Example of a basic mongod.conf configuration
# This file is usually located at /etc/mongod.conf (Linux)
# or C:\Program Files\MongoDB\Server\X.Y\bin\mongod.cfg (Windows)

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
  wiredTiger:
    engineConfig:
      # Defines the WiredTiger cache size in GB.
      # This is the most common parameter, but not the only one!
      cacheSizeGB: 16
    collectionConfig:
      # Default compression configuration for collections
      # Can be 'snappy', 'zlib', 'zstd', or 'none'
      defaultDataCompressor: snappy
    indexConfig:
      # Default compression configuration for indexes
      defaultIndexCompressor: snappy

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

processManagement:
  fork: true
  pidFilePath: /var/run/mongodb/mongod.pid

net:
  port: 27017
  bindIp: 127.0.0.1

3 Fatal WiredTiger Configuration Errors That Are Devouring Your RAM

Error #1: Underestimating the Read Rate (and the Compression Factor)

WiredTiger uses compression to store data on disk. This saves space but can increase CPU workload and, ironically, RAM consumption in some cases. Optimizing the compression_level for your specific workload is a balancing act. A common mistake is to use the default settings for everything.

Why is this a problem? A database with a high read rate (read-heavy) and very aggressive compression can suffer from an increased decompression cache, which bloats in RAM to meet demand. Through our specialized database performance consulting, HTI Tecnologia has identified and corrected this type of problem for dozens of clients, freeing up resources and restoring agility to their operations.

// Example of compression configuration in the mongod.conf file (already shown above)
// storage:
//   wiredTiger:
//     collectionConfig:
//       defaultDataCompressor: snappy // Or 'zlib', 'zstd', 'none'
//     indexConfig:
//       defaultIndexCompressor: snappy

// Example of how to create a collection with a specific compressor,
// overriding the WiredTiger default.
// This is useful for collections with different access profiles.
db.createCollection("myCollectionWithZlib", {
  storageEngine: {
    wiredTiger: {
      configString: "block_compressor=zlib" // Zlib compression for this collection
    }
  }
});

// Another example, using Snappy compression (a common and good balance)
db.createCollection("myCollectionWithSnappy", {
  storageEngine: {
    wiredTiger: {
      configString: "block_compressor=snappy"
    }
  }
});

// Example of changing the compressor for an existing collection
// WARNING: This operation can be costly and may lock the collection for writes
// for a while, depending on the size of the collection. Do this during maintenance windows.
db.runCommand({
  collMod: "anotherCollection",
  storageEngine: {
    wiredTiger: {
      configString: "block_compressor=zstd" // Changes to Zstd compression
    }
  }
});

RAM

Error #2: Ignoring eviction_trigger and eviction_target

These are crucial parameters for WiredTiger’s cache cleanup. They define when the engine should start “evicting” data from memory to free up space (eviction_trigger) and when it should stop (eviction_target). If these values are not correctly adjusted, the cache can grow uncontrollably until it hits the limit imposed by cacheSizeGB (and often, it can exceed it in practice due to other factors, like the operating system’s page cache).

What’s the risk? A very high eviction_trigger can lead to a scenario where the database only starts freeing memory when it’s already too late, drastically impacting the performance of the entire system. HTI Tecnologia’s 24/7 support monitors these parameters in real time, ensuring that your operation always has an optimized cache, without any unpleasant surprises.

// Connect to your MongoDB server using the 'mongo' or 'mongosh' shell
// Example: mongosh --port 27017

// 1. Get the general WiredTiger status
db.adminCommand({ "serverStatus": 1, "wiredTiger": 1 }).wiredTiger

// 2. Focus on cache and eviction counters
var wtStatus = db.adminCommand({ "serverStatus": 1, "wiredTiger": 1 }).wiredTiger;

print("--- WiredTiger Cache ---");
print("Maximum bytes configured: " + wtStatus.cache["maximum bytes configured"].toLocaleString() + " bytes");
print("Bytes currently in the cache: " + wtStatus.cache["bytes currently in the cache"].toLocaleString() + " bytes");
print("Bytes belonging to pages currently in the cache: " + wtStatus.cache["bytes belonging to pages currently in the cache"].toLocaleString() + " bytes");
print("Percentage of cache used: " + wtStatus.cache["percentage of cache used"] + "%");

print("\n--- WiredTiger Eviction ---");
print("Pages currently queued for eviction: " + wtStatus.cache["pages currently queued for eviction"].toLocaleString());
print("Pages evicted because they were too large: " + wtStatus.cache["pages evicted because they were too large"].toLocaleString());
print("Pages evicted by application threads: " + wtStatus.cache["pages evicted by application threads"].toLocaleString());
print("Pages evicted by the LAZY_QUEUE: " + wtStatus.cache["pages evicted by the LAZY_QUEUE"].toLocaleString());
print("Pages evicted, some portion of which were dirty: " + wtStatus.cache["pages evicted, some portion of which were dirty"].toLocaleString());
print("Eviction calls that walked nothing: " + wtStatus.cache["eviction calls that walked nothing"].toLocaleString());

// To configure eviction_trigger/target via mongod.conf, they would be under:
// storage:
//   wiredTiger:
//     engineConfig:
//       eviction_trigger: 90 # Starts evicting when 90% of the cache is full
//       eviction_target: 80  # Tries to reduce it to 80% of the cache
// These values are not directly accessible via serverStatus as 'trigger' or 'target',
// but their impact is reflected in the 'pages evicted' counters.

Error #3: Not Understanding the Relationship Between cacheSizeGB and Total Server RAM

This is perhaps the most basic error, but also the most common. Many professionals define the WiredTiger cache size based on a fixed percentage of the total server RAM without considering the memory consumption of the operating system itself, the mongod process, and other applications. The result? A server that can’t breathe.

The solution? The ideal is to leave a safety margin. For example, if you have a server with 64GB of RAM, don’t allocate 48GB to WiredTiger. HTI Tecnologia recommends a holistic approach, where we analyze the total memory usage, other applications running on the server, and the database workload before defining any parameters.

free -h

ps aux --sort -rss | grep mongod

db.adminCommand({ getDiagnosticData: 1 })._data.serverStatus.mem
db.adminCommand({ getDiagnosticData: 1 })._data.serverStatus.wiredTiger.cache
RAM

Why Not Try to Solve This Alone? The Case for DBA Outsourcing with HTI Tecnologia

It’s tempting to think that you or your IT team can solve these problems. After all, the documentation is available. But the truth is that managing modern databases, like MongoDB, is a complex discipline that requires full-time dedication.

That’s why DBA outsourcing is not a luxury, but a smart business strategy for companies seeking performance, security, and availability. By hiring the expertise of HTI Tecnologia, you’re not just hiring a service; you’re:

  • Gaining Technical Focus: Your IT team can concentrate on what really matters: innovating, developing new applications, and delivering value to your business. We take care of what’s underneath, ensuring your database foundation is unshakeable.
  • Reducing Operational Risk: Database problems don’t give a warning. A WiredTiger misconfiguration can manifest months later when traffic increases. Our experts are 24/7 monitoring and acting proactively, mitigating risks before they turn into crises.
  • Ensuring Continuity: Staff turnover is a reality. The loss of an internal DBA can be catastrophic. With HTI, you have a team of specialists ready to act at any time, ensuring the continuity of your business without interruptions.

Don’t try to reinvent the wheel. The complexity of WiredTiger is just the tip of the iceberg. There is a universe of optimizations, security protocols, and best practices that only a specialized and dedicated team can master.

The Perfect Scenario: When WiredTiger Configuration and HTI Tecnologia Unite

Imagine an environment where your MongoDB database operates at its full potential. RAM usage is optimized, operations are lightning-fast, and you have the peace of mind of knowing an elite team is ensuring the availability and security of your data. This scenario isn’t a dream; it’s the reality for HTI’s clients.

We don’t just fix problems; we build robust systems. We thoroughly analyze your workload, surgically adjust every WiredTiger parameter, and implement a monitoring and support plan that ensures the long-term health of your database.

Our work goes far beyond MongoDB. We offer support and consulting for a complete ecosystem of SQL and NoSQL databases, including MySQL, MariaDB, PostgreSQL, Oracle, SQL Server, Redis, and Neo4J, proving that, in the world of data, specialization is the key to success.

To delve deeper into the challenges of data management and how outsourcing can be the answer, read our page on Data Management.

Stop Devouring Your RAM and Start Optimizing Your Operation

WiredTiger is a powerful tool, but it requires deep knowledge to be tamed. Negligence in its configuration is not just a technical problem; it’s a business problem that translates into performance loss, application slowdowns, and, at the end of the day, customer dissatisfaction and lost revenue.

Stop settling for mediocre performance and risking the security and availability of your data. HTI Tecnologia is here to help you change the game.

HTI Tecnologia invites you to take the next step toward operational excellence.

Don’t wait for the next traffic spike to turn your database into a nightmare.

Schedule a meeting now with one of our database specialists and discover how our expertise can transform your company’s performance. The solution to your WiredTiger’s rampant RAM consumption is just a click away.

Schedule a meeting here

Visit our Blog

Learn more about databases

Learn about monitoring with advanced tools

RAM

Have questions about our services? Visit our FAQ

Want to see how we’ve helped other companies? Check out what our clients say in these testimonials!

Discover the History of HTI Tecnologia

Compartilhar: