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 ,如需转载请自行联系原作者


相关文章
|
8天前
|
运维 关系型数据库 MySQL
os-copilot安装_配置_功能测试全集
我是一位中级运维工程师,我平时工作会涉及到 各类服务器的 数据库 与 java环境配置 操作。 我顺利使用了OS Copilot的 -t -f | 功能,我的疑惑是不能在自动操作过程中直接给与脚本运行权限,必须需要自己运行一下 chmod 这个既然有了最高的权限,为什么就不能直接给与运行权限呢。 我认为 -t 功能有用,能解决后台运行基础命令操作。 我认为 -f 功能有用,可以通过task文件中撰写连续任务操作。 我认为 | 对文件理解上有很直接的解读,可以在理解新程序上有很大帮助。
157 84
|
4天前
|
弹性计算 Ubuntu Java
OS-Copilot-ubuntu镜像版本的具体测试使用(安装方式有单独注明)
作为一名个人开发者,我主要负责云资源的运维和管理。在使用OS Copilot的过程中,我遇到了一些配置问题,特别是在ECS实例中设置AccessKey时,但最终成功解决了。通过使用OS Copilot的-t/-f/管道功能,我大大提升了效率,减少了命令编写的工作量,特别是在搭建Java运行环境时效果显著。此外,| 功能帮助我快速理解文档,整体体验非常流畅,推荐给其他开发者使用。
23 6
|
8天前
|
弹性计算 运维 Ubuntu
os-copilot在Alibaba Cloud Linux镜像下的安装与功能测试
我顺利使用了OS Copilot的 -t -f 功能,我的疑惑是在换行的时候就直接进行提问了,每次只能写一个问题,没法连续换行更有逻辑的输入问题。 我认为 -t 管道 功能有用 ,能解决环境问题的连续性操作。 我认为 -f 管道 功能有用 ,可以单独创建可连续性提问的task问题。 我认为 | 对文件直接理解在新的服务器理解有很大的帮助。 此外,我还有建议 可以在非 co 的环境下也能进行连续性的提问。
49 7
|
1月前
|
安全 Ubuntu Linux
Metasploit Pro 4.22.6-2024111901 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.6-2024111901 (Linux, Windows) - 专业渗透测试框架
55 9
Metasploit Pro 4.22.6-2024111901 (Linux, Windows) - 专业渗透测试框架
|
2月前
|
人工智能 测试技术 Windows
Windows 竞技场:面向下一代AI Agent的测试集
【10月更文挑战第25天】随着人工智能的发展,大型语言模型(LLMs)在多模态任务中展现出巨大潜力。为解决传统基准测试的局限性,研究人员提出了Windows Agent Arena,一个在真实Windows操作系统中评估AI代理性能的通用环境。该环境包含150多个多样化任务,支持快速并行化评估。研究团队还推出了多模态代理Navi,在Windows领域测试中成功率达到19.5%。尽管存在局限性,Windows Agent Arena仍为AI代理的评估和研究提供了新机遇。
59 3
|
3月前
|
测试技术 PHP 开发工具
php性能监测模块XHProf安装与测试
【10月更文挑战第13天】php性能监测模块XHProf安装与测试
44 0
|
28天前
|
安全 关系型数据库 MySQL
Windows Server 安装 MySQL 8.0 详细指南
安装 MySQL 需要谨慎,特别注意安全配置和权限管理。根据实际业务需求调整配置,确保数据库的性能和安全。
162 9
|
2月前
|
网络安全 Windows
Windows server 2012R2系统安装远程桌面服务后无法多用户同时登录是什么原因?
【11月更文挑战第15天】本文介绍了在Windows Server 2012 R2中遇到的多用户无法同时登录远程桌面的问题及其解决方法,包括许可模式限制、组策略配置问题、远程桌面服务配置错误以及网络和防火墙问题四个方面的原因分析及对应的解决方案。
169 4
|
2月前
|
监控 安全 网络安全
使用EventLog Analyzer日志分析工具监测 Windows Server 安全威胁
Windows服务器面临多重威胁,包括勒索软件、DoS攻击、内部威胁、恶意软件感染、网络钓鱼、暴力破解、漏洞利用、Web应用攻击及配置错误等。这些威胁严重威胁服务器安全与业务连续性。EventLog Analyzer通过日志管理和威胁分析,有效检测并应对上述威胁,提升服务器安全性,确保服务稳定运行。
|
2月前
|
监控 安全 网络安全
Windows Server管理:配置与管理技巧
Windows Server管理:配置与管理技巧
125 3

热门文章

最新文章