Exemple #1
0
        public static Object CreateApplicationHost(Type hostType, String virtualDir, String physicalDir)
        {
#if !FEATURE_PAL // FEATURE_PAL does not require PlatformID.Win32NT
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                throw new PlatformNotSupportedException(SR.GetString(SR.RequiresNT));
            }
#else // !FEATURE_PAL
            // FEATURE_PAL
#endif // !FEATURE_PAL

            if (!StringUtil.StringEndsWith(physicalDir, Path.DirectorySeparatorChar))
            {
                physicalDir = physicalDir + Path.DirectorySeparatorChar;
            }

            ApplicationManager appManager = ApplicationManager.GetApplicationManager();

            String appId = StringUtil.GetNonRandomizedHashCode(String.Concat(virtualDir, physicalDir)).ToString("x");


            ObjectHandle h = appManager.CreateInstanceInNewWorkerAppDomain(
                hostType, appId, VirtualPath.CreateNonRelative(virtualDir), physicalDir);

            return(h.Unwrap());
        }
Exemple #2
0
            internal RecycleLimitMonitorSingleton(long privateBytesLimit)
            {
#if PERF
                SafeNativeMethods.OutputDebugString(String.Format("Creating RecycleLimitMonitorSingleton with PrivateBytesLimit = {0:N}\n", privateBytesLimit));
#endif

                // don't create timer if there's no memory limit
                if (privateBytesLimit <= 0)
                {
                    return;
                }

                _limit      = privateBytesLimit;
                _appManager = ApplicationManager.GetApplicationManager();
                _pid        = (uint)SafeNativeMethods.GetCurrentProcessId();

                _proxyMonitors = new Dictionary <RecycleLimitMonitor, string>();

                // the initial expected maximum increase in private bytes is 2MB per second per CPU
                _minMaxDelta = 2 * AspNetMemoryMonitor.MEGABYTE * SystemInfo.GetNumProcessCPUs();
                AdjustMaxDeltaAndPressureMarks(_minMaxDelta);

                _samples                 = new long[SAMPLE_COUNT];
                _sampleTimes             = new DateTime[SAMPLE_COUNT];
                _useGetProcessMemoryInfo = (VersionInfo.ExeName == "w3wp");
                _deltaSamples            = new long[DELTA_SAMPLE_COUNT];

                // start timer with initial poll interval
                _timer = new Timer(new TimerCallback(this.PBytesMonitorThread), null, Timeout.Infinite, _currentPollInterval);
            }
        public static object CreateApplicationHost(Type hostType, string virtualDir, string physicalDir)
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                throw new PlatformNotSupportedException(System.Web.SR.GetString("RequiresNT"));
            }
            if (!StringUtil.StringEndsWith(physicalDir, Path.DirectorySeparatorChar))
            {
                physicalDir = physicalDir + Path.DirectorySeparatorChar;
            }
            ApplicationManager applicationManager = ApplicationManager.GetApplicationManager();
            string             appId = (virtualDir + physicalDir).GetHashCode().ToString("x");

            return(applicationManager.CreateInstanceInNewWorkerAppDomain(hostType, appId, VirtualPath.CreateNonRelative(virtualDir), physicalDir).Unwrap());
        }
Exemple #4
0
 public void EnumerateAppDomains(out IAppDomainInfoEnum appDomainInfoEnum)
 {
     try
     {
         AppDomainInfo[] appDomainInfos = ApplicationManager.GetApplicationManager().GetAppDomainInfos();
         appDomainInfoEnum = new AppDomainInfoEnum(appDomainInfos);
     }
     catch (Exception exception)
     {
         using (new ProcessImpersonationContext())
         {
             Misc.ReportUnhandledException(exception, new string[] { System.Web.SR.GetString("Failure_AppDomain_Enum") });
         }
         throw;
     }
 }
