Repository navigation
perf(LogController): Use streamed responses and only read log once - #2331
Open
DerDreschner wants to merge 2 commits into
Open
DerDreschner wants to merge 2 commits into
DerDreschner wants to merge 2 commits into
Conversation
DerDreschner
requested review from
Antreesy and
CarlSchwan
and
a balanced review from Copilot
October 19, 2026 14:17
Contributor
Author
|
/backport to stable35 |
Contributor
Author
|
/backport to stable34 |
Contributor
Author
|
/backport to stable33 |
DerDreschner
enabled auto-merge
October 19, 2026 14:18
DerDreschner
force-pushed
the
perf/stream-log-responses
branch
from
October 19, 2026 14:37
e5ce132 to
b4a6a4b
Compare
At the moment, the endpoints /api/poll and /api/log collect all entries they return and then JSON-encode them all at once. In a test scenario with ten 25 MB entries among the newest 50, the request needed 720 MB and failed on the memory limit, leaving the log viewer empty. Since Nextcloud 33, there is a better way to do it: using StreamTraversableResponse and sending one entry at a time. That way, the same test scenario only needs 95 MB at peak. Such large entries can occur after an upgrade, as the upgrader sets the log level to debug, and exceptions are then logged with all their arguments. As the response is already being sent while the entries are read, values JSON cannot represent are replaced instead of failing halfway, and a poll reads at most the newest 100,000 entries like a search. LogIteratorFactory now only returns lines that decode to an entry with a level, so lines without a level are no longer shown. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
A search rewound its iterator in the SearchFilter constructor, in get() and again in responseFromIterator(). Each rewind of a filter reads the log up to the first matching entry, so a search without a match read the whole log several times. A poll opened the log once to compare the newest entry with lastReqId, and then a second time to send the new entries. Skipping to the offset of a page also went on after the end of the log. Rewind a search only in responseFromIterator(), use a single iterator for a poll, and stop skipping at the end of the log. The streamed response already answers with an empty list when the newest entry is the last known one. A search without a match over 100,000 entries now takes 0.20 s instead of 0.40 s. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
DerDreschner
force-pushed
the
perf/stream-log-responses
branch
from
October 19, 2026 14:59
b4a6a4b to
2eb5f53
Compare
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.


At the moment, the endpoints /api/poll and /api/log collect all entries they return and then JSON-encode them all at once. In a test scenario with ten 25 MB entries among the newest 50, the request needed 720 MB, more than the usual memory limit of 512 MB, leaving the log viewer empty.
This is being improved by this PR in two ways:
StreamTraversableResponse, available since Nextcloud 33. This allows us to stream each log entry to the browser, which means the memory usage is only dependent on the largest entry. For the test scenario, that was 95 MB peak memory consumption.As large log entries can happen (like after an upgrade, during which the log level is temporarily set to debug and exceptions are logged with all their arguments), improvements here are necessary IMHO.
Fixes #1025
Fixes #1170
馃 AI (if applicable)