CodeBlanks Logo Icon CodeBlanks

Production tuning

Learn production tuning and Node.js flags.

Production tuning

Production tuning is the set of adjustments that keep a Node.js application at its best in production. Memory uses --max-old-space-size, CPU uses flame graphs, GC uses --expose-gc, and library choice belongs here too.

A tuningAdvice(issue) function models these decisions: 'memory' returns 'limit heap', 'cpu' returns 'profile flame', others return 'check flags'. Every tuning has a cost in production; a wrong flag can cause unexpected crashes. So changes ship gradually and each is followed by measurement. This simple model reduces the issue to a category and points at the right knob; in real settings each tuning needs its own experiment.

Flags and measurement

In production, measurement must precede any flag change. --max-old-space-size raises the heap ceiling but can hide a leak. --expose-gc allows manual garbage collection calls but misuse adds latency.

Example: tuningAdvice('memory') returns 'limit heap'; first cap the heap. tuningAdvice('cpu') returns 'profile flame'; find the bottleneck with a flame graph. No single setting stands alone; each must be tested under the real workload that runs the app. This is why good teams ship settings through an experiment-measure-compare loop. Even a correct flag can cause trouble if applied for the wrong reason.

Practice Write the tuning advice function

Write function tuningAdvice(issue). Add if (issue === 'memory') return 'limit heap';, if (issue === 'cpu') return 'profile flame'; and return 'check flags';. Print console.log(tuningAdvice('memory')) and console.log(tuningAdvice('cpu')).

Starter code

index.js
// Write the tuningAdvice function
// Return 'limit heap' for 'memory', 'profile flame' for 'cpu', 'check flags' otherwise
// Print calls with 'memory' and 'cpu'
// write here

Sample solution

index.js
function tuningAdvice(issue) {
  if (issue === 'memory') return 'limit heap';
  if (issue === 'cpu') return 'profile flame';
  return 'check flags';
}
console.log(tuningAdvice('memory'));
console.log(tuningAdvice('cpu'));

Expected output

limit heap
profile flame

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Complete the memory branch

Question
if (issue === 'memory') return '____';
Answer
if (issue === 'memory') return 'limit heap';

Explanation: memory returns 'limit heap'.

2 What does tuningAdvice return for a CPU bottleneck?

index.js
tuningAdvice('cpu')
  • limit heap
  • check flags
  • profile flame Correct answer
  • more memory

Explanation: cpu returns 'profile flame'; a flame graph shows the bottleneck.

3 Match each piece to its role

Term Meaning
memory limit heap
cpu profile flame
--max-old-space-size Heap ceiling
--expose-gc Manual GC

All lessons in Expert