Example #1
0
		public void Defaults ()
		{
			CacheSection c = new CacheSection ();
			Assert.AreEqual (false, c.DisableExpiration, "A1");
			Assert.AreEqual (false, c.DisableMemoryCollection, "A2");
			Assert.AreEqual (0, c.PercentagePhysicalMemoryUsedLimit, "A3");
			Assert.AreEqual (0, c.PrivateBytesLimit, "A4");
			Assert.AreEqual (TimeSpan.FromMinutes (2), c.PrivateBytesPollTime, "A4");
		}
 internal override void ReadConfig(CacheSection cacheSection)
 {
     int percentagePhysicalMemoryUsedLimit = cacheSection.PercentagePhysicalMemoryUsedLimit;
     if (percentagePhysicalMemoryUsedLimit != 0)
     {
         base._pressureHigh = Math.Max(3, percentagePhysicalMemoryUsedLimit);
         base._pressureMiddle = Math.Max(2, base._pressureHigh - 2);
         base._pressureLow = Math.Max(1, base._pressureHigh - 9);
         PerfCounters.SetCounter(AppPerfCounter.CACHE_PERCENT_MACH_MEM_LIMIT_USED_BASE, base._pressureHigh);
     }
 }
Example #3
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        // Get the application configuration file.
        System.Configuration.Configuration config =
            System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");


        // <Snippet2>
        System.Web.Configuration.CacheSection cacheSection =
            (System.Web.Configuration.CacheSection)config.GetSection(
                "system.web/caching/cache");
        // </Snippet2>

        // <Snippet6>
        // Increase the PrivateBytesLimit property to 0.
        cacheSection.PrivateBytesLimit =
            cacheSection.PrivateBytesLimit + 10;
        // </Snippet6>


        // <Snippet7>
        // Increase memory limit.
        cacheSection.PercentagePhysicalMemoryUsedLimit =
            cacheSection.PercentagePhysicalMemoryUsedLimit + 1;
        // </Snippet7>

        // <Snippet8>
        // Increase poll time.
        cacheSection.PrivateBytesPollTime =
            cacheSection.PrivateBytesPollTime + TimeSpan.FromMinutes(1);
        // </Snippet8>


        // <Snippet3>
        // Enable or disable memory collection.
        cacheSection.DisableMemoryCollection =
            !cacheSection.DisableMemoryCollection;
        // </Snippet3>

        // <Snippet4>
        // Enable or disable cache expiration.
        cacheSection.DisableExpiration =
            !cacheSection.DisableExpiration;
        // </Snippet4>

        // Save the configuration file.
        config.Save(System.Configuration.ConfigurationSaveMode.Modified);
    }
Example #4
0
        internal void Init(CacheSection cacheSection) {
            if (_inited) {
                return;
            }
            
            lock (_initLock) {
                if (_inited) {
                    return;
                }
                
                NameValueCollection config = null;
                if (cacheSection != null) {
                    //_enableMemoryCollection = (!cacheSection.DisableMemoryCollection);
                    //_enableExpiration = (!cacheSection.DisableExpiration);
                    int physicalMemoryLimitPercentage = cacheSection.PercentagePhysicalMemoryUsedLimit;
                    long cacheMemoryLimitMegabytes = cacheSection.PrivateBytesLimit << 20;
                    TimeSpan pollingInterval = cacheSection.PrivateBytesPollTime;
                    config = new NameValueCollection(3);
                    config["physicalMemoryLimitPercentage"] = physicalMemoryLimitPercentage.ToString(CultureInfo.InvariantCulture);
                    config["cacheMemoryLimitMegabytes"] = cacheMemoryLimitMegabytes.ToString(CultureInfo.InvariantCulture);
                    config["pollingInterval"] = pollingInterval.ToString();
                }

                Type t = _cacheInternal.GetType();

                t.InvokeMember("UpdateConfig",
                               BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, 
                               null, // binder
                               _cacheInternal, // target
                               new object[] {config}, // args
                               CultureInfo.InvariantCulture);
                t.InvokeMember("UpdateConfig",
                               BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, 
                               null, // binder
                               _cachePublic, // target
                               new object[] {config}, // args
                               CultureInfo.InvariantCulture);

                _inited = true;
            }
        }
Example #5
0
    protected void Button2_Click(object sender, EventArgs e)
    {
        // Get the application configuration file.
        System.Configuration.Configuration config =
            System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");


        System.Web.Configuration.CacheSection cacheSection =
            (System.Web.Configuration.CacheSection)config.GetSection(
                "system.web/caching/cache");

        // Read the cache section.
        System.Text.StringBuilder buffer = new System.Text.StringBuilder();

        string   currentFile    = cacheSection.CurrentConfiguration.FilePath;
        bool     dExpiration    = cacheSection.DisableExpiration;
        bool     dMemCollection = cacheSection.DisableMemoryCollection;
        TimeSpan pollTime       = cacheSection.PrivateBytesPollTime;
        int      phMemUse       = cacheSection.PercentagePhysicalMemoryUsedLimit;
        long     pvBytesLimit   = cacheSection.PrivateBytesLimit;

        string cacheEntry = String.Format("File: {0} <br/>", currentFile);

        buffer.Append(cacheEntry);
        cacheEntry = String.Format("Expiration Disabled: {0} <br/>", dExpiration);
        buffer.Append(cacheEntry);
        cacheEntry = String.Format("Memory Collection Disabled: {0} <br/>", dMemCollection);
        buffer.Append(cacheEntry);
        cacheEntry = String.Format("Poll Time: {0} <br/>", pollTime.ToString());
        buffer.Append(cacheEntry);
        cacheEntry = String.Format("Memory Limit: {0} <br/>", phMemUse.ToString());
        buffer.Append(cacheEntry);
        cacheEntry = String.Format("Bytes Limit: {0} <br/>", pvBytesLimit.ToString());
        buffer.Append(cacheEntry);

        Label1.Text = buffer.ToString();
    }
 internal virtual void ReadConfig(CacheSection cacheSection)
 {
 }
