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
----------------------------------------------------------------------------------------
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/.
e.g.:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/**
* MemcachedBench.cs
*
* Copyright (c) 2005
* Tim Gebhardt <tim@gebhardtcomputing.com>
*
* Based off of code written by
* Greg Whalin <greg@meetup.com>
* for his Java Memcached client:
*
*
* See the memcached website:
*
* This module is Copyright (c) 2005 Tim Gebhardt.
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later
* version.
*
* This library is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @author Tim Gebhardt<tim@gebhardtcomputing.com>
* @version 1.0
*/
namespace Memcached.MemcachedBench
{
using System;
using System.Collections;
using Memcached.ClientLibrary;
public class MemcachedBench
{
/// <summary>
/// Arguments:
/// arg[0] = the number of runs to do
/// arg[1] = the run at which to start benchmarking
/// </summary>
/// <param name="args"></param>
[STAThread]
public static void Main(String[] args)
{
int runs = 100;
int start = 200;
if (args.Length > 1)
{
runs = int .Parse(args[0]);
start = int .Parse(args[1]);
}
//可以设置多个服务器列表
//string[] serverlist = { "127.0.0.1:11211" , "140.192.34.73:11211" };
string [] serverlist = { "127.0.0.1:11211" }; //, "140.192.34.73:11211" };
// initialize the pool for memcache servers
SockIOPool pool = SockIOPool.GetInstance();
pool.SetServers(serverlist);
pool.InitConnections = 3;
pool.MinConnections = 3;
pool.MaxConnections = 5;
pool.SocketConnectTimeout = 1000;
pool.SocketTimeout = 3000;
pool.MaintenanceSleep = 30;
pool.Failover = true ;
pool.Nagle = false ;
pool.Initialize();
// initialize the pool for memcache servers
// SockIOPool pool = SockIOPool.Instance; // pool.Servers = serverlist; // // pool.InitConn = 5; // pool.MinConn = 5; // pool.MaxConn = 50; // pool.MaintSleep = 30; // pool.SocketTO = 1000; // // pool.Nagle = false; // pool.Initialize(); // // // get client instance
MemcachedClient mc = new MemcachedClient();
mc.EnableCompression = false ;
// MemcachedClient mc = new MemcachedClient(); // mc.CompressEnable = false; // mc.CompressThreshold = 0; // mc.Serialize = true;
string keyBase = "testKey" ;
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" ;
long begin = DateTime.Now.Ticks;
for ( int i = start; i < start+runs; i++)
{
mc.Set(keyBase + i, obj);
}
long end = DateTime.Now.Ticks;
long time = end - begin;
Console.WriteLine(runs + " 设置花费的时间-sets: " + new TimeSpan(time).ToString() + "ms" );
begin = DateTime.Now.Ticks;
int hits = 0;
int misses = 0;
for ( int i = start; i < start+runs; i++)
{
string str = ( string ) mc.Get(keyBase + i);
Console.WriteLine( "key={0},value={1}" ,keyBase+i,str);
if (str != null )
++hits;
else
++misses;
}
end = DateTime.Now.Ticks;
time = end - begin;
Console.WriteLine(runs + "读取花费的时间- gets: " + new TimeSpan(time).ToString() + "ms" );
Console.WriteLine( "Cache hits,成功: " + hits.ToString());
Console.WriteLine( "Cache misses,失败: " + misses.ToString());
IDictionary stats = mc.Stats();
foreach ( string key1 in stats.Keys)
{
Console.WriteLine(key1);
Hashtable values = (Hashtable)stats[key1];
foreach ( string key2 in values.Keys)
{
Console.WriteLine(key2 + ":" + values[key2]);
}
Console.WriteLine();
}
SockIOPool.GetInstance().Shutdown();
Console.ReadKey();
}
}
} |
服务器端: 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
相关推荐
在终端(也即cmd命令界面)下输入 ‘c:\memcached\memcached.exe -d install’ 安装 3. 再输入: ‘c:\memcached\memcached.exe -d start’ 启动。NOTE: 以后memcached将作为windows的一个服务每次开机时自动启动...
一个完整的memcached使用实例,memcached安装在windows上,使用java代码测试memcached是否安装部署成功,包括编译好的exe 及 jar文件,使用请看readme.txt文件
提供最新版本的Windows 32位、64位Memcache安装服务程序。经测试可支持Windows2003/Windows7/Windows8/Windows2008 系统。
在终端(也即cmd命令界面)下输入 ‘c:\memcached\memcached.exe -d install’ 安装 3. 再输入: ‘c:\memcached\memcached.exe -d start’ 启动。NOTE: 以后memcached将作为windows的一个服务每次开机时自动启动。...
包含Windows下memcached安装包,PHP5.2、5.3、5.4、5.5、5.6的php memcache dll扩展包,以及详细的memcached安装步骤,php-memcache搭建步骤,测试是否搭建成功步骤 附图文说明
最近一直在做一个项目的前期设计工作,考虑到... 以上是我在windows下对memcached的一点小学习和实践,在以后的项目开发过程中将会更深入的学习和应用这一缓存工具,也希望和有兴趣的同行一起讨论学习该工具的使用~~
----------memcached服务器的安装与部署---------- 安装服务 D:\memcached-1.4.15>memcachedw32.exe -d install 启动服务 D:\memcached-1.4.15>memcachedw32.exe -l 127.0.0.1 -m 32 -d start 注释:安装后...
本资源中包括了两个测试的demo,http://blog.csdn.net/supingemail/article/details/48010141 中涉及到的session共享的tomcat配置,以及windows memcached 的安装文件,以供学习者了解和学习。
这里包含了所有的东西.有实例,window环境下安装包,安装文档,使用文档,LINUX下说明文档等等,基本上所有的东西都全...如果是在WINDOWS下测试,安装一下安装包然后执行实例就可以了,命令窗口不要关闭不然取不到值.
里面有tomcat7配置文件和memcached session共享所需jar包.httpd配置文件。和一些文档,我已经测试过了,能够使用,适用系统为windows
下面测试下分布式缓存Memcached软件,一直在学习关注大访问量网站的缓存是如何实现,之前看过Memcached的资料,忙于没有时间来真正测试一下,本文测试分布式缓存Memcached的环境如下:(两台电脑作为服务器)CPU:...
memcached windows版本 32,64下测试过都可以 只有2个文件memcached.exe 解压到任意文件下运行memcached.exe即可 修改端口和内存大小修改:MemcahcedConfig.ini [MEMCACHED] MaxMem=128 Port=12000
windows下64位 亲测可用,32位未测试 安装教程网上百度
由于windows现在没有php memcached扩展,搭建开发环境比较困难,所以这个类会很有帮助。 灵感来源: ://github.com/joonas-fi/xslib-memcached 用法: 就像 php_memcached 扩展,新的 Memcached 对象等。 $m = ...
本地测试环境安装memcached服务端后,安装memcache扩展不成功? memcache扩展:相当于memcached客户端 注意:非memcached扩展 php-7.2.x_memcache.dll,为windows下编译文件,专门本地测试环境phpStudy2018(7.2.10-...
采用nginx+memcached+tomcat集群方案时所需的资源包,其中序列化采用的是msm-javolution-serializer-1.8.2 ,里面还有memcached服务端安装包。...此测试包都是基于windows平台的,故下载时请注意。
本人已经亲自测试使用,php_memcache.dll 在网上下载相应的PHP版本号即可
1.4.1 下载与安装Nginx 1.4.2 Nginx配置文件的结构 1.4.3 配置与调试Nginx 1.4.4 Nginx的启动、关闭和平滑重启 1.5 Nginx常用配置实例 1.5.1 虚拟主机配置实例 1.5.2 负载均衡配置实例 1.5.3 防盗链...