Repository navigation
Index job logs by job and timestamp - #820
Open
thomashoneyman wants to merge 1 commit into
Open
thomashoneyman wants to merge 1 commit into
thomashoneyman wants to merge 1 commit into
Conversation
Member
Author
|
Since this is affecting the actual server I went ahead and applied the migration directly. You can see the job succeeded now in 1.5 mins: ...where previously it had failed due to being killed in a timeout after 10 minutes: |
This branch has not been deployed
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.
I was checking in on the logs and noticed
nextuiandnextjspublishes were hitting the registry’s ten-minute timeout. This was happening, oddly enough, in dependency installation rather than compilation.While investigating, I found Node using about a full CPU core on the server. A three-second
stracesample showed 45,445pread64calls, with sequential reads targeting SQLite; the job-log query took about a second even though it returned at most 100 rows. That is...extremely slow.The logs table has no secondary indexes, so every poll scanned the table and built a temporary sort. With a 595 MB database and synchronous SQLite queries, polling the job’s progress was itself blocking the server. Pretty bad!
So this change adds an index on
logs (jobId, timestamp). SQLite can now seek to one job’s time window and read it in either timestamp order without sorting. The query and API behavior are unchanged. There is a reversible dbmate migration for existing databases and a schema update for fresh ones.I checked this locally using the actual query function against a file-backed database containing one million synthetic logs across 1,000 jobs. These are median timings from nine warmed calls:
The returned rows all match, and the plans changed from a table scan and temporary sort to a search using
idx_logs_job_timestamp. I also checked the same query against a copy of the production database after applying the migration, which took 7.58 seconds. The query went from 1010.6 ms to 2.03 ms, with an identical result hash and no temporary sort. Node CPU dropped from about 100% to 4%, and the runningnext-uiretry installed its dependencies within a few seconds.