Comments (5)
Without more information, it's hard to say what the problem is.
RMS is made for repeated use. Are you deserializing that file once or repeatedly? Are you creating a single manager object and re-using it?
Your block size is very, very small--you would be using so many chained buffers, your efficiency could go down from that alone. I'd probably use something like 128KB or bigger, depending on your typical data sizes.
from microsoft.io.recyclablememorystream.
The file is deserialized multiple times. There are many files in the range of 500MB to 2GB. At a time, 5-6 files will be deserialized.
I am using a static memory stream that provided me with a ~50% gain in memory usage. I will try with a bigger blocker.
I wanted to make sure if response time degradation is expected especially in case of large files?
Here is the code.
using (MemoryStream ms = RecyclableMemoryStream.GetMemoryStream())
{
if (await Func(assetLocation, ms, cancellationToken).ConfigureAwait(false))
{
ms.Position = 0;
using (StreamReader sr = new StreamReader(ms))
{
using (JsonTextReader jr = new JsonTextReader(sr))
{
result = jsonSerializer.Deserialize(jr);
}
}
}
}
public static class RecyclableMemoryStream
{
///
/// The object used for lock.
///
private static readonly object LockObject = new object();
/// <summary>
/// The recyclable memory stream manager.
/// It has to be static to take the benefit of the library.
/// </summary>
private static RecyclableMemoryStreamManager recyclableMemoryStreamManager;
/// <summary>
/// Gets or sets a value indicating whether to use recyclable memory stream manager.
/// </summary>
public static bool UseRecyclableMemoryStreamManager { get; set; }
/// <summary>
/// Gets the recyclable memory stream from recyclable memory stream manager if <see cref="UseRecyclableMemoryStreamManager"/> is true, otherwise <see cref="MemoryStream" />.
/// </summary>
/// <returns>The Memory stream.</returns>
public static MemoryStream GetMemoryStream()
{
if (UseRecyclableMemoryStreamManager && recyclableMemoryStreamManager == null)
{
lock (LockObject)
{
recyclableMemoryStreamManager ??= GetRecyclableMemoryStreamManager();
}
}
return recyclableMemoryStreamManager == null ? new MemoryStream() : recyclableMemoryStreamManager.GetStream();
}
/// <summary>
/// Returns the RecyclableMemoryStreamManager instance with default values.
/// </summary>
/// <returns><see cref="RecyclableMemoryStreamManager"/>.</returns>
private static RecyclableMemoryStreamManager GetRecyclableMemoryStreamManager()
{
int blockSize = 1024;
int largeBufferMultiple = 1024 * 1024;
int maxBufferSize = 16 * largeBufferMultiple;
int maximumFreeLargePoolBytes = 3 * maxBufferSize;
int maximumFreeSmallPoolBytes = 100 * blockSize;
RecyclableMemoryStreamManager manager = new RecyclableMemoryStreamManager(
blockSize: blockSize,
largeBufferMultiple: largeBufferMultiple,
maximumBufferSize: maxBufferSize,
maximumSmallPoolFreeBytes: maximumFreeSmallPoolBytes,
maximumLargePoolFreeBytes: maximumFreeLargePoolBytes);
manager.AggressiveBufferReturn = true;
return manager;
}
}
from microsoft.io.recyclablememorystream.
There should be no inherent reason why using RMS is slower than using MS.
If using a larger block size doesn't work, you will need to do some profiling to see where the slowdown is coming.
from microsoft.io.recyclablememorystream.
@anilgupta29Dev Do you have any updates on your end to this issue?
from microsoft.io.recyclablememorystream.
We can close the issue. I was able to get similar response time with changed settings.
from microsoft.io.recyclablememorystream.
Related Issues (20)
- Using memory stream with httpClient post HOT 3
- Is there a plan to contribute to the dotnet/runtime? HOT 4
- FeatureRequest: Add opt-in possibility to zeroed-out buffers HOT 10
- Continous benchmarking HOT 1
- Multiple StreamManagers in referenced libraries - how to find total memory usage HOT 1
- Large pool limit should apply to whole pool, not each slot HOT 1
- Humanitarian Organization Team mbrgi
- Question: GetStream copy existing buffer use case HOT 1
- How effective is this package for buffers that are usually smaller than 256 bytes? HOT 1
- Consider using ArrayPool<byte> as underlying storage mechanism HOT 4
- Breaking changes at 3.0.0 version break OfficeOpenXml NuGet package HOT 11
- Guideline about cryptography with RMS HOT 5
- Unclear Documentation for MaximumFreeSmallPoolBytes
- Upgrade blocker: Recent change of GetStream() to return RecyclableMemoryStream instead of MemoryStream HOT 1
- why just pool MemoryStream HOT 2
- FileStreamResult: ObjectDisposedException: Cannot access a disposed object. HOT 4
- For many small stream writes, RecyclableMemoryStream is slower than other implementations HOT 4
- ETW event source is not working HOT 2
- Use of RecyclableMemoryStreamManager with Confluent.Kafka HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microsoft.io.recyclablememorystream.