Memcached windows 下安装与测试

简介:

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

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

Memcached官方:http://danga.com/memcached/

关于Memcached的介绍请参考:Memcached深度分析

下载Windows的Server端

下载地址:http://code.jellycan.com/memcached/

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

1. 下载memcached的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中都有详细的说明和注释)

https://sourceforge.net/projects/memcacheddotnet/
http://www.codeplex.com/EnyimMemcached/ - Client developed in .NET 2.0 keeping performance and extensibility in

mind. (Supports consistent hashing.) 
http://code.google.com/p/beitmemcached/ - Client developed by BeIT with many new features

转载出处: http://www.yaosansi.com/

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

Client调用:

下载示例代码网址: http://sourceforge.net/projects/memcacheddotnet/

C#/.NET memcached client library. This library can be used by .NET projects to access memcached servers. Ported from the Java memcached library located athttp://www.whalin.com/memcached/.

 

 
  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.  } 

服务器端: http://files.cnblogs.com/wucg/memcached-1.2.6-win32-bin.zip

下载Client库文件及示例,vs2008,.netframework 1.0,2.0 http://files.cnblogs.com/wucg/clientlib.zip
















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


相关文章
|
3月前
|
C++
jrtplib开源库系列之一:jrtplib介绍、安装和测试(window 10环境介绍)
关于jrtplib库网上已经有很多介绍,而且目前jrtplib作者已经停止更新(Apr 18, 2020),最新版本为v3.11.2。本系列内容也以该版本进行介绍。 相信你已经对RTP/RTCP协议有一定的了解,并想更深入的了解RTP协议的具体实现,jrtplib就是使用使用C++实现的RTP/RTCP协议。具体标准为RFC3550,如果想仔细阅读原文,但是对英文又有点吃力,可以参考我的博客RTP/RTCP中英文对照,在博客的后面有百度链接,是对RFC3550的中文翻译,可能很多地方不太准确,有些内容是自己添加进去的,希望不会影响你的阅读。
34 0
|
1月前
|
消息中间件 Kafka Linux
Kafka【付诸实践 03】Offset Explorer Kafka 的终极 UI 工具安装+简单上手+关键特性测试(一篇学会使用 Offset Explorer)
【2月更文挑战第21天】Kafka【付诸实践 03】Offset Explorer Kafka 的终极 UI 工具安装+简单上手+关键特性测试(一篇学会使用 Offset Explorer)
154 2
|
1月前
|
Linux iOS开发 MacOS
|
3月前
|
测试技术 API 芯片
阿萨聊测试:如何在Mac 电脑上安装Postman?
阿萨聊测试:如何在Mac 电脑上安装Postman?
阿萨聊测试:如何在Mac 电脑上安装Postman?
|
3月前
|
网络协议 网络安全 Go
Kali下安装渗透测试常用工具dnsx和dirsearch
Kali下安装渗透测试常用工具dnsx和dirsearch
60 0
|
3月前
|
存储 Kubernetes 安全
虚拟机测试Windows Server 2016原地升级2019,应用和数据完美保留
Windows Server 2016可以无缝升级到2019版本,确保应用程序和数据在原地升级过程中完整保留。
102 0
|
3月前
|
Kubernetes NoSQL Linux
linux安装Lua及代码测试
linux安装Lua及代码测试
|
4月前
|
Linux Memcache
Linux - 安装memcached
Linux - 安装memcached
48 0
Linux - 安装memcached
|
5月前
|
Docker 容器
Docker下安装memcached
Docker下安装memcached
49 0
|
8月前
|
Shell C语言
脚本用源码来安装 memcached 服务器
脚本用源码来安装 memcached 服务器
34 1