Skip to content

Howto Tune difficulty and clearance lifetime

github-actions[bot] edited this page Nov 27, 2026 · 2 revisions

How to tune difficulty and clearance lifetime

Two numbers set the price of your site: how much work one clearance costs, and how long it lasts.

Difficulty

pow_gate_difficulty N is the expected number of hashes per solve. Cost is linear in N — for the attacker and for the honest visitor alike.

N Typical wait on a laptop Use when
50000 (default) imperceptible light deterrence only
500000 ~0.1–0.5 s sensible starting point
2000000 ~0.5–2 s active scraping, some human delay is acceptable
10000000+ several seconds targeted abuse; slow devices will complain

The solver hashes on all cores through Web Workers. A low-end phone is roughly ten times slower than a laptop, so test your choice on the slowest device you care about. The compiled-in default of 50000 is low for the current solver — set the value explicitly.

Raise the price for suspicious clients only, instead of for everyone: Block or slow down crawlers.

Raise it only while the server is busy

$pow_gate_load is the one-minute load average as a percentage of the CPUs (100 = all busy). Map it to a multiplier:

map $pow_gate_load $pow_scale {
    default                  1;
    ~^(1[5-9]\d|2\d\d)$     2;     # 150–299 %
    "~^([3-9]\d\d|\d{4,})$" 4;     # 300 % and up
}

location / {
    pow_gate                  on;
    pow_gate_difficulty       500000;
    pow_gate_difficulty_scale $pow_scale;
}

The multiplier applies to new challenges only. Visitors who are already cleared are not challenged again when load rises. A complete include is in examples/load-adaptive.conf.

Solves are much slower than the table

A Content-Security-Policy that does not allow worker-src 'self' stops the solver from starting workers. It still works, on one core. The browser console shows the CSP violation.

Clearance lifetime

pow_gate_clearance_ttl (default 12h) is how long one solve lasts.

  • Shorter: a scraper pays more often — and so do your visitors.
  • Longer: fewer challenges, and a longer free ride after one solve.

Lowering the value also shortens clearances that were already issued.

Address binding

A clearance is bound to the exact client address, the User-Agent and the policy. A visitor whose address changes solves again. If your audience moves between addresses a lot — mobile networks, IPv6 privacy addresses — widen the binding:

pow_gate_ipv6_prefix 64;    # default 128
pow_gate_ipv4_prefix 32;    # default 32

Everyone inside the prefix then shares the same address binding, so do not go wider than you need. Changing a prefix renames the cookie; clients solve once more.

Invalidate everything on purpose

  • Change pow_gate_policy <name> to drop the clearances of that scope.
  • Replace the HMAC key to drop all of them.

Measure before and after

Log $pow_gate_result and $pow_gate_difficulty (Read the gate logs) and compare issued (challenges fetched) with accepted (challenges solved). Many fetched and few solved means clients give up or run out of time — on real browsers, a sign the difficulty is too high for their devices.

Reference: configuration.md › Tuning.

Clone this wiki locally