← Couchbase memory quota calculator

How the Couchbase calculator works

This page walks through every number the Couchbase calculator produces: the formula, where each constant comes from, the checks behind each warning, and the commands it writes. Statements backed by Couchbase's documentation end with a Couchbase docs link to the page that says so. Where the calculator has to fill a gap the documentation leaves, the choice is explained and marked Assumption, which links to the table of all of them.

01 Two levels of quota

Couchbase doesn't have one memory limit. It has two levels of quota, nested inside the node's RAM (Memory):

  • Service quotas, per node. The Data, Index, Search, Eventing and Analytics services each get a quota that applies on every node running that service. The Query service has no quota: it uses whatever memory the operating system has left.
  • Bucket quotas, also per node. Each bucket gets a quota taken out of the Data service's on every Data node, so all bucket quotas together must fit in the Data quota. Couchbase's ramQuota and --bucket-ramsize are both MiB per node. Couchbase docs

The calculator works from the inside out: it sizes each bucket from its data (step 1), adds them up into the Data quota (step 2), adds the other services (step 3), and checks the total against the node's RAM (step 4).

02 Step 1 — each bucket's quota

The bucket quota is Couchbase's own Data service sizing formula, from the Sizing Guidelines, applied to one bucket at a time Couchbase docs, then spread over the Data nodes, since a bucket's quota is set per node:

copies    = 1 + replicas
metadata  = documents × (56 bytes + key length) × copies
dataset   = documents × document size × copies
working   = dataset × working set %
need      = (metadata + working) × (1 + 25%) ÷ 85%      the whole cluster
quota     = need ÷ Data nodes                           per node
TermValueWhere it comes from
Metadata per document56 bytesSizing Guidelines (metadata_per_document). Every document's key and metadata take this much plus the key itself. Couchbase docs
Overhead25%Sizing Guidelines (overhead_percentage): memory the bucket uses beyond the metadata and working set the formula counts. The guide gives one figure; you can change it, and the other two, under Values you can change. Couchbase docs
High-water mark85%Sizing Guidelines and Memory: once a bucket's memory use reaches 85% of its quota, Couchbase starts ejecting items. Dividing by 0.85 keeps the working set below that line. Couchbase docs
Replicas0–3Every replica is a full extra copy of the bucket's data and metadata, held in the same quota. bucket-edit accepts 0 to 3. Couchbase docs
Working set %Your inputThe share of the data you want served from RAM. Higher means fewer disk reads and a bigger quota.
Key length, document sizeYour inputAverages you supply from a sample of real documents. Nothing in the metrics or REST APIs gives them reliably, so the calculator never guesses them. Assumption

The formula, and the 10% minimum it's checked against, are written for the Couchstore storage engine, so the calculator assumes buckets use it. Magma buckets can run with much less memory. Assumption

Rounding

Couchbase takes quotas in whole MiB (is in mebibytes), so the result is rounded up to the next whole MiB and no further. A bucket can't have less than 100 MiB per node, so smaller results are raised to 100 MiB. Couchbase docs

Worked example

One bucket with 1,000,000 documents, 36-byte keys (a UUID), 1 KiB documents, 1 replica, 20% working set and value ejection, on 3 Data nodes:

copies1 + 12
metadata1,000,000 × (56 + 36) B × 2 = 184,000,000 B175.48 MiB
dataset1,000,000 × 1,024 B × 2 = 2,048,000,000 B1,953.13 MiB
working1,953.13 MiB × 20%390.63 MiB
metadata + working175.48 + 390.63566.10 MiB
× (1 + 25%)566.10 × 1.25707.63 MiB
÷ 85%707.63 ÷ 0.85, for the whole cluster832.50 MiB
÷ Data nodes832.50 ÷ 3277.50 MiB
bucket quotarounded up to a whole MiB, per node278 MiB

Notice that metadata is almost a third of what's in RAM here, even though it's under a tenth of the data. With value ejection all of it stays in memory however small the working set is, which is why buckets with many small documents need more RAM than their size suggests.

03 Step 2 — the Data quota per node

Data quota per node = sum of bucket quotas   (at least 256 MiB)

Bucket quotas and the Data quota are both per node, and every bucket's quota comes out of the Data quota on each Data node, so the Data quota is the bucket quotas added up; Couchbase refuses a bucket quota that doesn't fit. Step 1 already divided each bucket's need by the Data nodes, the way the Sizing Guidelines do it the other way round: number of nodes = cluster RAM quota required ÷ per-node RAM quota. The Data service needs at least 256 MiB. Couchbase docs

This assumes a bucket's data spreads evenly over the Data nodes. Couchbase distributes a bucket's vBuckets across them, so after a rebalance that holds closely; a cluster that hasn't been rebalanced may be uneven. Assumption