Example #7
0
 internal void ReadCacheInternalConfig(CacheSection cacheSection) {
     _cacheCommon.ReadCacheInternalConfig(cacheSection);
 }
Example #8
0
        internal void ReadCacheInternalConfig(CacheSection cacheSection) {
            if (_internalConfigRead) {
                return;
            }

            lock (this) {
                if (_internalConfigRead) {
                    return;
                }

                // Set it to true here so that even if we have to call ReadCacheInternalConfig
                // from the code below, we won't get into an infinite loop.
                _internalConfigRead = true;

                if (cacheSection != null) {
                    _enableMemoryCollection = (!cacheSection.DisableMemoryCollection);
                    _enableExpiration = (!cacheSection.DisableExpiration);
                    _cacheMemoryStats.ReadConfig(cacheSection);
                    _currentPollInterval = CacheMemorySizePressure.PollInterval;
                    ResetFromConfigSettings();
                }
            }
        }
Example #9
0
		public void PrivateBytesLimit_validationFailure ()
		{
			CacheSection c = new CacheSection ();
			c.PrivateBytesLimit = -1L;
		}
Example #10
0
		public void PercentagePhysicalMemoryUsedLimit_validationFailure()
		{
			CacheSection c = new CacheSection ();
			c.PercentagePhysicalMemoryUsedLimit = -1;
		}
 internal void ReadCacheInternalConfig(CacheSection cacheSection)
 {
     if (!this._internalConfigRead)
     {
         lock (this)
         {
             if (!this._internalConfigRead)
             {
                 this._internalConfigRead = true;
                 if (cacheSection != null)
                 {
                     this._enableMemoryCollection = !cacheSection.DisableMemoryCollection;
                     this._enableExpiration = !cacheSection.DisableExpiration;
                     this._cacheMemoryStats.ReadConfig(cacheSection);
                     this._currentPollInterval = CacheMemorySizePressure.PollInterval;
                     this.ResetFromConfigSettings();
                 }
             }
         }
     }
 }
 internal override void ReadConfig(CacheSection cacheSection)
 {
     long privateBytesLimit = cacheSection.PrivateBytesLimit;
     this._memoryLimit = WorkerProcessMemoryLimit;
     if ((privateBytesLimit == 0L) && (this._memoryLimit == 0L))
     {
         this._memoryLimit = EffectiveProcessMemoryLimit;
     }
     else if ((privateBytesLimit != 0L) && (this._memoryLimit != 0L))
     {
         this._memoryLimit = Math.Min(this._memoryLimit, privateBytesLimit);
     }
     else if (privateBytesLimit != 0L)
     {
         this._memoryLimit = privateBytesLimit;
     }
     if (this._memoryLimit > 0L)
     {
         if (s_pid == 0)
         {
             s_pid = (uint) SafeNativeMethods.GetCurrentProcessId();
         }
         base._pressureHigh = 100;
         base._pressureMiddle = 90;
         base._pressureLow = 80;
     }
     s_pollInterval = (int) Math.Min(cacheSection.PrivateBytesPollTime.TotalMilliseconds, 2147483647.0);
     PerfCounters.SetCounter(AppPerfCounter.CACHE_PERCENT_PROC_MEM_LIMIT_USED_BASE, (int) (this._memoryLimit >> 10));
 }
 internal void ReadConfig(CacheSection cacheSection)
 {
     this._pressureTotalMemory.ReadConfig(cacheSection);
     this._pressureCacheSize.ReadConfig(cacheSection);
 }
