Repository navigation
perf(traffic): index exchanges on (host, ts) - #540
Open
Phantom-IN wants to merge 1 commit into
Open
Phantom-IN wants to merge 1 commit into
Phantom-IN wants to merge 1 commit into
Conversation
traffic_search and the host-filtered traffic list run WHERE host=? ORDER BY ts DESC LIMIT n. With only idx_ex_host(host) SQLite reads every exchange of the host and sorts them in a temp b-tree to return the newest few. Hosts(), which the traffic page polls every 5 s, scans the table for GROUP BY host / MAX(ts). Replace idx_ex_host with idx_ex_host_ts(host, ts). The host search walks the index backwards and stops after n rows, and Hosts() reads only the index. Existing stores get the new index and drop the old one on open. BenchmarkHostSearch, 50k exchanges (45k on one host): search 42.05 ms -> 0.038 ms hosts 19.89 ms -> 7.77 ms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
traffic_search(called by the agent before binding traffic to a finding) and the host-filtered traffic list both runWHERE host=? ORDER BY ts DESC LIMIT n. The capture index only hasidx_ex_host(host)andidx_ex_ts(ts), so SQLite pulls every exchange for that host and sorts them to return the newest 3.Hosts(), which the traffic page polls every 5 s, scans the whole table.This replaces
idx_ex_hostwithidx_ex_host_ts(host, ts). The search now walks the index and stops afternrows, andHosts()only reads the index. Existing stores pick it up on next open.idx_ex_tmplstill starts withhost, so nothing that relied on the old index loses it.BenchmarkHostSearch(50k exchanges, 45k on one host, modernc sqlite):Hosts()TestHostSearchUsesHostTSIndexchecks the query plans: no temp b-tree for the host search, and a covering index forHosts(). It fails on main.go test ./traffic/passes.