{"id":13740,"date":"2026-01-07T10:19:09","date_gmt":"2026-01-07T04:49:09","guid":{"rendered":"https:\/\/www.youstable.com\/blog\/?p=13740"},"modified":"2026-01-07T10:19:12","modified_gmt":"2026-01-07T04:49:12","slug":"how-to-optimize-mongodb-on-linux-server","status":"publish","type":"post","link":"https:\/\/www.youstable.com\/blog\/how-to-optimize-mongodb-on-linux-server","title":{"rendered":"How to Optimize MongoDB on Linux Server &#8211; Easy Guide"},"content":{"rendered":"\n<p><strong>How to Optimize MongoDB on Linux Server: <\/strong>start by tuning the OS (XFS filesystem, disable Transparent Huge Pages, set proper ulimit, sysctl, and NUMA), then configure mongod (WiredTiger cache, journaling, compression, security), and finally optimize schema, indexes, and queries. Monitor with mongostat\/mongotop and Linux tools, and scale via replica sets or sharding as needed.<\/p>\n\n\n\n<p><strong>Optimizing MongoDB on a Linux server <\/strong>means balancing the operating system, MongoDB configuration, and workload design. In this guide, we\u2019ll walk through practical, production-tested steps to improve throughput, reduce latency, and keep your database stable. Whether you run MongoDB on bare metal, VM, or cloud instances, these best practices will help you extract consistent performance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"quick-optimization-checklist\"><strong>Quick Optimization Checklist<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use XFS on fast disks (NVMe SSD preferred) with appropriate mount options.<\/li>\n\n\n\n<li>Disable Transparent Huge Pages (THP) and tune swappiness and dirty ratios.<\/li>\n\n\n\n<li>Fix NUMA behavior, <a href=\"https:\/\/www.youstable.com\/blog\/how-to-increase-file-upload-size-in-cpanel\/\">increase file<\/a> descriptors, and tune TCP\/kernel parameters.<\/li>\n\n\n\n<li>Right-size WiredTiger cache and choose the right compression (zstd\/snappy).<\/li>\n\n\n\n<li>Design schema for reads, create selective compound indexes, and avoid heavy skip\/limit.<\/li>\n\n\n\n<li>Monitor with mongostat, mongotop, and <a href=\"https:\/\/www.youstable.com\/blog\/configure-directadmin-on-linux\/\">Linux<\/a> perf tools; profile queries and use explain().<\/li>\n\n\n\n<li>Scale with replica sets and sharding as your working set grows.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"server-and-os-level-tuning-linux\"><strong>Server and OS-Level Tuning (Linux)<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"filesystem-and-disks\"><strong>Filesystem and Disks<\/strong><\/h3>\n\n\n\n<p>MongoDB recommends XFS for WiredTiger. Use fast SSDs\/NVMe. For general-purpose workloads on <a href=\"https:\/\/www.youstable.com\/blog\/configure-mongodb-on-linux\/\">Linux kernels 4.x+ and MongoDB<\/a> 4.4\u20137.x, XFS delivers excellent concurrency and predictable latency.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Disks: <\/strong>Prefer NVMe SSDs; provision adequate IOPS on cloud volumes.<\/li>\n\n\n\n<li><strong>Filesystem: <\/strong>Use XFS; ext4 is acceptable but typically slower under contention.<\/li>\n\n\n\n<li><strong>Mount options:<\/strong> noatime,nodiratime can reduce metadata writes in read-heavy workloads.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># Example: format and mount XFS\nsudo mkfs.xfs -f \/dev\/nvme0n1\nsudo mkdir -p \/var\/lib\/mongo\necho '\/dev\/nvme0n1 \/var\/lib\/mongo xfs noatime,nodiratime,inode64 0 0' | sudo tee -a \/etc\/fstab\nsudo mount -a<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"disable-transparent-huge-pages-thp\"><strong>Disable Transparent Huge Pages (THP)<\/strong><\/h3>\n\n\n\n<p>THP can cause latency spikes for databases. Disable it permanently to keep memory allocation predictable.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Temporary (until reboot)\necho never | sudo tee \/sys\/kernel\/mm\/transparent_hugepage\/enabled\necho never | sudo tee \/sys\/kernel\/mm\/transparent_hugepage\/defrag\n\n# Persistent with GRUB\nsudo sed -i 's\/GRUB_CMDLINE_LINUX=\"\/GRUB_CMDLINE_LINUX=\"transparent_hugepage=never \/' \/etc\/default\/grub\nsudo update-grub &amp;&amp; sudo reboot<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"numa-and-cpu-affinity\"><strong>NUMA and CPU Affinity<\/strong><\/h3>\n\n\n\n<p>On multi-socket servers, Non-Uniform Memory Access (NUMA) can skew memory locality. Run mongod with interleaved memory or pin it appropriately.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Systemd override to interleave memory across NUMA nodes\nsudo systemctl edit mongod\n\n# Insert:\n&#91;Service]\nExecStart=\nExecStart=\/usr\/bin\/numactl --interleave=all \/usr\/bin\/mongod --config \/etc\/mongod.conf\n\nsudo systemctl daemon-reload\nsudo systemctl restart mongod<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"kernel-readahead-and-i-o-scheduler\"><strong>Kernel, Readahead, and I\/O Scheduler<\/strong><\/h3>\n\n\n\n<p>Modern NVMe prefers the \u201cnone\u201d scheduler. Reduce readahead for random-access workloads to cut unnecessary I\/O.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Readahead (lower for random workloads)\nsudo blockdev --setra 32 \/dev\/nvme0n1\n\n# Verify current scheduler\ncat \/sys\/block\/nvme0n1\/queue\/scheduler\n# For NVMe it is often 'none' by default on newer kernels<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"ulimit-and-file-descriptors\"><strong>ulimit and File Descriptors<\/strong><\/h3>\n\n\n\n<p>MongoDB needs many file handles for connections and journal\/data files. Increase limits via systemd.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl edit mongod\n\n# Insert:\n&#91;Service]\nLimitNOFILE=100000\nLimitNPROC=64000\n\nsudo systemctl daemon-reload\nsudo systemctl restart mongod<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"sysctl-network-and-memory-tuning\"><strong>sysctl Network and Memory Tuning<\/strong><\/h3>\n\n\n\n<p>Keep swapping minimal and increase network backlog to handle bursts.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tee \/etc\/sysctl.d\/99-mongodb.conf &gt;\/dev\/null &lt;&lt;'EOF'\nvm.swappiness=1\nvm.dirty_background_ratio=5\nvm.dirty_ratio=15\nnet.core.somaxconn=1024\nnet.ipv4.tcp_fin_timeout=15\nnet.ipv4.tcp_keepalive_time=120\nEOF\n\nsudo sysctl --system<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"mongodb-configuration-mongod-conf-best-practices\"><strong>MongoDB Configuration (mongod.conf) Best Practices<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"wiredtiger-cache-and-compression\"><strong>WiredTiger Cache and Compression<\/strong><\/h3>\n\n\n\n<p>By default, WiredTiger uses about 50% of RAM minus a safety margin. If MongoDB contends with other services, set cacheSizeGB explicitly. Use zstd for balanced compression ratio and speed; snappy is faster with lower compression.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \/etc\/mongod.conf\nstorage:\n  dbPath: \/var\/lib\/mongo\n  journal:\n    enabled: true\n  wiredTiger:\n    engineConfig:\n      cacheSizeGB: 32        # Example for a 64\u201396 GB RAM server; adjust to your box\n    collectionConfig:\n      blockCompressor: zstd  # Alternatives: snappy, zlib\n\nnet:\n  bindIp: 127.0.0.1,10.0.0.10\n  port: 27017\n\nsecurity:\n  authorization: enabled\n\nsetParameter:\n  ttlMonitorSleepSecs: 60\n  failIndexKeyTooLong: true\n  diagnosticDataCollectionEnabled: true<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"journaling-write-concern-and-read-concern\"><strong>Journaling, Write Concern, and Read Concern<\/strong><\/h3>\n\n\n\n<p>Keep journaling enabled for durability. Use writeConcern and readConcern appropriate to your SLA: w:1 for speed, w:majority for strong durability across a replica set. For read-mostly apps, local or available read concerns can reduce latency; for critical reads, use majority.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"replica-set-oplog-sizing\"><strong>Replica Set Oplog Sizing<\/strong><\/h3>\n\n\n\n<p>Ensure your oplog holds several hours (often 24+ hours) of traffic to tolerate maintenance and lag. Resize during maintenance windows to avoid rollover during peak load.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Resize oplog (run on primary, MongoDB Shell)\nuse local\ndb.adminCommand({ replSetResizeOplog: 1, size: 51200 })  \/\/ ~50 GB example<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"profiling-and-slow-query-threshold\"><strong>Profiling and Slow Query Threshold<\/strong><\/h3>\n\n\n\n<p>Enable the profiler at level 1 in non-peak windows or set slowOpThresholdMs to capture problematic operations without high overhead.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># In mongosh\ndb.setProfilingLevel(1, { slowms: 100 })  \/\/ Log ops slower than 100 ms<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"schema-design-and-query-optimization\"><strong>Schema Design and Query Optimization<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"design-for-access-patterns\"><strong>Design for Access Patterns<\/strong><\/h3>\n\n\n\n<p>MongoDB performs best when documents model how your app reads data. Embed data that is read together and updated atomically; reference when subdocuments grow unbounded or are shared across many parents. Keep documents well below the 16 MB limit.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"indexing-strategy-that-scales\"><strong>Indexing Strategy That Scales<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create selective, compound indexes that match your most common query predicates and sort orders (prefix rule applies).<\/li>\n\n\n\n<li>Avoid over-indexing: each index costs RAM and write amplification.<\/li>\n\n\n\n<li>Use TTL indexes for time-based data to auto-expire old documents.<\/li>\n\n\n\n<li>Ensure unique constraints (e.g., on emails) with unique indexes.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Examples\ndb.users.createIndex({ email: 1 }, { unique: true })\ndb.orders.createIndex({ customerId: 1, createdAt: -1 })  \/\/ filter + sort\ndb.sessions.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 0 })  \/\/ TTL<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"use-explain-and-covered-queries\"><strong>Use explain() and Covered Queries<\/strong><\/h3>\n\n\n\n<p>Always inspect execution plans to confirm index usage, cardinality, and scanned vs. returned docs. Covered queries (when all fields come from the index) avoid document fetches and reduce I\/O.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Check plan and stats\ndb.orders.find(\n  { customerId: ObjectId(\"...\"), status: \"PAID\" },\n  { _id: 0, orderId: 1, total: 1 }\n).sort({ createdAt: -1 }).explain(\"executionStats\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"pagination-without-skip\"><strong>Pagination Without skip()<\/strong><\/h3>\n\n\n\n<p>Deep skip\/limit is expensive. Use range-based pagination with an indexed field (e.g., createdAt or _id).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Page 1\ndb.posts.find().sort({ _id: 1 }).limit(50)\n\n\/\/ Subsequent pages\ndb.posts.find({ _id: { $gt: ObjectId(\"last_seen_id\") } })\n        .sort({ _id: 1 }).limit(50)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"aggregation-pipeline-tips\"><strong>Aggregation Pipeline Tips<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Push $match and $project to the earliest stages to shrink <a href=\"https:\/\/www.youstable.com\/blog\/configure-zfs-on-linux\/\">data quickly<\/a>.<\/li>\n\n\n\n<li>Align $sort with an index; consider compound indexes to support $match + $sort.<\/li>\n\n\n\n<li>Use $facet carefully; it can materialize large intermediates.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"monitoring-and-troubleshooting\"><strong>Monitoring and Troubleshooting<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"mongodb-built-in-tools\"><strong>MongoDB Built-in Tools<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>mongostat: <\/strong>High-level throughput and queue metrics.<\/li>\n\n\n\n<li><strong>mongotop:<\/strong> Collection-level read\/write time distribution.<\/li>\n\n\n\n<li><strong>ServerStatus: <\/strong>In-depth metrics (wiredTiger cache, queues, connections).<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>mongostat --discover 1\nmongotop 5\nmongosh --eval 'db.serverStatus().wiredTiger.cache'<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"linux-observability-stack\"><strong>Linux Observability Stack<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>iostat, pidstat, vmstat, sar:<\/strong> Spot CPU steal, I\/O waits, run queues.<\/li>\n\n\n\n<li><strong>perf and eBPF tools:<\/strong> Pinpoint kernel-level bottlenecks and allocator stalls.<\/li>\n\n\n\n<li><strong>Cloud metrics:<\/strong> Verify disk IOPS\/throughput throttling and burst credits.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"query-profiling-and-logs\"><strong>Query Profiling and Logs<\/strong><\/h3>\n\n\n\n<p>Use the profiler and logs to find slow collections and outlier queries. Combine with explain() to decide whether to add or adjust indexes, rewrite filters, or refactor the schema.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"scaling-and-high-availability\"><strong>Scaling and High Availability<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"vertical-scale-vs-sharding\"><strong>Vertical Scale vs. Sharding<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Scale up first:<\/strong> more RAM reduces page faults and boosts cache hit rate.<\/li>\n\n\n\n<li>Shard when a single node\u2019s working set exceeds memory or you need horizontal write scale.<\/li>\n\n\n\n<li>Use hashed sharding for uniform distribution; range sharding for range queries (with zone sharding for data locality).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"replica-set-tuning\"><strong>Replica Set Tuning<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Priorities: <\/strong>Keep primary on the strongest node\/storage.<\/li>\n\n\n\n<li><strong>Hidden secondaries:<\/strong> Offload analytics without impacting primary.<\/li>\n\n\n\n<li><strong>Read preferences:<\/strong> Use nearest for geo-distributed reads when consistency allows.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"backups-and-consistency\"><strong>Backups and Consistency<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use filesystem snapshots (LVM, cloud snapshots) with fsyncLock\/fsyncUnlock for consistency.<\/li>\n\n\n\n<li>Regularly test restores; stale backups give false confidence.<\/li>\n\n\n\n<li>Consider point-in-time recovery <a href=\"https:\/\/www.youstable.com\/blog\/how-to-configure-ssh-backup-via-jetbackup-in-directadmin\/\">via oplog backups<\/a> for mission-critical data.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-by-step-linux-hardening-script-starter\"><strong>Step-by-Step Linux Hardening Script (Starter)<\/strong><\/h2>\n\n\n\n<p>Test in staging first. Values below are sane defaults for NVMe-backed servers and general OLTP workloads.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/env bash\nset -euo pipefail\n\n# 1) Disable THP (runtime)\nfor f in \/sys\/kernel\/mm\/transparent_hugepage\/enabled \/sys\/kernel\/mm\/transparent_hugepage\/defrag; do\n  &#91;&#91; -f \"$f\" ]] &amp;&amp; echo never | sudo tee \"$f\"\ndone\n\n# 2) Kernel params\nsudo tee \/etc\/sysctl.d\/99-mongodb.conf &gt;\/dev\/null &lt;&lt;'EOF'\nvm.swappiness=1\nvm.dirty_background_ratio=5\nvm.dirty_ratio=15\nnet.core.somaxconn=1024\nnet.ipv4.tcp_fin_timeout=15\nnet.ipv4.tcp_keepalive_time=120\nEOF\nsudo sysctl --system\n\n# 3) Systemd limits and NUMA interleave (if using system mongod service)\nsudo systemctl edit mongod &lt;&lt;'EOF'\n&#91;Service]\nLimitNOFILE=100000\nLimitNPROC=64000\nExecStart=\nExecStart=\/usr\/bin\/numactl --interleave=all \/usr\/bin\/mongod --config \/etc\/mongod.conf\nEOF\nsudo systemctl daemon-reload\nsudo systemctl restart mongod\n\n# 4) Reduce readahead on data device\nsudo blockdev --setra 32 \/dev\/nvme0n1 || true\n\necho \"Baseline tuning applied. Verify with: mongostat, mongotop, iostat -x, vmstat 1\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"common-pitfalls-to-avoid\"><strong>Common Pitfalls to Avoid<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Relying on ext4 on busy OLTP workloads where XFS would perform better.<\/li>\n\n\n\n<li>Leaving THP enabled and NUMA unmanaged, causing latency spikes.<\/li>\n\n\n\n<li>Over-indexing collections, wasting RAM and slowing writes.<\/li>\n\n\n\n<li>Using skip\/limit for deep pagination; switch to range-based pagination.<\/li>\n\n\n\n<li>Running with undersized oplog leading to frequent rollovers and replication lag.<\/li>\n\n\n\n<li>Choosing low-IOPS cloud disks or RAID5 for write-heavy workloads (prefer NVMe or RAID10).<\/li>\n\n\n\n<li>Ignoring slow query logs and not validating plans with explain().<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"why-host-mongodb-with-youstable\"><strong>Why Host MongoDB with YouStable<\/strong><\/h2>\n\n\n\n<p>As a <a href=\"https:\/\/www.youstable.com\/blog\/best-web-hosting-provider-in-india\/\">hosting provider<\/a> focused on databases and performance, YouStable deploys MongoDB on tuned Linux stacks: NVMe storage, XFS, THP disabled, right-sized WiredTiger cache, and proactive monitoring. Our engineers handle replica sets, backups, and security hardening so your workloads stay fast and resilient. Need a smooth migration or 24\/7 support? We\u2019re ready to help.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"faqs\"><strong>FAQ&#8217;s<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1765873109834\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \" class=\"rank-math-question \" id=\"1-what-is-the-best-filesystem-for-mongodb-on-linux\">1. <strong>What is the best filesystem for MongoDB on Linux?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>XFS is the recommended filesystem for WiredTiger because it handles concurrency and metadata updates efficiently. Ext4 works but tends to show higher write amplification under load. Pair XFS with NVMe SSDs for the best latency and throughput.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1765873122718\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \" class=\"rank-math-question \" id=\"2-how-big-should-the-wiredtiger-cache-be\">2. <strong>How big should the WiredTiger cache be?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>By default, it\u2019s roughly 50% of RAM. If the server runs only MongoDB, leave it at default. If you share the host with other services, set cacheSizeGB to avoid memory pressure. Monitor the WiredTiger cache eviction stats to refine sizing.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1765873127452\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \" class=\"rank-math-question \" id=\"3-should-i-disable-transparent-huge-pages-for-mongodb\">3. <strong>Should I disable Transparent Huge Pages for MongoDB?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes. THP can cause latency spikes due to defragmentation and allocation behavior. Disable THP and <a href=\"https:\/\/www.youstable.com\/blog\/set-up-wordpress-private-pages-and-posts\/\">set swappiness low to prevent the kernel from swapping active pages<\/a> under normal conditions.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1765873142602\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \" class=\"rank-math-question \" id=\"4-how-do-i-find-slow-queries-in-mongodb\">4. <strong>How do I find slow queries in MongoDB?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Enable the profiler with a sensible slowOpThresholdMs, review mongod logs, and run explain(&#8220;executionStats&#8221;) on candidates. Focus on queries scanning many documents, lacking index support, or performing in-memory sorts.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1765873153903\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \" class=\"rank-math-question \" id=\"5-when-should-i-shard-my-mongodb-cluster\">5. <strong>When should I shard my MongoDB cluster?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Shard when a single replica set can\u2019t hold the working set in RAM, you need horizontal write scale, or you hit vertical scaling limits (CPU, IOPS). Choose a shard <a href=\"https:\/\/www.youstable.com\/blog\/ssh-keys-vs-password-authentication\/\">key aligned with access<\/a> patterns\u2014hashed for uniform distribution, range for ordered queries with zone sharding if needed.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>How to Optimize MongoDB on Linux Server: start by tuning the OS (XFS filesystem, disable Transparent Huge Pages, set proper [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":17198,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[350],"tags":[],"class_list":["post-13740","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-knowledgebase"],"acf":[],"featured_image_src":"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2025\/12\/How-to-Optimize-MongoDB-on-Linux-Server.jpg","author_info":{"display_name":"Prahlad Prajapati","author_link":"https:\/\/www.youstable.com\/blog\/author\/prahladblog"},"_links":{"self":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/13740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/comments?post=13740"}],"version-history":[{"count":6,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/13740\/revisions"}],"predecessor-version":[{"id":17200,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/13740\/revisions\/17200"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media\/17198"}],"wp:attachment":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media?parent=13740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/categories?post=13740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/tags?post=13740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}