Example #14
0
 private void GetInitConfigSections(out CacheSection cacheSection, out TrustSection trustSection, out SecurityPolicySection securityPolicySection, out CompilationSection compilationSection, out HostingEnvironmentSection hostingEnvironmentSection, out Exception initException)
 {
   cacheSection = (CacheSection) null;
   trustSection = (TrustSection) null;
   securityPolicySection = (SecurityPolicySection) null;
   compilationSection = (CompilationSection) null;
   hostingEnvironmentSection = (HostingEnvironmentSection) null;
   initException = (Exception) null;
   RuntimeConfig appLkgConfig = RuntimeConfig.GetAppLKGConfig();
   RuntimeConfig runtimeConfig = (RuntimeConfig) null;
   try
   {
     runtimeConfig = RuntimeConfig.GetAppConfig();
   }
   catch (Exception ex)
   {
     initException = ex;
   }
   if (runtimeConfig != null)
   {
     try
     {
       cacheSection = runtimeConfig.Cache;
     }
     catch (Exception ex)
     {
       if (initException == null)
         initException = ex;
     }
   }
   if (cacheSection == null)
     cacheSection = appLkgConfig.Cache;
   if (runtimeConfig != null)
   {
     try
     {
       trustSection = runtimeConfig.Trust;
     }
     catch (Exception ex)
     {
       if (initException == null)
         initException = ex;
     }
   }
   if (trustSection == null)
     trustSection = appLkgConfig.Trust;
   if (runtimeConfig != null)
   {
     try
     {
       securityPolicySection = runtimeConfig.SecurityPolicy;
     }
     catch (Exception ex)
     {
       if (initException == null)
         initException = ex;
     }
   }
   if (securityPolicySection == null)
     securityPolicySection = appLkgConfig.SecurityPolicy;
   if (runtimeConfig != null)
   {
     try
     {
       compilationSection = runtimeConfig.Compilation;
     }
     catch (Exception ex)
     {
       if (initException == null)
         initException = ex;
     }
   }
   if (compilationSection == null)
     compilationSection = appLkgConfig.Compilation;
   if (runtimeConfig != null)
   {
     try
     {
       hostingEnvironmentSection = runtimeConfig.HostingEnvironment;
     }
     catch (Exception ex)
     {
       if (initException == null)
         initException = ex;
     }
   }
   if (hostingEnvironmentSection != null)
     return;
   hostingEnvironmentSection = appLkgConfig.HostingEnvironment;
 }
        override internal void ReadConfig(CacheSection cacheSection) {
            // Read the private bytes limit set in config
            long    privateBytesLimit;
            privateBytesLimit = cacheSection.PrivateBytesLimit;

            // per-process information
            _memoryLimit = WorkerProcessMemoryLimit;
            
            // VSWhidbey 546381: never override what the user specifies as the limit;
            // only call AutoPrivateBytesLimit when the user does not specify one.
            if (privateBytesLimit == 0 && _memoryLimit == 0) {
                // Zero means we impose a limit
                _memoryLimit = EffectiveProcessMemoryLimit;
            }
            else if (privateBytesLimit != 0 && _memoryLimit != 0) {
                // Take the min of "process recycle limit" and our internal "private bytes limit"
                _memoryLimit = Math.Min(_memoryLimit, privateBytesLimit);
            }
            else if (privateBytesLimit != 0) {
                // _memoryLimit is 0, but privateBytesLimit is non-zero, so use it as the limit
                _memoryLimit = privateBytesLimit;
            }

            Debug.Trace("CacheMemory", "CacheMemorySizePressure.ReadConfig: _memoryLimit=" + (_memoryLimit >> MEGABYTE_SHIFT) + "Mb");

            if (_memoryLimit > 0) {

                if (s_pid == 0) // only set this once
                    s_pid = (uint) SafeNativeMethods.GetCurrentProcessId();

                _pressureHigh = 100;
                _pressureMiddle = 90;
                _pressureLow = 80;
            }
            
            // convert <cache privateBytesPollTime/> to milliseconds
            s_pollInterval = (int)Math.Min(cacheSection.PrivateBytesPollTime.TotalMilliseconds, (double)Int32.MaxValue);

            // PerfCounter: Cache Percentage Process Memory Limit Used
            //    = memory used by this process / process memory limit at pressureHigh

            // Set private bytes limit in kilobytes becuase the counter is a DWORD
            PerfCounters.SetCounter(AppPerfCounter.CACHE_PERCENT_PROC_MEM_LIMIT_USED_BASE, (int)(_memoryLimit >> KILOBYTE_SHIFT));

            Debug.Trace("CacheMemory", "CacheMemorySizePressure.ReadConfig: _pressureHigh=" + _pressureHigh + 
                        ", _pressureMiddle=" + _pressureMiddle + ", _pressureLow=" + _pressureLow);
        }
        override internal void ReadConfig(CacheSection cacheSection) {
            // Read the percentagePhysicalMemoryUsedLimit set in config
            int limit = cacheSection.PercentagePhysicalMemoryUsedLimit;
            if (limit == 0) {
                // use defaults
                return;
            }

            _pressureHigh = Math.Max(3, limit);
            _pressureMiddle = Math.Max(2, _pressureHigh - 2);
            _pressureLow = Math.Max(1, _pressureHigh - 9);
            
            // PerfCounter: Cache Percentage Machine Memory Limit Used
            //    = total physical memory used / total physical memory used limit
            PerfCounters.SetCounter(AppPerfCounter.CACHE_PERCENT_MACH_MEM_LIMIT_USED_BASE, _pressureHigh);
            
#if DBG
            Debug.Trace("CacheMemory", "CacheMemoryTotalMemoryPressure.ReadConfig: _pressureHigh=" + _pressureHigh + 
                        ", _pressureMiddle=" + _pressureMiddle + ", _pressureLow=" + _pressureLow);
#endif
        }