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)
- Assign a large buffer HOT 3
- This repo is missing important files
- Add NET6 target HOT 3
- RecyclableMemoryStream.ToString should not throw if disposed HOT 2
- ArgumentNullException during Write HOT 1
- Enable nullable annotations and warnings HOT 4
- Change Target Framework from `net5.0` to `net6.0` HOT 3
- Reduce the number of Method/Constructor overloads. HOT 2
- Question about how to use Recyclable memory stream manager HOT 6
- RMS v3.0 Planning HOT 3
- NullReferenceException possible with M.IO.RecyclableMemoryStream.Dispose(true) HOT 1
- 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
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.