คำตอบที่เสนอ Handling Load Balancing

  • 23 เมษายน 2555 8:05
     
     
    Guys,

    Im new in Implementing AppFabric, i have a few basic questions..
    we are using "SQL Server " as cache provider


    1) where the cache data gets stored in the local system (or) sql- server

    2) we are having load balenced networks, there are 2 dedidcated wcf servers so how can i handle the scenario with app fabric
                
                 (a) Can i have the same "Cache Port" number in the two servers, while installing app fabric if i select the "Join Cluster" is that enough.. if not how can i handle the app fabric code..


    pls guide me in this..

ตอบทั้งหมด

  • 23 เมษายน 2555 20:34
     
     คำตอบที่เสนอ

    Hi Kumar,

    Is you are using SQL Server as a config store, it will serve two purposes:

    1) Serve as a config store (this is where the configuration of the cache cluster is stored)

    2) Serve as a Cluster Manager. It will manage the cluster, help new hosts to join, etc.

    It will not hold the cache data. All cache data is stored in memory of the cache host.

    For your second question, if I understand you correctly, that you have 2 cache hosts that have a the same Cache ports will that be fine. Yes, because although they are the Same Cache Port "22233" for example, they are on two different servers.

    Once you have installed the and configured the first cache node, all you should have to do is "join Cluster" for all the subsequent nodes.


    Mohammad Faridi.

    • เสนอเป็นคำตอบโดย Mohammad Faridi 23 เมษายน 2555 20:34
    •  
  • 24 เมษายน 2555 2:33
     
     

    Hi folks,

    Adding to Faridi's point: While using SQL for a config store is good... you have two options to use either SQL for cluster mgmt or use lead host mgmt. The lead host mgmt is recommended for clusters with 3 or more cache servers as SQL will not be a single point of failure.

    For more details, please see here: http://msdn.microsoft.com/en-us/library/hh334351.aspx

    thanks,
    Prashant

  • 24 เมษายน 2555 4:40
     
     

    Thanks for ur replies,

    Faridi u have understood my concern correctly.. please see the below 3 cs files im using in my project..

    in my "CacheUtility.cs" pls see the method "GetCache" in that im trying to add two different servers is that enough am i going in right direction in handling two cache hosts..

    can u pls go through the different cs files im using in handling the appfabric, are all these required.. help me in understanding this..

    CacheUtility.cs
    ================


            private static DataCacheFactory factory = null;
            private static DataCache cache = null;
            private const string appFabricCacheGroup = "AppFabricCacheGroup/AppFabricCache";
            private const string defaultKey = "default";
            private const string cachePortkey = "CachePort";



            public static DataCache GetCache()
            {
                if (cache != null)
                {
                    return cache;
                }
                else
                {
                    // Define Array for a single Cache Host.
                    List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(1);

                    CacheConfigSection config = (CacheConfigSection)System.Configuration.ConfigurationManager.
                    GetSection(appFabricCacheGroup);
                    servers.Add(new DataCacheServerEndpoint(config.AppFabricHost.HostName, Convert.ToInt32(config.AppFabricHost.Port)));

    //here im trying to add one more server ....

                    // Create cache configuration.
                    DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();

                    configuration.Servers = servers;

                    // Set default properties for local cache (local cache disabled).
                    configuration.LocalCacheProperties = new DataCacheLocalCacheProperties();

                    configuration.SecurityProperties = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None);
                    configuration.MaxConnectionsToServer = config.MaxConnections;
                    configuration.ChannelOpenTimeout = config.ChannelOpenTimeout;
                    configuration.RequestTimeout = config.RequestTimeout;

                    // Disable tracing to avoid informational/verbose messages on the web page.
                    DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);

                    factory = new DataCacheFactory(configuration);

                    // Get reference to named cache called "default".
                    cache = factory.GetCache(defaultKey);
                }
                return cache;
            }

      public static void Add(string key, object value)
            {
                cache = GetCache();
                cache.Add(key, value);
            }

    public static Boolean Remove(string key)
            {
                cache = GetCache();
                return cache.Remove(key);
            }

     public static void Update(string key, object value)
            {
                cache = GetCache();
                cache.Put(key, value);
            }



    CacheConfigSection.cs
    ======================

     public class CacheConfigSection : ConfigurationSection
        {


            private const string appFabricHost = "AppFabricHost";
            private const string appFabricHostTwo = "AppFabricHost2";
            private const string maxConnections = "MaxConnections";
            private const string channelOpenTimeout = "ChannelOpenTimeout";
            private const string requestTimeout = "RequestTimeout";
            private const string namedCache = "NamedCache";
            private const string defaultValue = "000000";





            // Create a "AppFabricHost" attribute.
            [ConfigurationProperty(appFabricHost, IsRequired = true)]
            public CacheConfigSectionElement AppFabricHost
            {
                get
                {
                    return (CacheConfigSectionElement)this[appFabricHost];
                }
                set
                {
                    this[appFabricHost] = value;
                }
            }

            [ConfigurationProperty(appFabricHostTwo, IsRequired = true)]
            public CacheConfigSectionElement AppFabricHost2
            {
                get
                {
                    return (CacheConfigSectionElement)this[appFabricHostTwo];
                }
                set
                {
                    this[appFabricHostTwo] = value;
                }
            }

            [ConfigurationProperty(maxConnections, DefaultValue = defaultValue, IsRequired = true)]
            public int MaxConnections
            {
                get
                {
                    return (int)this[maxConnections];
                }
                set
                {
                    this[maxConnections] = value;
                }
            }

            [ConfigurationProperty(channelOpenTimeout, DefaultValue = defaultValue, IsRequired = true)]
            public TimeSpan ChannelOpenTimeout
            {
                get
                {
                    return (TimeSpan)this[channelOpenTimeout];
                }
                set
                {
                    this[channelOpenTimeout] = value;
                }
            }

            [ConfigurationProperty(requestTimeout, DefaultValue = defaultValue, IsRequired = true)]
            public TimeSpan RequestTimeout
            {
                get
                {
                    return (TimeSpan)this[requestTimeout];
                }
                set
                {
                    this[requestTimeout] = value;
                }
            }

            [ConfigurationProperty(namedCache, DefaultValue = defaultValue, IsRequired = true)]
            public String NamedCache
            {
                get
                {
                    return (String)this[namedCache];
                }
                set
                {
                    this[namedCache] = value;
                }
            }

            #endregion
        }



    CacheConfigSectionElement.cs
    =============================



    public class CacheConfigSectionElement : ConfigurationElement
        {


            private const string hostName = "HostName";
            private const string port = "Port";
            private const string defaultValueOne = "FFFFFF";
            private const string defaultValueTwo = "000000";





            [ConfigurationProperty(hostName, DefaultValue = defaultValueOne, IsRequired = true)]
            public String HostName
            {
                get
                {
                    return (String)this[hostName];
                }
                set
                {
                    this[hostName] = value;
                }
            }

            [ConfigurationProperty(port, DefaultValue = defaultValueTwo, IsRequired = true)]
            public String Port
            {
                get
                {
                    return (String)this[port];
                }
                set
                {
                    this[port] = value;
                }
            }


        }