AddServer() public method

Adds a new server to the sockIOPool.
public AddServer ( string address ) : void
address string The address and the port of the server in the format 'host:port'.
return void
Exemplo n.º 1
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            // or just initialize the client from code
            var nscc = new MembaseClientConfiguration();

            nscc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 2);
            nscc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10);

            nscc.Urls.Add(new Uri("http://192.168.2.160:8091/pools/default"));
            //nscc.Urls.Add(new Uri("http://192.168.2.162:8091/pools/default"));
            nscc.Credentials = new NetworkCredential("A", "11111111");
            nscc.PerformanceMonitorFactory = new Membase.Configuration.DefaultPerformanceMonitorFactory();
            //nscc.BucketPassword = "******";

            ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_A_"));
            ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient("content"), "TesT_B_"));

            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_B_"));
            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_C_"));
            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_D_"));

            Console.ReadLine();

            return;

            var mcc = new MemcachedClientConfiguration();
            mcc.AddServer("192.168.2.200:11211");
            mcc.AddServer("192.168.2.202:11211");

            mcc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 4);
            mcc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 4);
            mcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10);

            StressTest(new MemcachedClient(mcc), "TesT_");

            return;

            var nc = new MembaseClient(nscc, "content");

            var stats1 = nc.Stats("slabs");
            foreach (var kvp in stats1.GetRaw("curr_connections"))
                Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);

            var nc2 = new MembaseClient(nscc, "content");

            var stats2 = nc2.Stats();
            foreach (var kvp in stats2.GetRaw("curr_connections"))
                Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);
        }
Exemplo n.º 2
0
 public void Setup()
 {
     var configuration = new MemcachedClientConfiguration();
     configuration.AddServer("127.0.0.1", PortNumber);
     _memcachedEntityTagStore = new MemcachedEntityTagStore(configuration);
     _memcachedEntityTagStore.Clear();
 }
        public void SetUp()
        {
            var config = new MemcachedClientConfiguration();
            config.AddServer("127.0.0.1", 11211);

            _Client = new MemcachedClient(config);
        }
Exemplo n.º 4
0
		public void TestThrottlingFailurePolicy()
		{
			var config = new MemcachedClientConfiguration();
			config.AddServer("nonexisting.enyim.com:2244");

			config.SocketPool.FailurePolicyFactory = new ThrottlingFailurePolicyFactory(4, TimeSpan.FromMilliseconds(2000));
			config.SocketPool.ConnectionTimeout = TimeSpan.FromMilliseconds(10);
			config.SocketPool.ReceiveTimeout = TimeSpan.FromMilliseconds(10);
			config.SocketPool.MinPoolSize = 1;
			config.SocketPool.MaxPoolSize = 1;

			var client = new MemcachedClient(config);
			var canFail = false;
			var didFail = false;

			client.NodeFailed += node =>
			{
				Assert.IsTrue(canFail, "canfail");

				didFail = true;
			};

			Assert.IsNull(client.Get("a"), "Get should have failed. 1");
			Assert.IsNull(client.Get("a"), "Get should have failed. 2");

			canFail = true;
			Thread.Sleep(2000);

			Assert.IsNull(client.Get("a"), "Get should have failed. 3");
			Assert.IsNull(client.Get("a"), "Get should have failed. 4");
			Assert.IsNull(client.Get("a"), "Get should have failed. 5");
			Assert.IsNull(client.Get("a"), "Get should have failed. 6");

			Assert.IsTrue(didFail, "didfail");
		}
        public override void Initialize()
        {
            lock (locker) {
                // Check we don't already have a client
                if (client != null) return;

                // Set up configuration
                config = new MemcachedClientConfiguration();

                var ts = new TimeSpan(0,0,30);

                config.SocketPool.ConnectionTimeout = ts;
                config.SocketPool.ReceiveTimeout = ts;
                config.SocketPool.DeadTimeout = ts;
                //config.SocketPool.QueueTimeout = ys;
                config.SocketPool.MinPoolSize = 1;
                config.SocketPool.MaxPoolSize = 10;

                foreach(string server in cache_servers) config.AddServer(server);

                config.Protocol = MemcachedProtocol.Text;

                // Create client
                client = new MemcachedClient(config);
            }
        }
Exemplo n.º 6
0
 private void InitializeMemcachedClient()
 {
     var config = new MemcachedClientConfiguration();
     var address = ConfigurationManager.AppSettings.Get("MemcachedAddress");
     var port = Convert.ToInt32(ConfigurationManager.AppSettings.Get("MemcachedPort"));
     config.AddServer(address, port);
     Cache.Initialize(config);
 }
