You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can clearly measure the benefit of this package for buffers larger than 8kb, but what about those smaller than 256 bytes?
My scenario is that I use buffers to buff incoming http request/response in order to log the request body, pretty much like this:
privateasync Task LogRequest(HttpContextcontext){
context.Request.EnableBuffering();awaitusingvarrequestStream= _recyclableMemoryStreamManager.GetStream();await context.Request.Body.CopyToAsync(requestStream);
_logger.LogInformation(ReadStreamInChunks(requestStream));
context.Request.Body.Position =0;}privatestaticstringReadStreamInChunks(Streamstream){constintreadChunkBufferLength=256;//my avg request body size is about 100 bytes and 95% are smaller than 1kb
stream.Seek(0, SeekOrigin.Begin);usingvartextWriter=new StringWriter();usingvarreader=new StreamReader(stream);varreadChunk=newchar[readChunkBufferLength];intreadChunkLength;do{readChunkLength= reader.ReadBlock(readChunk,0, readChunkBufferLength);
textWriter.Write(readChunk,0, readChunkLength);}while(readChunkLength>0);return textWriter.ToString();}
A single pod usually handles peaks of about 1000 requests per minute (17 req/s)...
so I was wondering how effective is this on my scenario?
The text was updated successfully, but these errors were encountered:
Leonardo-Ferreira
changed the title
How effective is this package for buffers that are usually smaller than 1kb?
How effective is this package for buffers that are usually smaller than 256 bytes?
Nov 1, 2023
The only real answer is that you would have to test and see. 256 bytes is pretty small, but you have a lot of them.
I suspect it would still be beneficial--you'll avoid creating a ton of buffers that will trigger GC. OTOH, as long as their in-use time was quite short, they would be cleaned up in gen0 anyway, so it might be a wash.
I can clearly measure the benefit of this package for buffers larger than 8kb, but what about those smaller than 256 bytes?
My scenario is that I use buffers to buff incoming http request/response in order to log the request body, pretty much like this:
A single pod usually handles peaks of about 1000 requests per minute (17 req/s)...
so I was wondering how effective is this on my scenario?
The text was updated successfully, but these errors were encountered: