Repository navigation
Cut per-request DB work on osctrl-tls and osctrl-api hot paths - #1071
Merged
Merged
Conversation
This was referenced Oct 11, 2026
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.
Cut per-request DB work on osctrl-tls and osctrl-api hot paths
Several paths that run on every node check-in or every SPA poll were doing far more database work than needed. This PR removes it without changing response shapes.
osctrl-tls
pkg/logging/db.go). The defaultlogger.type: dbinserted each status/result line in its own transaction, so a batch of N lines cost N commits. It now uses multi-row INSERTs in a single transaction. A 200-line batch dropped from 87 ms to 1.3 ms on file-backed SQLite; Postgres should gain more, since each commit there is a WAL flush.text) still loses only itself.created_atat storage precision. Readers order bycreated_atalone, so this keeps batch lines in send order.UpdateQueryStatus). Each node result ranCOUNT(*)over every node_query row of the query (statusisn't indexed), which is O(targets²) over a query's life. It now does an existence check (LIMIT 1), and the SELECT-then-UPDATE of the node's row is one UPDATE.UpdateMetadataByUUID). A full-row SELECT plus an UPDATE became a single UPDATE.bytes_receivedis now incremented in SQL. The old read-modify-write lost bytes when batches overlapped: in a test with 8 concurrent writers, 75 of 600 bytes were recorded.osctrl-api
last_token_usewrite when the IP is unchanged and the last recorded use is under a minute old.INquery./stats: per-environment full-row loads of active queries and carves, made only tolen()them, replaced by one groupedCOUNT.Behaviour changes
last_token_usenow has minute resolution; a new IP is still recorded immediately. It's display-only, and nothing authorizes on it.MetadataRefreshis removed; its only caller wasUpdateMetadataByUUID.Not in this PR
osquery_nodes,node_queries,distributed_queries, and the log tables would be the next big win. I left them out becauseAutoMigratecreates indexes at startup, and on Postgres that blocks writes to large tables while it runs.hostIdentifier, not the authenticated node. That's tracked separately as a security fix.Validation
go build ./...andgo vet ./...are clean, and all packages passgo test ./....GetQueries/GetCarves.golangci-lintreports one pre-existing goimports issue inpkg/queries/events_test.go, which this PR doesn't touch.