Exemplo n.º 7
0
        static MemcachedClientConfiguration GetConfig()
        {
            const string server = "192.168.0.8";
            const int port = 11211;

            var config = new MemcachedClientConfiguration();
            config.AddServer(server, port);
            return config;
        }
        public IMemcachedClient Create(IMemcachedSettings memcachedSettings)
        {
            var mcConfig = new MemcachedClientConfiguration();

            foreach (var server in memcachedSettings.Server)
                mcConfig.AddServer(server.Item1, server.Item2);

            mcConfig.Protocol = MemcachedProtocol.Text;
            return new MemcachedClient(mcConfig);
        }
 static MemcachedSessionStateStoreProvider()
 {
     SessionKey = ConfigurationManager.AppSettings["MemcachedSessionKey"] ?? "MemcachedSession";
     MemcachedClient = new Lazy<MemcachedClient>(() =>
     {
         var configuration = new MemcachedClientConfiguration();
         configuration.AddServer(ConfigurationManager.AppSettings["MemcachedServerAddress"]);
         configuration.Protocol = MemcachedProtocol.Binary;
         return new MemcachedClient(configuration);
     });
 }
Exemplo n.º 10
0
		public void TestIfCalled()
		{
			var config = new MemcachedClientConfiguration();
			config.AddServer("nonexisting.enyim.com:2244");

			config.SocketPool.FailurePolicyFactory = new FakePolicy();
			config.SocketPool.ConnectionTimeout = TimeSpan.FromSeconds(4);
			config.SocketPool.ReceiveTimeout = TimeSpan.FromSeconds(6);

			var client = new MemcachedClient(config);

			Assert.IsNull(client.Get("a"), "Get should have failed.");
		}
 public MemcacheCL()
 {
     MemcachedClientConfiguration config = new MemcachedClientConfiguration();
     config.AddServer(Settings.ipAddress, Settings.port);
     config.Protocol = MemcachedProtocol.Binary;
     try
     {
         _mc = new MemcachedClient(config);
     }
     catch (MemcachedClientException e)
     {
         Logger.Log(string.Format("Could not connect to the memcached daemon! Reason: {0}",e), Logger.LogType.Error, typeof(MemcacheCL));
     }
 }
Exemplo n.º 12
0
        public void Constructor()
        {
            // set service cache provider from app.config
            ServiceCacheManager.SetProvider(() => new MemcachedServiceCache());

            // set service cache provider from a IMemcachedClientConfiguration
            var configuration = new MemcachedClientConfiguration();
            configuration.AddServer("serveraddress", 11211);
            ServiceCacheManager.SetProvider(() => new MemcachedServiceCache(configuration));

            // set service cache provider from an existing MemcachedClient
            var memcachedClient = new MemcachedClient();
            ServiceCacheManager.SetProvider(() => new MemcachedServiceCache(memcachedClient));
        }
 protected override IServiceCache CreateServiceCache()
 {
     var configuration = new MemcachedClientConfiguration();
     configuration.AddServer("degssql01", 11211);
     return new MemcachedServiceCache(configuration);
 }
        public MemcachedClient GetClient() {
            // caches the ignored urls to prevent a query to the settings
            var servers = _cacheManager.Get("MemcachedSettingsPart.Servers",
                context => {
                    context.Monitor(_signals.When(MemcachedSettingsPart.CacheKey));

                    var part = _service.Value.GetSiteSettings().As<MemcachedSettingsPart>();

                    // initializes the client to notify it has to be constructed again
                    lock (_synLock) {
                        if (_client != null) {
                            _client.Dispose();
                        }
                        _client = null;
                    }
                    
                    return part.Servers;
                }
            );

            if (_client == null  && !String.IsNullOrEmpty(servers)) {
                var configuration = new MemcachedClientConfiguration();
                using (var urlReader = new StringReader(servers)) {
                    string server;
                    // ignore empty lines and comments (#)
                    while (null != (server = urlReader.ReadLine())) {
                        if (String.IsNullOrWhiteSpace(server) || server.Trim().StartsWith("#")) {
                            continue;
                        }

                        var values = server.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        int port = 11211;

                        if (values.Length == 2) {
                            Int32.TryParse(values[1], out port);
                        }

                        if (values.Length > 0) {
                            configuration.AddServer(values[0], port);
                        }
                    }

                    lock (_synLock) {
                        _client = new MemcachedClient(configuration);
                    }
                }

            }

            return _client;
        }
