Skip to content

IIS: keep the first #Fields: header when the last line parses with it - #6

Merged
FMXExpress merged 1 commit into
mainfrom
iis-header-fast
Oct 31, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
iis-header-fast

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Startup used to read every byte of a big log, Apache logs included. It was searching backwards for an IIS header, and the search only stopped when it found one, so a file with a single header at the top, or none at all, was read in full.

Now:

  1. The first #Fields: header is read from the file's first 64 KB.
  2. It is kept if the last line before the starting point parses with it: same field count, a valid client address, and a status of 100–599.
  3. Otherwise the file is searched backwards. The search stops at the first header it meets, which is the point where the fields changed.
  4. A file with no #Fields: in its first 64 KB is not W3C, and is not searched at all.

Measured on 1 GB logs, with startup reads from /proc/<pid>/io:

Log Read at startup New lines
IIS, header only at the top 0.2 MB, 0.03 s (whole file before) parsed, scanner banned
IIS, fields changed at 3/4 257 MB, 0.09 s (back to the change) parsed with the new fields
IIS, ends in a fresh header block 1.2 MB, 0.03 s parsed with the new fields
Apache 0.1 MB, 0.03 s (whole file before) parsed

Known limit: if the fields changed to another set with the same count, and with the address and status in the same columns, the check would still pass. IIS fields come from one fixed list, so that would take a deliberate reshuffle.

Unit tests: 150 checks, 0 failed. The four new checks cover the first header still in effect, fields changed mid-file, a file ending in a header block, and a non-W3C log.


Generated by Claude Code

Startup read every byte of a big log searching backwards for a header,
Apache logs included. Now the first header is checked against the last line
and the backward search runs only for a file whose fields changed (and stops
at the change); a file with no header in its first 64 KB is not searched.
1 GB IIS log: 0.2 MB read at startup instead of the whole file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJFY41846T15QqxmGW2
@FMXExpress
FMXExpress merged commit cab6cc3 into main Oct 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants