Repository navigation
perf(traffic): write the full-text index off the request path - #543
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
The proxy records an exchange in its Response hook, before the client gets the response, and recordViews wrote the trigram index of each body (up to 4 MiB) inside its transaction while holding wmu. That is almost all of the recording cost: a 1 MB minified script takes ~163 ms with the index and ~1 ms without, and every other request being recorded waits on wmu behind it. Queue the index write instead and let one background worker do it. Searches that use the index wait for everything queued before them, so a body search still finds an exchange recorded before it. The worker only writes an entry whose exchange still exists with the same rowid and id, so a delete in between can't leave an entry that matches a later exchange. The queue holds at most 16 bodies; a recorder waits when it is full. Fixes BaaRai#542.
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.
Fixes #542.
Recording no longer writes the full-text index inline.
recordViewswrites the exchange, bodies, blob refs and trace as before, then hands the index text to a single background worker (traffic/fts_queue.go). The proxy replies without waiting for the trigram indexing.How it stays correct:
ftsFilterwaits until everything queued before the call is indexed, so a body search finds any exchange recorded before it. That coverstraffic_search,ResponseContainingand the traffic page search, since they all go throughftsFilter.WHERE EXISTS (exchange with this rowid and id), so ifDeleteHostremoves an exchange before its entry is written, the entry is dropped and can't later match a new exchange that reuses the rowid.addis called afterwmuis released, because the worker needswmu.Closeindexes what's left, then closes the db. Without FTS5, or on a zero-valueTraffic, recording indexes inline like before.BenchmarkRecordScriptmeasures record time for a 1 MiB script with the indexer idle: 52.3 ms on main, 1.47 ms here. With a real 1.3 MB minified bundle, main took 163 ms.Tests: a body search right after 20 back-to-back recordings (more than the queue holds) finds the last one, and a queued entry for a missing exchange isn't written.
go test -race ./traffic/passes, and./server/and./agent/pass apart from the two tests that fail on my Mac on main too.