Skip to content

Performance and Scale Tuning

Heisenbug edited this page Mar 5, 2026 · 1 revision

Home · Configuration Guide · Troubleshooting & Recovery

At a glance

  • CSF performance issues usually come from one of three places: rule volume, log/detection churn, or connection-tracking pressure.
  • The biggest wins are usually: LF_IPSET, sane deny limits, targeted detectors, and measured scan intervals.
  • Tune one subsystem at a time and validate after each change.

Related guides:

15-minute quick-start (most common wins)

If you need fast, safe improvements without deep tuning yet:

  1. Baseline current behavior (time csf -ra, rule/list size, recent lfd.log).
  2. Enable and validate IPSET support (csftest.pl, then LF_IPSET=1 if supported).
  3. Keep deny limits bounded (DENY_IP_LIMIT, DENY_TEMP_IP_LIMIT).
  4. Leave CT_LIMIT=0 unless you have a clear abuse pattern and scoped plan.
  5. Reload and compare baseline vs after-state.

Performance model (what actually gets slow)

1) Rule-application and reload time

Slows down when:

  • csf.deny / temp deny lists grow large
  • large CC / blocklist feeds are loaded as classic iptables rules
  • frequent restarts/reloads happen under heavy change

Primary controls:

  • LF_IPSET
  • LF_IPSET_HASHSIZE
  • LF_IPSET_MAXELEM
  • DENY_IP_LIMIT
  • DENY_TEMP_IP_LIMIT
  • FASTSTART
  • CC_DROP_CIDR

2) Detection/parsing overhead in LFD

Slows down when:

  • too many noisy detectors are enabled simultaneously
  • LF_PARSE is very aggressive
  • log scanner scope is broad (many files/globs)

Primary controls:

  • LF_PARSE
  • LF_INTERVAL
  • LF_TRIGGER / application triggers
  • LOGSCANNER, LOGSCANNER_LINES, log-file scope

3) Connection-state pressure

Slows down when:

  • CT_LIMIT/tracking is enabled with broad states/ports on busy protocols
  • large numbers of TIME_WAIT states are counted

Primary controls:

  • CT_LIMIT
  • CT_PORTS
  • CT_STATES
  • CT_SKIP_TIME_WAIT
  • CT_SUBNET_LIMIT

Baseline before tuning (required)

Capture current state first:

# Rule/list size indicators
wc -l /etc/csf/csf.deny /etc/csf/csf.allow /etc/csf/csf.ignore 2>/dev/null
csf -t | wc -l

# Reload timing (run a few times and compare)
time csf -ra

# Rule footprint snapshots
iptables -S | wc -l
ip6tables -S | wc -l

# lfd signal quality
tail -n 200 /var/log/lfd.log

If using IPSET:

ipset list -t

High-impact tuning levers

A) Reduce rule-chain bloat first

Enable IPSET for large lists

First validate platform/module support:

perl /etc/csf/csftest.pl

Then configure:

LF_IPSET = "1"
LF_IPSET_HASHSIZE = "1024"
LF_IPSET_MAXELEM = "65536"

Then scale hash/maxelem gradually based on set fullness and memory.

Keep deny lists bounded

DENY_IP_LIMIT = "200"
DENY_TEMP_IP_LIMIT = "100"

Increase only with clear need and capacity headroom.

Keep FASTSTART enabled where supported

FASTSTART = "1"

This improves restart/reload behavior by using save/restore paths.

Reduce huge CC rule expansion when needed

CC_DROP_CIDR = "16"

Use only when you intentionally accept coarser CC granularity for throughput gain.

B) Tune LFD parser cadence and trigger strategy

Parse frequency

LF_PARSE = "5"
  • Lower values react faster but increase parser churn.
  • Raise carefully if CPU pressure is sustained and response latency tolerance allows.

Trigger semantics

  • LF_TRIGGER = "0" → app-specific thresholds are used directly.
  • LF_TRIGGER > "0" → cumulative threshold model (app toggles become on/off).

