/// <summary> /// Sets the maximum (approx) MB/sec allowed by all write IO performed by /// <see cref="IndexOutput"/> created with the given <see cref="IOContext.UsageContext"/>. Pass /// <c>null</c> for <paramref name="mbPerSec"/> to have no limit. /// /// <para/> /// <b>NOTE</b>: For already created <see cref="IndexOutput"/> instances there is no /// guarantee this new rate will apply to them; it will only be guaranteed to /// apply for new created <see cref="IndexOutput"/> instances. /// <para/> /// <b>NOTE</b>: this is an optional operation and might not be respected by /// all <see cref="Directory"/> implementations. Currently only buffered (<see cref="FSDirectory"/>) /// <see cref="Directory"/> implementations use rate-limiting. /// <para/> /// @lucene.experimental /// </summary> /// <exception cref="ObjectDisposedException"> if the <see cref="Directory"/> is already disposed /// </exception> public void SetMaxWriteMBPerSec(double?mbPerSec, IOContext.UsageContext context) { EnsureOpen(); //if (context is null) // LUCENENET NOTE: enum values can never be null in .NET //{ // throw new ArgumentException("Context must not be null"); //} //int ord = context.ordinal(); _contextRateLimiters.TryGetValue(context, out RateLimiter limiter); if (mbPerSec is null) { if (limiter != null) { limiter.SetMbPerSec(double.MaxValue); _contextRateLimiters[context] = null; } } else if (limiter != null) { limiter.SetMbPerSec(mbPerSec.Value); _contextRateLimiters[context] = limiter; // cross the mem barrier again } else { _contextRateLimiters[context] = new RateLimiter.SimpleRateLimiter(mbPerSec.Value); } }
/// <summary> /// See <see cref="SetMaxWriteMBPerSec"/>. /// <para/> /// @lucene.experimental /// </summary> /// <exception cref="ObjectDisposedException"> if the <see cref="Directory"/> is already disposed /// </exception> public double GetMaxWriteMBPerSec(IOContext.UsageContext context) { EnsureOpen(); var limiter = GetRateLimiter(context); return(limiter is null ? 0 : limiter.MbPerSec); }
private RateLimiter GetRateLimiter(IOContext.UsageContext context) { //Debug.Assert(context != null); // LUCENENET NOTE: In .NET, enum can never be null RateLimiter ret; return(_contextRateLimiters.TryGetValue(context, out ret) ? ret : null); }
/// <summary> /// Sets the rate limiter to be used to limit (approx) MB/sec allowed by all IO /// performed with the given context (<see cref="IOContext.UsageContext"/>). Pass <c>null</c> to /// have no limit. /// /// <para/> /// Passing an instance of rate limiter compared to setting it using /// <see cref="SetMaxWriteMBPerSec(double?, IOContext.UsageContext)"/> /// allows to use the same limiter instance across several directories globally /// limiting IO across them. /// <para/> /// @lucene.experimental /// </summary> /// <exception cref="ObjectDisposedException"> if the <see cref="Directory"/> is already disposed /// </exception> public void SetRateLimiter(RateLimiter mergeWriteRateLimiter, IOContext.UsageContext context) { EnsureOpen(); _contextRateLimiters[context] = mergeWriteRateLimiter; }