Exemple #5
0
 private ProcessHost(IProcessHostSupportFunctions functions)
 {
     try
     {
         this._functions = functions;
         HostingEnvironment.SupportFunctions = functions;
         this._appManager = ApplicationManager.GetApplicationManager();
         int initialCount = (int)Misc.GetAspNetRegValue(null, "MaxPreloadConcurrency", 0);
         if (initialCount > 0)
         {
             this._preloadingThrottle = new Semaphore(initialCount, initialCount);
         }
     }
     catch (Exception exception)
     {
         using (new ProcessImpersonationContext())
         {
             Misc.ReportUnhandledException(exception, new string[] { System.Web.SR.GetString("Cant_Create_Process_Host") });
         }
         throw;
     }
 }
Exemple #6
0
        public AppManagerAppDomainFactory()
        {
            _appManager = ApplicationManager.GetApplicationManager();

            _appManager.Open();
        }
Exemple #7
0
        internal LowPhysicalMemoryMonitor()
        {
            /*
             * The chart below shows physical memory in megabytes, and the 1, 3, and 10% values.
             *
             * RAM     1%      3%      10%
             * -----------------------------
             * 128     1.28    3.84    12.8
             * 256     2.56    7.68    25.6
             * 512     5.12    15.36   51.2
             * 1024    10.24   30.72   102.4
             * 2048    20.48   61.44   204.8
             * 4096    40.96   122.88  409.6
             * 8192    81.92   245.76  819.2
             *
             * Low memory notifications from CreateMemoryResourceNotification are calculated as follows
             * (.\base\ntos\mm\initsup.c):
             *
             * MiInitializeMemoryEvents() {
             * ...
             * //
             * // Scale the threshold so on servers the low threshold is
             * // approximately 32MB per 4GB, capping it at 64MB.
             * //
             *
             * MmLowMemoryThreshold = MmPlentyFreePages;
             *
             * if (MmNumberOfPhysicalPages > 0x40000) {
             *    MmLowMemoryThreshold = MI_MB_TO_PAGES (32);
             *    MmLowMemoryThreshold += ((MmNumberOfPhysicalPages - 0x40000) >> 7);
             * }
             * else if (MmNumberOfPhysicalPages > 0x8000) {
             *    MmLowMemoryThreshold += ((MmNumberOfPhysicalPages - 0x8000) >> 5);
             * }
             *
             * if (MmLowMemoryThreshold > MI_MB_TO_PAGES (64)) {
             *    MmLowMemoryThreshold = MI_MB_TO_PAGES (64);
             * }
             * ...
             *
             * E.g.
             *
             * RAM(mb) low      %
             * -------------------
             * 256	  20	  92%
             * 512	  24	  95%
             * 768	  28	  96%
             * 1024	  32	  97%
             * 2048	  40	  98%
             * 3072	  48	  98%
             * 4096	  56	  99%
             * 5120	  64	  99%
             */

            long memory = AspNetMemoryMonitor.s_totalPhysical;

            Debug.Assert(memory != 0, "memory != 0");
            if (memory >= 0x100000000)
            {
                _pressureHigh = 99;
            }
            else if (memory >= 0x80000000)
            {
                _pressureHigh = 98;
            }
            else if (memory >= 0x40000000)
            {
                _pressureHigh = 97;
            }
            else if (memory >= 0x30000000)
            {
                _pressureHigh = 96;
            }
            else
            {
                _pressureHigh = 95;
            }

            _pressureLow = _pressureHigh - 9;

            InitHistory();

            _appManager = ApplicationManager.GetApplicationManager();

            _observers = new List <IObserver <LowPhysicalMemoryInfo> >();

            CacheSection  cacheConfig  = null;
            RuntimeConfig lkgAppConfig = RuntimeConfig.GetAppLKGConfig();
            RuntimeConfig appConfig    = null;

            try {
                appConfig   = RuntimeConfig.GetAppConfig();
                cacheConfig = appConfig.Cache;
            }
            catch (Exception) {
                cacheConfig = lkgAppConfig.Cache;
            }
            ReadConfig(cacheConfig);

            // 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);

            // start timer with initial poll interval
            _timer = new Timer(new TimerCallback(this.MonitorThread), null, Timeout.Infinite, _currentPollInterval);
        }