void InitMemcache() { pool.SetWeights(new int[] { 1 }); //初始化时创建连接数 pool.InitConnections = 3; //最小连接数 pool.MinConnections = 3; //最大连接数 pool.MaxConnections = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["MemcacheMax"] ?? "10000"); //连接的最大空闲时间,下面设置为6个小时(单位ms),超过这个设置时间,连接会被释放掉 pool.MaxIdle = 1000 * 60; //socket连接的超时时间,下面设置表示不超时(单位ms),即一直保持链接状态 pool.SocketConnectTimeout = 10000; //通讯的超市时间,下面设置为3秒(单位ms),.Net版本没有实现 pool.SocketTimeout = 1000 * 3; //维护线程的间隔激活时间,下面设置为30秒(单位s),设置为0时表示不启用维护线程 pool.MaintenanceSleep = 30; //设置SocktIO池的故障标志 pool.Failover = true; //是否对TCP/IP通讯使用nalgle算法,.net版本没有实现 pool.Nagle = false; //socket单次任务的最大时间(单位ms),超过这个时间socket会被强行中端掉,当前任务失败。 pool.MaxBusy = 1000 * 10; pool.Initialize(); cacheManager = new MemcachedClient(); //是否启用压缩数据:如果启用了压缩,数据压缩长于门槛的数据将被储存在压缩的形式 cacheManager.EnableCompression = false; //压缩设置,超过指定大小的都压缩 //cache.CompressionThreshold = 1024 * 1024; }
static void InitPool(SockIOPool pool) { string[] services = { "127.0.0.1:11211" }; pool.SetServers(services); //各服务器之间负载均衡的设置比例 pool.SetWeights(new int[] { 1 }); //初始化时创建连接数 pool.InitConnections = 3; //最小连接数 pool.MinConnections = 3; //最大连接数 pool.MaxConnections = 5; //连接的最大空闲时间,下面设置为6个小时(单位ms),超过这个设置时间,连接会被释放掉 pool.MaxIdle = 1000 * 60 * 60 * 6; //socket连接的超时时间,下面设置表示不超时(单位ms),即一直保持链接状态 pool.SocketConnectTimeout = 0; //通讯的超市时间,下面设置为3秒(单位ms),.Net版本没有实现 pool.SocketTimeout = 1000 * 3; //维护线程的间隔激活时间,下面设置为30秒(单位s),设置为0时表示不启用维护线程 pool.MaintenanceSleep = 30; //设置SocktIO池的故障标志 pool.Failover = true; //是否对TCP/IP通讯使用nalgle算法,.net版本没有实现 pool.Nagle = false; //socket单次任务的最大时间(单位ms),超过这个时间socket会被强行中端掉,当前任务失败。 pool.MaxBusy = 1000 * 10; pool.Initialize(); }
/// <summary> /// 自动货源切换管理服务 /// </summary> static void Main() { SockIOPool pool2 = SockIOPool.GetInstance("Price_Cache"); string[] serverlist2 = ConfigurationManager.AppSettings["ServerList2"].Split(','); pool2.SetServers(serverlist2); pool2.SetWeights(new int[] { 1 }); pool2.InitConnections = 5; pool2.MinConnections = 5; pool2.MaxConnections = 280; pool2.MaxIdle = 1000 * 60 * 60 * 6; pool2.SocketTimeout = 1000 * 3; pool2.SocketConnectTimeout = 0; pool2.SocketTimeout = 3000; pool2.MaintenanceSleep = 60; pool2.Failover = true; pool2.Nagle = false; pool2.MaxBusy = 1000 * 10; pool2.Initialize(); ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(ServicesToRun); }
static MemCachedManager() { string[] servers = { "127.0.0.1:11211" }; //初始化池 SockIOPool pool = SockIOPool.GetInstance(); //设置服务器列表 pool.SetServers(servers); //设置各服务之间负责均衡的权重 pool.SetWeights(new int[] { 1 }); //初始化时创建连接数 pool.InitConnections = 3; //最小连接数 pool.MinConnections = 3; //最大连接数 pool.MaxConnections = 5; //连接的最大空闲时间,下面设置为6个小时(单位为ms),超过这个设置时间,连接会被释放 pool.MaxIdle = 1000 * 60 * 60 * 6; //socket连接的超时时间,为0表示永不超时,即一直保持连接状态 pool.SocketConnectTimeout = 0; //通讯的超时时间,下面设置为3秒,.net版本没有实现 pool.SocketTimeout = 1000 * 3; //维护线程的间隔激活时间,下面设置为30秒(单位s),设置为0时表示不启用维护线程 pool.MaintenanceSleep = 30; //设置SocketIO池的故障标志 pool.Failover = true; //是否对TCP/IP通讯使用nalgle算法,.net版本没有实现 pool.Nagle = false; //socket单次任务的最大时间(单位ms),超过这个时间socket会被强行中断,当前任务失败 pool.MaxBusy = 1000 * 10; pool.Initialize(); cache = new MemcachedClient(); //是否启用压缩数据:如果启用了压缩,数据压缩长于门槛的数据将被储存在压缩的形式 cache.EnableCompression = false; }
public cr_yppf() { InitializeComponent(); SockIOPool pool2 = SockIOPool.GetInstance("Price_Cache"); string[] serverlist2 = ConfigurationManager.AppSettings["ServerList2"].Split(','); pool2.SetServers(serverlist2); pool2.SetWeights(new int[] { 1 }); pool2.InitConnections = 5; pool2.MinConnections = 5; pool2.MaxConnections = 280; pool2.MaxIdle = 1000 * 60 * 60 * 6; pool2.SocketTimeout = 1000 * 3; pool2.SocketConnectTimeout = 0; pool2.SocketTimeout = 3000; pool2.MaintenanceSleep = 60; pool2.Failover = true; pool2.Nagle = false; pool2.MaxBusy = 1000 * 10; pool2.Initialize(); backgroundWorker4.RunWorkerAsync(); //销售数量处理 backgroundWorker5.RunWorkerAsync(); //处理商品价格 SOSOshop.BLL.Logs.Log.LogServiceAdd("商城消息处理服务启动成功...", 0, "", "MSG", "", 1); }
/// <summary> /// 创建链接池管理对象 /// </summary> public static void CreateManager() { //MemCachedConfigInfo = MemCachedConfigs.GetConfig(); //serverList = Utils.SplitString(MemCachedConfigInfo.ServerList, ","); serverList = MemCachedConfig.ServerList.Split(',');// Utils.SplitString(MemCachedConfigInfo.ServerList, ","); pool = SockIOPool.GetInstance(MemCachedConfig.PoolName); pool.SetServers(serverList); pool.SetWeights(viviLib.Utils.TypeParse.StringToIntArray(MemCachedConfig.ServerList, 1)); pool.InitConnections = MemCachedConfig.IntConnections; //初始化链接数 pool.MinConnections = MemCachedConfig.MinConnections; //最少链接数 pool.MaxConnections = MemCachedConfig.MaxConnections; //最大连接数 pool.SocketConnectTimeout = MemCachedConfig.SocketConnectTimeout; //Socket链接超时时间 pool.SocketTimeout = MemCachedConfig.SocketTimeout; // Socket超时时间 pool.MaintenanceSleep = MemCachedConfig.MaintenanceSleep; //维护线程休息时间 pool.Failover = MemCachedConfig.FailOver; //失效转移(一种备份操作模式) pool.Nagle = MemCachedConfig.Nagle; //是否用nagle算法启动socket pool.HashingAlgorithm = HashingAlgorithm.NewCompatibleHash; pool.Initialize(); mc = new MemcachedClient(); mc.PoolName = MemCachedConfig.PoolName; mc.EnableCompression = false; }
private void init(List <CachePool> pools) { foreach (CachePool p in pools) { if (cacheClients.ContainsKey(p.Name)) { throw new Exception("Duplicate configuration for the pool name : " + p.Name); } MemcachedClient client = new MemcachedClient(); //TODO:考虑增加是否压缩的配置选项 client.EnableCompression = false; SockIOPool pool = null; if (p.Name.Equals("default instance") || string.IsNullOrEmpty(p.Name)) { pool = SockIOPool.GetInstance(); defaultClient = client; } else { pool = SockIOPool.GetInstance(p.Name); client.PoolName = p.Name; } pool.SetServers(p.Servers); pool.SetWeights(p.Weights); pool.InitConnections = p.InitConnections; pool.MinConnections = p.MinConnections; pool.MaxConnections = p.MaxConnections; pool.MaxIdle = p.MaxIdle; pool.SocketConnectTimeout = p.SocketConnectTimeout; pool.SocketTimeout = p.SocketTimeout; pool.MaintenanceSleep = p.MaintenanceSleep; pool.Failover = p.Failover; pool.Nagle = p.Nagle; pool.Initialize(); cacheClients.Add(p.Name, client); } if (defaultClient == null) { throw new Exception("Missing the configuration for default cache pool"); } }
/// <summary> /// 初始化MemCahce /// </summary> public MemCache() { try { //memchached服务IP 和端口 string[] servers = { "127.0.0.1:11211" }; //初始化池 SockIOPool pool = SockIOPool.GetInstance(); //设置服务器列表 pool.SetServers(servers); //各服务器之间负载均衡的设置比例 pool.SetWeights(new int[] { 1 }); //初始化时创建连接数 pool.InitConnections = 3; //最小连接数 pool.MinConnections = 3; //最大连接数 pool.MaxConnections = 5; //连接的最大空闲时间,下面设置为6个小时(单位ms),超过这个设置时间,连接会被释放掉 pool.MaxIdle = 1000 * 60 * 60 * 6; //socket连接的超时时间,下面设置表示不超时(单位ms),即一直保持链接状态 pool.SocketConnectTimeout = 0; //通讯的超市时间,下面设置为3秒(单位ms),.Net版本没有实现 pool.SocketTimeout = 1000 * 3; //维护线程的间隔激活时间,下面设置为30秒(单位s),设置为0时表示不启用维护线程 pool.MaintenanceSleep = 30; //设置SocktIO池的故障标志 pool.Failover = true; //是否对TCP/IP通讯使用nalgle算法,.net版本没有实现 pool.Nagle = false; //socket单次任务的最大时间(单位ms),超过这个时间socket会被强行中端掉,当前任务失败。 pool.MaxBusy = 1000 * 10; pool.Initialize(); cache = new MemcachedClient(); //是否启用压缩数据:如果启用了压缩,数据压缩长于门槛的数据将被储存在压缩的形式 cache.EnableCompression = false; //压缩设置,超过指定大小的都压缩 //cache.CompressionThreshold = 1024 * 1024; } catch (Exception e) { e.ToString(); } }
static MemcacheHelper() { string[] serverlist = { "192.168.10.61:11212" };//一定要将地址写到Web.config文件中。 //初始化池 SockIOPool pool = SockIOPool.GetInstance(); pool.SetServers(serverlist); //各服务器之间负载均衡的设置比例 pool.SetWeights(new int[] { 1 }); //初始化时创建连接数 pool.InitConnections = 3; //最小连接数 pool.MinConnections = 3; //最大连接数 pool.MaxConnections = 5; //连接的最大空闲时间,下面设置为6个小时(单位ms),超过这个设置时间,连接会被释放掉 pool.MaxIdle = 1000 * 60 * 60 * 6; //socket连接的超时时间,下面设置表示不超时(单位ms),即一直保持链接状态 pool.SocketConnectTimeout = 0; //维护线程的间隔激活时间,下面设置为30秒(单位s),设置为0时表示不启用维护线程 pool.MaintenanceSleep = 30; //设置SocktIO池的故障标志 pool.Failover = true; //通讯的超市时间,下面设置为3秒(单位ms),.Net版本没有实现 pool.SocketTimeout = 1000 * 3; //是否对TCP/IP通讯使用nalgle算法,.net版本没有实现 pool.Nagle = false; //socket单次任务的最大时间(单位ms),超过这个时间socket会被强行中端掉,当前任务失败。 pool.MaxBusy = 1000 * 10; pool.Initialize(); // 获得客户端实例 mc = new MemcachedClient(); //是否启用压缩数据:如果启用了压缩,数据压缩长于门槛的数据将被储存在压缩的形式 mc.EnableCompression = false; //压缩设置,超过指定大小的都压缩 //mc.CompressionThreshold = 1024 * 1024; }
protected void Application_Start() { MvcHandler.DisableMvcResponseHeader = true; AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); SockIOPool pool = SockIOPool.GetInstance(); string[] serverlist = ConfigurationManager.AppSettings["ServerList"].Split(','); pool.SetServers(serverlist); pool.SetWeights(new int[] { 1 }); pool.InitConnections = 5; pool.MinConnections = 5; pool.MaxConnections = 280; pool.MaxIdle = 1000 * 60 * 60 * 6; pool.SocketTimeout = 1000 * 3; pool.SocketConnectTimeout = 0; pool.SocketTimeout = 3000; pool.MaintenanceSleep = 60; pool.Failover = true; pool.Nagle = false; pool.MaxBusy = 1000 * 10; pool.Initialize(); SockIOPool pool2 = SockIOPool.GetInstance("Price_Cache"); string[] serverlist2 = ConfigurationManager.AppSettings["ServerList2"].Split(','); pool2.SetServers(serverlist2); pool2.SetWeights(new int[] { 1 }); pool2.InitConnections = 5; pool2.MinConnections = 5; pool2.MaxConnections = 280; pool2.MaxIdle = 1000 * 60 * 60 * 6; pool2.SocketTimeout = 1000 * 3; pool2.SocketConnectTimeout = 0; pool2.SocketTimeout = 3000; pool2.MaintenanceSleep = 60; pool2.Failover = true; pool2.Nagle = false; pool2.MaxBusy = 1000 * 10; pool2.Initialize(); }
protected void Application_Start() { SockIOPool pool = SockIOPool.GetInstance(); string[] serverlist = ConfigurationManager.AppSettings["ServerList"].Split(','); pool.SetServers(serverlist); pool.SetWeights(new int[] { 1 }); pool.InitConnections = 5; pool.MinConnections = 5; pool.MaxConnections = 280; pool.MaxIdle = 1000 * 60 * 60 * 6; pool.SocketTimeout = 1000 * 3; pool.SocketConnectTimeout = 0; pool.SocketTimeout = 3000; pool.MaintenanceSleep = 60; pool.Failover = true; pool.Nagle = false; pool.MaxBusy = 1000 * 10; pool.Initialize(); }
protected void Application_Start(object sender, EventArgs e) { SockIOPool pool2 = SockIOPool.GetInstance("Price_Cache"); string[] serverlist2 = ConfigurationManager.AppSettings["ServerList2"].Split(','); pool2.SetServers(serverlist2); pool2.SetWeights(new int[] { 1 }); pool2.InitConnections = 5; pool2.MinConnections = 5; pool2.MaxConnections = 280; pool2.MaxIdle = 1000 * 60 * 60 * 6; pool2.SocketTimeout = 1000 * 3; pool2.SocketConnectTimeout = 0; pool2.SocketTimeout = 3000; pool2.MaintenanceSleep = 60; pool2.Failover = true; pool2.Nagle = false; pool2.MaxBusy = 1000 * 10; pool2.Initialize(); }
public MemcacheWriter() { string[] servers = strMemcacheServer.Split(','); //初始化池 SockIOPool pool = SockIOPool.GetInstance(); //设置服务器列表 pool.SetServers(servers); //各服务器之间负载均衡的设置比例 pool.SetWeights(new int[] { 1, 10 }); //初始化时创建连接数 pool.InitConnections = 3; //最小连接数 pool.MinConnections = 3; //最大连接数 pool.MaxConnections = 5; //连接的最大空闲时间,下面设置为6个小时(单位ms),超过这个设置时间,连接会被释放掉 pool.MaxIdle = 1000 * 60 * 60 * 6; //socket连接的超时时间,下面设置表示不超时(单位ms),即一直保持链接状态 pool.SocketConnectTimeout = 0; //通讯的超时时间,下面设置为3秒(单位ms),.Net版本没有实现 pool.SocketTimeout = 1000 * 3; //维护线程的间隔激活时间,下面设置为30秒(单位s),设置为0时表示不启用维护线程 pool.MaintenanceSleep = 30; //设置SocktIO池的故障标志 pool.Failover = true; //是否对TCP/IP通讯使用nalgle算法,.net版本没有实现 pool.Nagle = false; //socket单次任务的最大时间(单位ms),超过这个时间socket会被强行中端掉,当前任务失败。 pool.MaxBusy = 1000 * 10; // 初始化一些值并与MemcachedServer段建立连接 pool.Initialize(); cache = new MemcachedClient(); //是否启用压缩数据:如果启用了压缩,数据压缩长于门槛的数据将被储存在压缩的形式 cache.EnableCompression = false; //压缩设置,超过指定大小的都压缩 //cache.CompressionThreshold = 1024 * 1024; //指定客户端访问的SockIO池 //cache.PoolName = poolName; }
/// <summary> /// 初始化Memcached /// </summary> private static void InitMemcached() { // 初始化连接池 try { // 从连接池获取一个连接实例 SockIOPool pool = SockIOPool.GetInstance(); //设置服务器列表 pool.SetServers(s.ToArray()); //设置服务器负载量 pool.SetWeights(w.ToArray()); //初始连接数 pool.InitConnections = 3; //最小连接数 3 pool.MinConnections = 3; //最大连接数 50 pool.MaxConnections = 50; // 连接超时 时间 pool.SocketConnectTimeout = 1000; //设置 读取 超时3秒钟 pool.SocketTimeout = 3000; // 设置主线程睡眠时间,每隔30秒醒来 pool.MaintenanceSleep = 30; //服务器失效转移 pool.Failover = true; // 关闭nagle算法 pool.Nagle = false; pool.Initialize(); } catch (Exception ex) { throw ex; } }
private static void SockIOPoolInit() { String[] serverlist = { "127.0.0.1:11211" }; _pool = SockIOPool.GetInstance("default"); _pool.SetServers(serverlist); //设置服务器列表 //各服务器之间负载均衡的设置 _pool.SetWeights(new int[] { 1 }); //socket pool设置 _pool.InitConnections = 5; //初始化时创建的连接数 _pool.MinConnections = 5; //最小连接数 _pool.MaxConnections = 250; //最大连接数 //连接的最大空闲时间,下面设置为6个小时(单位ms),超过这个设置时间,连接会被释放掉 _pool.MaxIdle = 1000 * 60 * 60 * 6; //通讯的超时时间,下面设置为3秒(单位ms),.NET版本没有实现 _pool.SocketTimeout = 1000 * 3; //socket连接的超时时间,下面设置表示连接不超时,即一直保持连接状态 _pool.SocketConnectTimeout = 0; _pool.Nagle = false; //是否对TCP/IP通讯使用Nalgle算法,.NET版本没有实现 //维护线程的间隔激活时间,下面设置为60秒(单位s),设置为0表示不启用维护线程 _pool.MaintenanceSleep = 60; //socket单次任务的最大时间,超过这个时间socket会被强行中断掉(当前任务失败) _pool.MaxBusy = 1000 * 10; _pool.Initialize(); }
static MemCaheHelper() { string[] serverlist = JsonUtil.ToObj <string[]>(Global.Memcached.serverlist);//{ "127.0.0.1:11711" }; string poolName = Global.Memcached.poolName; int[] weights = JsonUtil.ToObj <int[]>(Global.Memcached.weights); //通过客户端来进行memcached的集群配置,在插入数据的时候,使用一致性哈希算法,将对应的value值存入Memcached // 初始化Memcached的服务池 SockIOPool pool = SockIOPool.GetInstance(poolName); //设置服务器列表 pool.SetServers(serverlist); //各服务器之间负载均衡的设置比例 pool.SetWeights(weights); pool.Initialize(); //创建一个Memcached的客户端对象 mc = new MemcachedClient(); mc.PoolName = poolName; //是否启用压缩数据:如果启用了压缩,数据压缩长于门槛的数据将被储存在压缩的形式 mc.EnableCompression = false; }
/// <inheritdoc /> public void Start(IDictionary <string, string> properties) { // Needs to lock staticly because the pool and the internal maintenance thread // are both static, and I want them syncs between starts and stops. lock (syncObject) { SockIOPool pool = SockIOPool.GetInstance(MemCacheClient.PoolName); if (pool.Initialized) { return; } bool debugEnabled = log.IsDebugEnabled; if (servers != null && servers.Length > 0) { pool.SetServers(servers); } if (weights != null && weights.Length > 0 && servers != null && weights.Length == servers.Length) { pool.SetWeights(weights); } if (properties.ContainsKey("failover")) { pool.Failover = Convert.ToBoolean(properties["failover"]); if (debugEnabled) { log.DebugFormat("failover set to {0}", pool.Failover); } } if (properties.ContainsKey("initial_connections")) { pool.InitConnections = Convert.ToInt32(properties["initial_connections"]); if (debugEnabled) { log.DebugFormat("initial_connections set to {0}", pool.InitConnections); } } if (properties.ContainsKey("maintenance_sleep")) { pool.MaintenanceSleep = Convert.ToInt64(properties["maintenance_sleep"]); if (debugEnabled) { log.DebugFormat("maintenance_sleep set to {0}", pool.MaintenanceSleep); } } if (properties.ContainsKey("max_busy")) { pool.MaxBusy = Convert.ToInt64(properties["max_busy"]); if (debugEnabled) { log.DebugFormat("max_busy set to {0}", pool.MaxBusy); } } if (properties.ContainsKey("max_connections")) { pool.MaxConnections = Convert.ToInt32(properties["max_connections"]); if (debugEnabled) { log.DebugFormat("max_connections set to {0}", pool.MaxConnections); } } if (properties.ContainsKey("max_idle")) { pool.MaxIdle = Convert.ToInt64(properties["max_idle"]); if (debugEnabled) { log.DebugFormat("max_idle set to {0}", pool.MaxIdle); } } if (properties.ContainsKey("min_connections")) { pool.MinConnections = Convert.ToInt32(properties["min_connections"]); if (debugEnabled) { log.DebugFormat("min_connections set to {0}", pool.MinConnections); } } if (properties.ContainsKey("nagle")) { pool.Nagle = Convert.ToBoolean(properties["nagle"]); if (debugEnabled) { log.DebugFormat("nagle set to {0}", pool.Nagle); } } if (properties.ContainsKey("socket_timeout")) { pool.SocketTimeout = Convert.ToInt32(properties["socket_timeout"]); if (debugEnabled) { log.DebugFormat("socket_timeout set to {0}", pool.SocketTimeout); } } if (properties.ContainsKey("socket_connect_timeout")) { pool.SocketConnectTimeout = Convert.ToInt32(properties["socket_connect_timeout"]); if (debugEnabled) { log.DebugFormat("socket_connect_timeout set to {0}", pool.SocketConnectTimeout); } } pool.Initialize(); } }