博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Memcached windows 下安装与测试
阅读量:7136 次
发布时间:2019-06-28

本文共 5596 字,大约阅读时间需要 18 分钟。

 http://www.cnblogs.com/wucg/archive/2011/03/01/1968185.html

Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态、数据库驱动网站的速度。Memcached基于一个存储键/值对的hashmap。其守护进程(daemon )是用C写的,但是客户端可以用任何语言来编写,并通过memcached协议与守护进程通信。但是它并不提供冗余(例如,复制其hashmap条目);当某个服务器S停止运行或崩溃了,所有存放在S上的键/值对都将丢失。

Memcached官方:

关于Memcached的介绍请参考:

下载Windows的Server端

下载地址:

安装Memcache Server(也可以不安装直接启动)

1. 下载的windows稳定版,解压放某个盘下面,比如在c:\memcached

2. 在CMD下输入 "c:\memcached\memcached.exe -d install" 安装.
3. 再输入:"c:\memcached\memcached.exe -d start" 启动。NOTE: 以后memcached将作为windows的一个服务每次开机时自动启动。这样服务器端已经安装完毕了。

如果下载的是二进制的版本,直接运行就可以了,可以加上参数来加以设置。

常用设置:
-p <num>          监听的端口
-l <ip_addr>      连接的IP地址, 默认是本机
-d start          启动memcached服务
-d restart        重起memcached服务
-d stop|shutdown  关闭正在运行的memcached服务
-d install        安装memcached服务
-d uninstall      卸载memcached服务
-u <username>     以<username>的身份运行 (仅在以root运行的时候有效)
-m <num>          最大内存使用,单位MB。默认64MB
-M                内存耗尽时返回错误,而不是删除项
-c <num>          最大同时连接数,默认是1024
-f <factor>       块大小增长因子,默认是1.25
-n <bytes>        最小分配空间,key+value+flags默认是48
-h                显示帮助

然后就可以用.net 的memcached客户端来试一下了。

C# 下可用的API(每个客户端API中都有详细的说明和注释)

 - Client developed in .NET 2.0 keeping performance and extensibility in

mind. (Supports consistent hashing.) 

 - Client developed by BeIT with many new features

转载出处: 

----------------------------------------------------------------------------------------

Client调用:

下载示例代码网址: 

