Example #1
0
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="cacheHostInformationPoller">The cache host information poller.</param>
        /// <param name="memCache">The mem cache to use for storing objects.</param>
        /// <param name="clientToCacheServiceHost">The client to cache service host.</param>
        /// <param name="cacheManagerClient">The cache manager client.</param>
        public CacheHostEngine(IRunnable cacheHostInformationPoller, MemCache memCache, ServiceHost clientToCacheServiceHost)
        {
            // Sanitize
            if (cacheHostInformationPoller == null)
            {
                throw new ArgumentNullException("cacheHostInformationPoller");
            }
            if (memCache == null)
            {
                throw new ArgumentNullException("memCache");
            }
            if (clientToCacheServiceHost == null)
            {
                throw new ArgumentNullException("clientToCacheServiceHost");
            }

            // Set the cache host information poller
            _cacheHostInformationPoller = cacheHostInformationPoller;

            // Set the mem cache container instance
            MemCacheContainer.Instance = memCache;

            // Initialize the service hosts
            _clientToCacheServiceHost = clientToCacheServiceHost;
        }
Example #2
0
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="configuration">The configuration to use for the cache host.</param>
        public CacheHostEngine(CacheHostConfigurationSection configuration)
        {
            // Sanitize
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            // Set default logger to file if necessary
            if (CustomLoggerLoader.DefaultLogger == null)
            {
                CustomLoggerLoader.DefaultLogger = new FileLogger();
            }

            var port = configuration.Port;
            var physicalMemoryLimitPercentage = configuration.CacheMemoryLimitPercentage;
            var maximumConnections = configuration.MaximumConnections;

            // Configure the performance counter data manager
            PerformanceDataManager performanceDataManager = null;
            try
            {
                performanceDataManager = new PerformanceCounterPerformanceDataManager(port);
            }
            catch (InvalidOperationException)
            {
                // Performance counters aren't installed, so don't use them
                performanceDataManager = new PerformanceDataManager();
            }

            // Determine the MemCache to use
            IMemCache memCache = new MemCache(physicalMemoryLimitPercentage, performanceDataManager);

            if (configuration.CompressData)
            {
                memCache = new GZipMemCache(memCache);
            }

            // Initialize the tag routing table
            var tagRoutingTable = new TagRoutingTable();

            // Initialize the cache host server
            var cacheHostServer = new CacheHostServer(memCache, tagRoutingTable, CustomLoggerLoader.LoadLogger(), configuration.Port, 
                configuration.MaximumConnections, configuration.MessageBufferSize, configuration.CommunicationTimeoutSeconds * 1000, configuration.MaximumMessageSizeKB * 1024);

            // Instantiate the cache host runner
            _cacheHostRunner = new CacheHostRunner(cacheHostServer);
        }
Example #3
0
        /// <summary>
        /// Fires when the windows service starts.
        /// </summary>
        /// <param name="args">The arguments passed, if any.</param>
        protected override void OnStart(string[] args)
        {
            _logger.Info("Cache Host is starting", "Cache Host is starting");

            // Configure the thread pool's minimum threads
            ThreadPool.SetMinThreads(128, 128);

            _logger.Info("Cache Host is starting", "Verifying settings");

            try
            {
                var port = CacheHostConfigurationSection.Settings.Port;

                // Configure the custom performance counter manager
                var customPerformanceCounterManager = new CustomPerformanceCounterManager(string.Format("port:{0}", port), false);

                // Initialize the mem cache container instance
                var physicalMemoryLimitPercentage = CacheHostConfigurationSection.Settings.CacheMemoryLimitPercentage;

                IMemCache memCache;
                var memoryCache = new MemCache("Dache", physicalMemoryLimitPercentage, customPerformanceCounterManager);

                if (CacheHostConfigurationSection.Settings.StorageProvider == typeof(GZipMemCache))
                {
                    memCache = new GZipMemCache(memoryCache);
                }
                else
                {
                    memCache = memoryCache;
                }

                // Initialize the tag routing table
                var tagRoutingTable = new TagRoutingTable();

                // Initialize the cache host server
                var maximumConnections = CacheHostConfigurationSection.Settings.MaximumConnections;
                var cacheHostServer = new CacheHostServer(memCache, tagRoutingTable, port, maximumConnections, 1024);

                // Initialize the cache host information poller
                var cacheHostInformationPoller = new CacheHostInformationPoller(memCache, customPerformanceCounterManager, 1000);

                // Instantiate the cache host engine
                _cacheHostEngine = new CacheHostEngine(cacheHostInformationPoller, cacheHostServer);
            }
            catch (Exception ex)
            {
                // The inner exception has the actual details of the configuration error
                if (ex.InnerException != null && ex.InnerException.Message != null && ex.InnerException.Message.StartsWith("The value for the property", StringComparison.OrdinalIgnoreCase))
                {
                    ex = ex.InnerException;
                }

                // Log the error
                _logger.Error("Cache Host failed to start", ex.Message);

                // Stop the service
                Stop();
            }

            _logger.Info("Cache Host is starting", "Settings verified successfully");

            _cacheHostEngine.Start();
        }
