Throttle

2 snippets across 2 stacks - Docker, JavaScript

DKDocker

CPU Limit (--cpus)

DK · Run Options
Syntax
docker run --cpus <number> <image>
Example
docker run -d --cpus 1.5 --name worker myapp:1.0
docker run -d --cpus 0.5 --name background-job myapp:1.0

Note The value represents CPU cores (1.5 means one and a half cores). This is a soft limit via CFS scheduling, not a hard reservation. The container can still burst briefly if the host is idle.

JSJavaScript

Throttle

JS · Common Patterns
Syntax
function throttle(fn, interval) { ... }
Example
function throttle(fn, interval) {
  let lastTime = 0;
  return function (...args) {
    const now = Date.now();
    if (now - lastTime >= interval) {
      lastTime = now;
      fn.apply(this, args);
    }
  };
}

// Usage: fire at most once per 200ms during scroll
window.addEventListener("scroll",
  throttle(() => {
    console.log("Scroll position:", window.scrollY);
  }, 200)
);

Note Throttling ensures a function runs at most once per interval, even if triggered constantly. Use for scroll, mousemove, and resize events.

Frequently asked questions

How does Docker handle throttle?
This task is covered in 2 stacks on this page: Docker, JavaScript. The "CPU Limit (--cpus)" snippet in Docker uses `docker run --cpus <number> <image>`.
Which command does the Docker example use?
The "CPU Limit (--cpus)" snippet uses `docker run --cpus <number> <image>`, from the Run Options section of the Docker cheat sheet.
Which stacks cover "throttle" on this page?
Docker, JavaScript. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "CPU Limit (--cpus)": The value represents CPU cores (1.5 means one and a half cores). This is a soft limit via CFS scheduling, not a hard reservation. The container can still burst briefly if the host is idle.