C#/.NET memcached client library. This library can be used by .NET projects to access memcached servers. Ported from the Java memcached library located at.

 

 
  1.   * MemcachedBench.cs  
  2.   *  
  3.   * Copyright (c) 2005  
  4.   * Tim Gebhardt <tim@gebhardtcomputing.com>  
  5.   *   
  6.   * Based off of code written by  
  7.   * Greg Whalin <greg@meetup.com>  
  8.   * for his Java Memcached client:  
  9.  * http://www.whalin.com/memcached/  
  10.   *   
  11.   *  
  12.   * See the memcached website:  
  13.   * http://www.danga.com/memcached/  
  14.   *  
  15.   * This module is Copyright (c) 2005 Tim Gebhardt.  
  16.   * All rights reserved.  
  17.   *  
  18.   * This library is free software; you can redistribute it and/or  
  19.   * modify it under the terms of the GNU Lesser General Public  
  20.   * License as published by the Free Software Foundation; either  
  21.   * version 2.1 of the License, or (at your option) any later  
  22.   * version.  
  23.   *  
  24.   * This library is distributed in the hope that it will be  
  25.   * useful, but WITHOUT ANY WARRANTY; without even the implied  
  26.   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR  
  27.   * PURPOSE.  See the GNU Lesser General Public License for more  
  28.   * details.  
  29.   *  
  30.   * You should have received a copy of the GNU Lesser General Public  
  31.   * License along with this library; if not, write to the Free Software  
  32.   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  
  33.   *  
  34.   * @author Tim Gebhardt<tim@gebhardtcomputing.com>   
  35.   * @version 1.0  
  36.   */ 
  37.  namespace Memcached.MemcachedBench  
  38.  {  
  39.   using System;  
  40.   using System.Collections;  
  41.  
  42.  
  43.   using Memcached.ClientLibrary;  
  44.  
  45.   public class MemcachedBench   
  46.  
  47.   {  
  48.  
  49. /// <summary>  
  50.  
  51. /// Arguments:   
  52.  
  53. ///  arg[0] = the number of runs to do  
  54.  
  55. ///  arg[1] = the run at which to start benchmarking  
  56.  
  57. /// </summary>  
  58.  
  59. /// <param name="args"></param>  
  60.  
  61. [STAThread]  
  62.  
  63. public static void Main(String[] args)   
  64. {  
  65.  int runs = 100;  
  66.  
  67.  int start = 200;  
  68.  if(args.Length > 1)  
  69.  {  
  70.   runs = int.Parse(args[0]);  
  71.   start = int.Parse(args[1]);  
  72.  }  
  73.  //可以设置多个服务器列表  
  74.  
  75.  //string[] serverlist = { "127.0.0.1:11211" , "140.192.34.73:11211" };  
  76.  
  77.  string[] serverlist = { "127.0.0.1:11211" }; //, "140.192.34.73:11211" };  
  78.  // initialize the pool for memcache servers  
  79.  
  80.  SockIOPool pool = SockIOPool.GetInstance();  
  81.  pool.SetServers(serverlist);  
  82. pool.InitConnections = 3;  
  83.  pool.MinConnections = 3;  
  84.  pool.MaxConnections = 5;  
  85.  pool.SocketConnectTimeout = 1000;  
  86.  pool.SocketTimeout = 3000;  
  87.  pool.MaintenanceSleep = 30;  
  88.  pool.Failover = true;  
  89.  pool.Nagle = false;  
  90.  pool.Initialize();  
  91.  // initialize the pool for memcache servers  
  92.  // SockIOPool pool = SockIOPool.Instance;  
  93.  // pool.Servers = serverlist;  
  94.  //  
  95.  // pool.InitConn = 5;  
  96.  // pool.MinConn = 5;  
  97.  // pool.MaxConn = 50;  
  98.  // pool.MaintSleep = 30;  
  99.  // pool.SocketTO = 1000;  
  100.  //  
  101.  // pool.Nagle = false;  
  102.  // pool.Initialize();  
  103.  //  
  104.  // // get client instance  
  105.  MemcachedClient mc = new MemcachedClient();  
  106.  mc.EnableCompression = false;  
  107.  // MemcachedClient mc = new MemcachedClient();  
  108.  // mc.CompressEnable = false;  
  109.  // mc.CompressThreshold = 0;  
  110.  // mc.Serialize = true;  
  111.  string keyBase = "testKey";  
  112.  string obj = "这是我的字符串This is a test of an object blah blah es, serialization does not seem to slow things down so much.  The gzip compression is horrible horrible performance, so we only use it for very large objects.  I have not done any heavy benchmarking recently";  
  113.  long begin = DateTime.Now.Ticks;  
  114.  for(int i = start; i < start+runs; i++)   
  115.  {  
  116.   mc.Set(keyBase + i, obj);  
  117.  }  
  118.  long end = DateTime.Now.Ticks;  
  119.  long time = end - begin;  
  120.  Console.WriteLine(runs + " 设置花费的时间-sets: " + new TimeSpan(time).ToString() + "ms");  
  121.  begin = DateTime.Now.Ticks;  
  122.  int hits = 0;  
  123.  int misses = 0;  
  124.  for(int i = start; i < start+runs; i++)   
  125.  {  
  126.   string str = (string) mc.Get(keyBase + i);  
  127.   Console.WriteLine("key={0},value={1}",keyBase+i,str);  
  128.   if(str != null)  
  129. ++hits;  
  130.   else 
  131. ++misses;  
  132.  }  
  133.  end = DateTime.Now.Ticks;  
  134.  time = end - begin;  
  135.  Console.WriteLine(runs + "读取花费的时间- gets: " + new TimeSpan(time).ToString() + "ms");  
  136.  Console.WriteLine("Cache hits,成功: " + hits.ToString());  
  137.  Console.WriteLine("Cache misses,失败: " + misses.ToString());  
  138.  IDictionary stats = mc.Stats();  
  139.  foreach(string key1 in stats.Keys)  
  140.  {  
  141.   Console.WriteLine(key1);  
  142.   Hashtable values = (Hashtable)stats[key1];  
  143.   foreach(string key2 in values.Keys)  
  144.   {  
  145. Console.WriteLine(key2 + ":" + values[key2]);  
  146.   }  
  147.   Console.WriteLine();  
  148.  }  
  149.  SockIOPool.GetInstance().Shutdown();  
  150.  Console.ReadKey();  
  151. }  
  152.   }  
  153.  } 

服务器端: 

下载Client库文件及示例,vs2008,.netframework 1.0,2.0 

本文转自cnn23711151CTO博客,原文链接:http://blog.51cto.com/cnn237111/589790 ,如需转载请自行联系原作者

你可能感兴趣的文章
Python爬虫实战之爬取链家广州房价_01简单的单页爬虫
查看>>
Chrome 性能监测
查看>>
LocalDateTime和Date互相转换
查看>>
基于Serverless架构最新应用场景详解
查看>>
[BTCC] 要“工程师”“工程师”“工程师”
查看>>
redis 目录
查看>>
lvs简介和命令
查看>>
在Centos7中使用firewall添加端口
查看>>
jquery验证表单的js代码(HTML+CSS+PHP代码部分省略)
查看>>
Linux学习之CentOS(二十)--CentOS6.4下修改MySQL编码方法
查看>>
Easy ×××
查看>>
公司腾讯企业邮箱服务器接口插件迁移的一个故障总结
查看>>
DNS域名服务基础
查看>>
微信头像透露你的性格,快看看你是哪一类
查看>>
软考信息系统监理师:2016年4月22日作业
查看>>
Linux-13软件安装
查看>>
C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 发送通知功能改进改进...
查看>>
写了C# ASP.NET WebService的XML解析网站接口程序收了200元辛苦费【加入软件项目源码交易群的好处】...
查看>>
为1900个JNI函数添加日志
查看>>
到2023年将会有超过90%的PC采用SSD硬盘
查看>>