-
Notifications
You must be signed in to change notification settings - Fork 24
psp-10487 address major memory useage outliers. #4880
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
Conversation
@@ -7,6 +7,8 @@ | |||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | |||
<ProjectGuid>{16BC0468-78F6-4C91-87DA-7403C919E646}</ProjectGuid> | |||
<TargetFramework>net8.0</TargetFramework> | |||
<ServerGarbageCollection>true</ServerGarbageCollection> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default GC setting is actually "workstation" which doesn't seem appropriate for our case. See here:
https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/workstation-server-gc
@@ -257,8 +257,9 @@ public async Task<ExternalResponse<DocumentDetailModel>> TryUploadDocumentAsync( | |||
string authenticationToken = await _authRepository.GetTokenAsync(); | |||
|
|||
byte[] fileData; | |||
using var byteReader = new BinaryReader(file.OpenReadStream()); | |||
fileData = byteReader.ReadBytes((int)file.OpenReadStream().Length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This opens an extra (untracked) readstream just to get the stream length.
@@ -48,13 +48,13 @@ public async Task Invoke(HttpContext context) | |||
{ | |||
context.Request.EnableBuffering(); | |||
await using var requestStream = _recyclableMemoryStreamManager.GetStream(); | |||
await context.Request.Body.CopyToAsync(requestStream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copy was happening before the max length check - as a result the entire copy operation was being persisted to memory - despite the using call (possibly due to the recycleable memory stream manager). This increased the size of the heap by the largest document uploaded.
string body = null; | ||
if (reader.BaseStream.Length < maxStreamLength) | ||
if (context.Response.ContentLength < maxStreamLength) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar story here - larger responses end up persisting in memory after the request is handled in these logging processes.
|
See CodeCov Report Here: https://app.codecov.io/github/bcgov/psp/pull/4880 |
No description provided.