Worked example: the one bucket's 278 MiB is the whole Data quota, 278 MiB per node.

04 Step 3 — the other services

The Index, Search, Eventing and Analytics quotas are the values you enter, not calculated. How much memory an index needs depends on the index definitions and the shape of the documents, which a few form fields can't describe; an estimate would look more authoritative than it is. 0 means the service doesn't run on these nodes. Assumption

A service that runs needs at least 256 MiB (Index, Search, Eventing) or 1024 MiB (Analytics); below that the calculator shows an error. Couchbase docs

05 Step 4 — do the quotas fit the node?

The quotas of every service on a node are added up and compared with the node's RAM, against two limits.

LimitRuleResult in the calculator
Firm limit max(RAM − 1 GiB, 80% × RAM) Error: Couchbase refuses quotas above this. Couchbase docs
Recommended share 90% of RAM, or 80% on nodes with little memory Warning: it leaves too little for the OS, its file cache and the Query service. Couchbase docs

Both rules come from Memory. The documentation doesn't say what "little memory" means. The calculator uses under 5 GiB: below that, 80% of RAM is already more than RAM − 1 GiB, so the firm limit itself is 80% and the two rules agree. Assumption

Worked example, on a 16 GiB node with a 512 MiB Index quota: 278 + 512 = 790 MiB, 4.8% of 16,384 MiB. The firm limit is 15,360 MiB and the recommended share 14,746 MiB, so there's no warning.

06 Value ejection and full ejection

When a bucket nears its quota, Couchbase ejects documents from memory Couchbase docs:

  • Value ejection (the default) removes a document's value but keeps its key and metadata in memory.
  • Full ejection removes the whole document, key and metadata included.

The sizing formula has no separate case for full ejection. Since full ejection evicts a document's metadata together with its value, the calculator counts metadata only for the documents that stay resident: metadata × working set %, instead of all of it. That follows from the documented behaviour, but the documentation doesn't spell it out as a formula. Assumption

Same bucket, 10% working setMetadata countedBucket quota
Value ejection175.48 MiB (all)546 MiB
Full ejection17.55 MiB (10%)314 MiB

The smaller quota has a cost. With full ejection, reading a document that isn't in memory, or checking whether a key exists, has to go to disk, where value ejection could answer from the metadata in RAM (Couchbase blog: Value-Only Ejection vs. Full Ejection). That's why the calculator warns when a full-ejection bucket keeps under 20% in RAM. Changing a bucket's ejection policy restarts the bucket, so the calculator's commands never change it.

07 Every warning, and why

Message aboutShown whenBasis
Quotas above the firm limit errorThe node's quotas total more than max(RAM − 1 GiB, 80% × RAM)Couchbase refuses them. Couchbase docs
Quotas above the recommended share warningAbove 90% of RAM (80% under 5 GiB)Couchbase's recommendation. Couchbase docs The 5 GiB line is ours. Assumption
Service quota below its minimum errorIndex, Search or Eventing under 256 MiB, Analytics under 1024 MiBCouchbase's minimums. Couchbase docs
Bucket raised to the minimum warningA bucket's result is under 100 MiB per nodeThe --bucket-ramsize minimum. Couchbase docs
Bucket quota under 10% of its dataset warningThe quota on all Data nodes together is less than 10% of the bucket's data, replicas includedCouchbase recommends at least 10% for Couchstore, 1% for Magma. Couchbase docs Comparing against the data with replicas is our reading: the docs say "dataset size" without defining it. Assumption
Full ejection with a small working set warningFull ejection and a working set under 20%The disk reads are documented behaviour; the 20% threshold is ours. Assumption

08 What a paste fills in

Paste mode reads three kinds of output, detects which it is, and fills in only what that output contains, so you can paste one after another. Anything it can't know stays as you entered it.

SourceFills inNotes
GET /pools/default/buckets Bucket names, document count (basicStats.itemCount), replicas, ejection policy; shows the current quota per node (quota.rawRAM) Ephemeral and Memcached buckets are skipped: they don't use this formula. itemCount is read as the number of documents without replicas; the documentation shows the field but doesn't define it. Assumption
GET /pools/default Data nodes, RAM per node, Index/Search/Eventing/Analytics quotas Data nodes are the nodes listing the kv service; RAM is the smallest Data node's systemStats.mem_total, so the result fits every node. A service no node runs gets 0. Assumption
Prometheus: kv_curr_items, from a node's /metrics or a Prometheus query Document count per bucket; shows the current quota per node from kv_ep_cache_size, the same on every node kv_curr_items counts items in active vBuckets, so one value per node is summed. Couchbase docs A node's own /metrics has no instance label, so identical lines there are read as different nodes and added up, and the feedback says how many nodes the count covers; paste every Data node's output. An aggregated query such as sum by (bucket) (kv_curr_items) drops the metric name and is read as the item count. For range data, each node's peak is used. Metrics don't include replicas or ejection policy. Assumption