Choose the model that fits your noise profile and keeps false-positive pressure manageable.

Don’t over-enable noisy detectors by default

Particularly on busy shared environments, be conservative with:

  • LF_APACHE_404
  • LF_APACHE_403
  • LF_APACHE_401
  • aggressive script/queue checks without baseline

C) Scope connection tracking instead of blanket enabling

If enabling CT_LIMIT, avoid all-ports/all-states as first move.

CT_LIMIT = "300"
CT_INTERVAL = "30"
CT_PORTS = "80,443"
CT_SKIP_TIME_WAIT = "1"
CT_STATES = "SYN_RECV,ESTABLISHED"

Then tune from observed false positives.

D) Keep scanner/reporting overhead intentional

LOGSCANNER can become expensive with broad file globs.

LOGSCANNER = "0"          # or keep narrow scope
LOGSCANNER_LINES = "5000"

If enabled, restrict monitored files and ignore noisy patterns aggressively.

E) Messenger mode choice affects footprint

  • v1 HTTPS messenger can be memory-heavy on large cert/domain inventories.
  • Prefer MESSENGERV3 where supported.

Reference: Messenger Service

Recommended tuning order (production-safe)

  1. List/rule volume first (LF_IPSET, deny limits, CC scope)
  2. Detection noise second (LF_PARSE, trigger model, noisy detectors)
  3. Connection tracking third (CT_* narrowly scoped)
  4. Scanner/report extras last (LOGSCANNER, optional alerts)

After each step:

csf -ra
tail -n 100 /var/log/lfd.log

Only change one major subsystem per maintenance window. This keeps root-cause analysis simple if behavior regresses.

Profile presets (starting points)

Profile 1 — Low-memory VPS (stability-first)

FASTSTART = "1"
LF_IPSET = "1"
DENY_IP_LIMIT = "200"
DENY_TEMP_IP_LIMIT = "100"
CT_LIMIT = "0"
LOGSCANNER = "0"

Notes:

  • enable LF_IPSET only if csftest.pl confirms support on your platform/container
  • avoid broad CC deny sets unless absolutely required
  • keep detector set minimal and deliberate

Profile 2 — Busy web node behind reverse proxy

LF_IPSET = "1"
CT_LIMIT = "0"                 # start disabled, enable only with scoped ports if needed
PORTFLOOD = "443;tcp;40;5"
LF_PARSE = "5"

Notes:

  • validate real client IP restoration before aggressive auth/trigger automation
  • avoid CT_SUBNET_LIMIT for proxied ports unless architecture explicitly supports it

Profile 3 — Shared hosting/auth-heavy node

LF_IPSET = "1"
DENY_IP_LIMIT = "500"
DENY_TEMP_IP_LIMIT = "300"
LF_TRIGGER = "0"               # keep app-specific thresholds explicit initially
PT_INTERVAL = "60"
PT_USERKILL = "0"

Notes:

  • prioritize false-positive control and operational predictability
  • tune login/script thresholds with real traffic history

Warning signs and immediate mitigations

Symptom Fast triage action
csf -ra takes too long check rule/list size, enable/tune IPSET, bound deny limits
repeated lock contention/hung iptables ops evaluate WAITLOCK strategy and competing firewall tooling
high lfd CPU with noisy logs raise LF_PARSE modestly, disable/tune noisy detectors, narrow log scanner scope
many false CT blocks set CT_LIMIT=0 temporarily, then re-enable with scoped CT_PORTS/states
rule churn during DDoS-like events cap deny lists, avoid over-broad auto-blocking features, keep rollback path ready

Validation checklist after each tuning batch

  • trusted admin access still works (IPv4 + IPv6 if enabled)
  • reload time improved or at least not regressed
  • no spike in false-positive block events
  • lfd.log shows stable behavior (no repeating parser/errors)
  • temporary/permanent block lifecycle still matches policy intent

Troubleshooting references

Last reviewed: 2026-02-25


← Configuration Guide · Deployment Runbooks

Clone this wiki locally