Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination to endpoints that read entire tables (alerts/messages) #1020

Open
alex-mcgovern opened this issue Feb 12, 2025 · 3 comments · May be fixed by #1186
Open

Add pagination to endpoints that read entire tables (alerts/messages) #1020

alex-mcgovern opened this issue Feb 12, 2025 · 3 comments · May be fixed by #1186
Assignees

Comments

@alex-mcgovern
Copy link
Contributor

@danbarr has made frequent reports that the dashboard is very slow to load on his machine, including here stacklok/codegate-ui#300

The root cause is that his local DB has been in use since December, and has thousands of records in the alerts & messages table.

The request here is to devise a method of pagination for /alerts & /messages and implement it. I'm not sure that this ranks highly against our other priorities, but recording it for posterity.

@alex-mcgovern
Copy link
Contributor Author

Related to #924

@alex-mcgovern
Copy link
Contributor Author

Adding more context — when discussing this with @danbarr he mentioned a scenario where he experienced slow responses from the LLM with exceptions related to DB locks being printed into the logs. There is a dump of the related logs attached.

My understanding of the issue is that as the LLM was streaming it's response back to the IDE client, alerts were being created — these trigger server-sent-events, which in turn trigger a read from the DB via the API.

I think what we have here is negative feedback loop that drags down the user experience as a whole.

server-error.txt

@blkt
Copy link
Contributor

blkt commented Feb 17, 2025

About locking, these lines fire a concurrent db insert task for each new alert. This is not a problem in and of itself, since version 3+ of SQLite implements a multi-read/single-write concurrency model, but there's a catch.

The process of writing to the database requires the following logical steps

  1. obtain a SHARED lock -> still readable, new readers allowed
  2. obtain a RESERVED lock -> still readable, new readers allowed
  3. write some stuff durably to the transaction log -> still readable, new readers allowed
  4. obtain a PENDING lock -> still readable, no new readers allowed
  5. obtain an EXCLUSIVE lock -> not readable anymore

Here's SQLite docs page.

Each of the statements goes through this pipe, which means we have a bunch of (green) threads who likely all acquired a PENDING lock, so no new readers are allowed, causing the issue that Dan faced.

I believe that, specifically for the locking issue, the very first thing we should do is implementing proper batch inserts, which are luckily trivial with sqlalchemy.

@yrobla yrobla self-assigned this Mar 3, 2025
yrobla added a commit that referenced this issue Mar 3, 2025
Modify the API to add pagination to those endpoints, to be able
to render faster in the browser

Closes: #1020
@yrobla yrobla linked a pull request Mar 3, 2025 that will close this issue
yrobla added a commit that referenced this issue Mar 3, 2025
Modify the API to add pagination to those endpoints, to be able
to render faster in the browser

Closes: #1020
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 a pull request may close this issue.

4 participants