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.