Example #4
0
        /// <summary>
        /// Fires when the windows service starts.
        /// </summary>
        /// <param name="args">The arguments passed, if any.</param>
        protected override void OnStart(string[] args)
        {
            LoggerContainer.Instance.Info("Cache Host is starting", "Cache Host is starting");

            // Configure the thread pool's minimum threads
            ThreadPool.SetMinThreads(128, 128);

            LoggerContainer.Instance.Info("Cache Host is starting", "Verifying settings");

            try
            {
                // Initialize the mem cache container instance
                var physicalMemoryLimitPercentage = CacheHostConfigurationSection.Settings.CacheMemoryLimitPercentage;

                var cacheConfig = new NameValueCollection();
                cacheConfig.Add("pollingInterval", "00:00:15");
                cacheConfig.Add("physicalMemoryLimitPercentage", physicalMemoryLimitPercentage.ToString());

                var memCache = new MemCache("Dache", cacheConfig);

                // Initialize the client to cache service host
                var clientToCacheServiceHost = new ServiceHost(typeof(ClientToCacheServer));
                // Configure the client to cache service host
                var cacheHostAddress = CacheHostConfigurationSection.Settings.Address;
                var cacheHostPort = CacheHostConfigurationSection.Settings.Port;
                // Build the endpoint address
                var endpointAddress = string.Format("net.tcp://{0}:{1}/Dache/CacheHost", cacheHostAddress, cacheHostPort);
                // Build the net tcp binding
                var netTcpBinding = CreateNetTcpBinding();
                // Service throttling
                var serviceThrottling = clientToCacheServiceHost.Description.Behaviors.Find<ServiceThrottlingBehavior>();
                if (serviceThrottling == null)
                {
                    serviceThrottling = new ServiceThrottlingBehavior
                    {
                        MaxConcurrentCalls = int.MaxValue,
                        MaxConcurrentInstances = int.MaxValue,
                        MaxConcurrentSessions = int.MaxValue
                    };

                    clientToCacheServiceHost.Description.Behaviors.Add(serviceThrottling);
                }

                // Configure the service endpoint
                clientToCacheServiceHost.AddServiceEndpoint(typeof(IClientToCacheContract), netTcpBinding, endpointAddress);

                // Configure the custom performance counter manager
                var serviceHostAddress = clientToCacheServiceHost.Description.Endpoints.First().Address.Uri;
                CustomPerformanceCounterManagerContainer.Instance = new CustomPerformanceCounterManager(string.Format("{0}_{1}", serviceHostAddress.Host, serviceHostAddress.Port), false);

                // Initialize the cache host information poller
                var cacheHostInformationPoller = new CacheHostInformationPoller(1000);

                // Instantiate the cache host engine
                _cacheHostEngine = new CacheHostEngine(cacheHostInformationPoller, memCache, clientToCacheServiceHost);
            }
            catch (Exception ex)
            {
                // The inner exception has the actual details of the configuration error
                if (ex.InnerException != null && ex.InnerException.Message != null && ex.InnerException.Message.StartsWith("The value for the property", StringComparison.OrdinalIgnoreCase))
                {
                    ex = ex.InnerException;
                }

                // Log the error
                LoggerContainer.Instance.Error("Cache Host failed to start", ex.Message);

                // Stop the service
                Stop();
            }

            LoggerContainer.Instance.Info("Cache Host is starting", "Settings verified successfully");

            _cacheHostEngine.Start();
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GZipMemCache"/> class.
 /// </summary>
 /// <param name="memCache">The memory cache.</param>
 public GZipMemCache(MemCache memCache)
 {
     _memCache = memCache;
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GZipMemCache"/> class.
 /// </summary>
 /// <param name="memCache">The memory cache.</param>
 public GZipMemCache(MemCache memCache)
 {
     _memCache = memCache;
 }