Exemplo n.º 15
0
        private static void MultigetSpeedTest()
        {
            //Enyim.Caching.LogManager.AssignFactory(new ConsoleLogFactory());
            var tmc = new MemcachedClientConfiguration();

            tmc.AddServer("172.16.203.2:11211");
            tmc.AddServer("172.16.203.2:11212");
            //tmc.AddServer("172.16.203.2:11213");
            //tmc.AddServer("172.16.203.2:11214");

            tmc.Protocol = MemcachedProtocol.Binary;
            //tmc.SocketPool.MinPoolSize = 1;
            //tmc.SocketPool.MaxPoolSize = 1;

            tmc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 4);
            tmc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 4);

            tmc.KeyTransformer = new DefaultKeyTransformer();

            var tc = new MemcachedClient(tmc);
            const string KeyPrefix = "asdfghjkl";

            var val = new byte[10 * 1024];
            val[val.Length - 1] = 1;

            for (var i = 0; i < 100; i++)
                if (!tc.Store(StoreMode.Set, KeyPrefix + i, val))
                    Console.WriteLine("Fail " + KeyPrefix + i);

            var keys = Enumerable.Range(0, 500).Select(k => KeyPrefix + k).ToArray();

            Console.WriteLine("+");

            var sw = Stopwatch.StartNew();
            //tc.Get(KeyPrefix + "4");
            //sw.Stop();
            //Console.WriteLine(sw.ElapsedMilliseconds);

            //sw = Stopwatch.StartNew();

            //var p = tc.Get2(keys);

            //sw.Stop();
            //Console.WriteLine(sw.ElapsedMilliseconds);

            //sw = Stopwatch.StartNew();

            //var t = tc.Get(keys);
            //Console.WriteLine(" --" + t.Count);

            //sw.Stop();
            //Console.WriteLine(sw.ElapsedMilliseconds);

            //Console.WriteLine("Waiting");
            //Console.ReadLine();

            //return;

            for (var i = 0; i < 100; i++)
            {
                const int MAX = 300;

                sw = Stopwatch.StartNew();
                for (var j = 0; j < MAX; j++) tc.Get(keys);
                sw.Stop();
                Console.WriteLine(sw.ElapsedMilliseconds);

                //sw = Stopwatch.StartNew();
                //for (var j = 0; j < MAX; j++) tc.GetOld(keys);
                //sw.Stop();
                //Console.WriteLine(sw.ElapsedMilliseconds);

                //sw = Stopwatch.StartNew();
                //for (var j = 0; j < MAX; j++)
                //    foreach (var k in keys) tc.Get(k);
                //sw.Stop();
                //Console.WriteLine(sw.ElapsedMilliseconds);

                Console.WriteLine("----");
            }

            Console.ReadLine();
            return;
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            // or just initialize the client from code
            var nscc = new MembaseClientConfiguration();

            nscc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 2);
            nscc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10);

            nscc.Urls.Add(new Uri("http://192.168.2.160:8091/pools/default"));
            //nscc.Urls.Add(new Uri("http://192.168.2.162:8091/pools/default"));
            //nscc.Credentials = new NetworkCredential("A", "11111111");
            //nscc.Bucket = "content";
            //nscc.BucketPassword = "******";

            var client = new MembaseClient(nscc);
            Console.WriteLine("Store = " + client.Store(StoreMode.Set, "4q", 1, new TimeSpan(0, 0, 4)));

            Console.WriteLine("Setting expiration to the far future.");
            //Console.ReadLine();

            client.Touch("4q", DateTime.Now.AddDays(1));

            Console.WriteLine("Wait for 4 sec.");
            Console.ReadLine();

            Console.WriteLine(client.Get("4q") ?? "<null>");

            //new MembaseClient(nscc, "data", "data").Store(StoreMode.Set, "q4", 2);
            //new MembaseClient(nscc, "feedback", null).Store(StoreMode.Set, "q4", 2);

            Console.ReadLine();

            //nscc.PerformanceMonitorFactory = new Membase.Configuration.DefaultPerformanceMonitorFactory();
            //nscc.BucketPassword = "******";

            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc), "TesT_A_"));
            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient("content", "content"), "TesT_B_"));

            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_B_"));
            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_C_"));
            //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_D_"));

            Console.ReadLine();

            return;

            var mcc = new MemcachedClientConfiguration();
            mcc.AddServer("192.168.2.200:11211");
            mcc.AddServer("192.168.2.202:11211");

            mcc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 4);
            mcc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 4);
            mcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10);

            StressTest(new MemcachedClient(mcc), "TesT_");

            return;

            var nc = new MembaseClient(nscc, "content", "content");

            var stats1 = nc.Stats("slabs");
            foreach (var kvp in stats1.GetRaw("curr_connections"))
                Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);

            var nc2 = new MembaseClient(nscc, "content", "content");

            var stats2 = nc2.Stats();
            foreach (var kvp in stats2.GetRaw("curr_connections"))
                Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);
        }
Exemplo n.º 17
0
        private void InitMC()
        {
            if (null == m_oMcConfig)
            {
                m_oMcConfig = new MemcachedClientConfiguration();

                string sServerName = ConfigurationManager.AppSettings["utils.taskresult.cacheddb.mc.server"] ?? "localhost:11211";

                m_oMcConfig.AddServer(sServerName);
                m_oMcConfig.Protocol = MemcachedProtocol.Text;
            }
        }