09 The commands

For the worked example, the calculator writes:

# Raising quotas: run these in order. Lowering them: run the bucket-edit lines first, since Couchbase refuses a Data quota below the bucket quotas already set.
couchbase-cli setting-cluster -c localhost:8091 -u Administrator -p "$CB_PASSWORD" \
  --cluster-ramsize 278 \
  --cluster-index-ramsize 512
couchbase-cli bucket-edit -c localhost:8091 -u Administrator -p "$CB_PASSWORD" --bucket orders --bucket-ramsize 278
  • setting-cluster sets the service quotas, in MiB. Only services that run get a flag: the CLI requires a quota for a service that's enabled. The CLI reference describes --cluster-ramsize as the Data quota "for future nodes", so check on a running cluster that it changed, or use the REST call below.
  • bucket-edit sets each bucket's quota. It only changes buckets that already exist (create new ones with bucket-create), and it can't lower a quota below what the bucket currently uses.
  • The order matters. Couchbase refuses a Data quota below the bucket quotas already set, and a bucket quota above the Data quota. When the quotas grow, set the Data quota first; when they shrink, edit the buckets first. The calculator doesn't know the current quotas, so the first line of the snippet, a shell comment, says so.
  • Bucket names follow Couchbase's rule: letters, digits, ., _, % and -, up to 100 characters. The calculator rejects any other name, so the commands, which don't quote the name, are safe to run as written.
  • The same service quotas through the REST API, POST /pools/default with memoryQuota, indexMemoryQuota, ftsMemoryQuota, eventingMemoryQuota and cbasMemoryQuota.

The password comes from a $CB_PASSWORD environment variable, so it never ends up in your shell history.

10 All assumptions in one place

Everything the calculator decides that Couchbase's documentation doesn't, and what changes if it's wrong for you.

Our default: a value we chose. Our reading: how we read documentation that isn't explicit. About your setup: something we take for granted about your data or cluster.

AssumptionKindWhyIf it doesn't hold
Full ejection counts only resident metadata ↩Our readingFull ejection evicts metadata with the document; the formula has no case for itQuotas for full-ejection buckets are too small. Set the policy to value ejection in the form to get the formula's upper bound.
Key and document sizes are the averages you enter ↩About your setupNo API gives them reliablyThe quota scales with them; measure a real sample.
Index, Search, Eventing, Analytics quotas are entered, not calculated ↩Our defaultThey depend on index definitions and document shapeSize them from the services' own memory use.
Buckets spread evenly over the Data nodes ↩About your setupvBuckets are distributed across nodesA node holding more than its share needs a larger Data quota; rebalance first.
"Little memory" means under 5 GiB ↩Our readingWhere the firm limit itself drops to 80%Only the warning threshold moves; the firm-limit error is exact.
The 10% check uses the data with replicas ↩Our readingThe bucket quota also holds the replicasOnly the warning moves.
Full ejection warns under a 20% working set ↩Our defaultA judgment call on when disk reads dominateOnly the warning moves.
itemCount counts documents without replicas ↩Our readingThe documentation shows the field without defining itIf it included replicas, pasted counts would be too high and quotas oversized.
Peak per node for Prometheus range data; smallest Data node's RAM ↩Our defaultSize for the worst caseQuotas are a little larger than an average would give.
Couchstore, not Magma ↩About your setupThe 10% guidance and the formula are written for itMagma buckets can run with much less memory (1% of the dataset); this sizing is conservative for them.

Values you can change

The calculator’s Advanced: sizing defaults and thresholds section, closed by default, lets you replace these values when your setup differs. Each field’s “?” says how it moves the result; a value outside the range is used at its nearest end, and “Reset to defaults” puts them all back.

ValueDefaultRangeWhere the default comes from
Metadata per document56 bytes0–256 bytesCouchbase’s sizing guidelines (metadata_per_document)
Overhead25%0–100%Couchbase’s sizing guidelines (overhead_percentage)
High-water mark85%50–99%Couchbase’s default; use the bucket’s own if you changed it
Storage engineCouchstoreCouchstore or MagmaAssumption 10; only moves the 10% (Magma: 1%) dataset warning
Small node below5 GiB1–64 GiBOur reading of “little memory”, assumption 5; only moves the 90%/80% warning
Full-ejection warning below20%1–100%Our threshold, assumption 7; only moves the warning

Minimums and defaults can change between Couchbase Server versions; check yours before applying a result.

11 References

← Back to the Couchbase calculator