Memcached介绍
基于对ERP项目的思考,我看看了关于缓存方面的东西。在所有的缓存方案中,Memcached是最让我有兴趣的。看看Memcached项目
的有关背景:
memcached is a high-performance, distributed memory object caching system, generic in nature, but intended
for use in speeding up dynamic web applications by alleviating database load.
Danga Interactive developed memcached to enhance the speed of LiveJournal.com,
a site which was already doing 20 million+ dynamic page views per day for 1 million users with a
bunch of webservers and a bunch of database servers. memcached dropped the database load to almost nothing,
yielding faster page load times for users, better resource utilization, and faster access to the databases
on a memcache miss.

不翻译了,只强调几个keywords:
high-performance,distributed memory
LiveJournal.com----------因为这个百万级的网站的需求而产生的。

1.high-performance
在官方wiki上有这么一句:
Very fast. It uses libevent to scale to any number of open connections (using epoll on Linux,
if available at runtime), uses non-blocking network I/O, refcounts internal objects (so objects
can be in multiple states to multiple clients), and uses its own slab allocator and hash table so
virtual memory never gets externally fragmented and allocations are guaranteed O(1).
使用libevent,它可以应对任意多个连接,使用非阻塞的网络IO.
由于它的工作机制是在内存中开辟一块空间,然后建立一个HashTable,Memcached自管理这些HashTable。
由于是对HashTable的遍历,所以其查询复杂度是O(1)。
至于其中提到的libevent,呵呵,还没有看:)

2.distributed memory:分布式的内存管理,这正式它的优势所在。Memcached Client API 屏蔽了对象在不同内存区域的差别,
以一致的接口方法,所以用起来你完全感觉不到在使用不同的内存对象,当然缓存的时候也感觉不到。
这也是系统水平扩展的一个要点。理论上内存可以无限扩展,只要平行增加server节点就可以。

3.和数据库缓存的比较:
  不考虑使用什么样的数据库(MS-SQL, Oracle, Postgres, MysQL-InnoDB, etc..),
  实现事务(ACID,Atomicity, Consistency, Isolation, and Durability )需要大量开销,
  特别当使用到硬盘的时候,意味着查询可能会阻塞。当使用不包含事务的数据库(例如Mysql-MyISAM),上面的开销不存在,但读线程又可能会被写线程阻塞。
  可以看出,用数据库做缓存,在很大程度上是不明智的。
4. 和共享内存的比较:
   最初的缓存做法是在线程内对对象进行缓存,但这样进程间就无法共享缓存,命中率非常低,导致缓存效率极低。
   后来出现了共享内存的缓存,多个进程或者线程共享同一块缓存,但毕竟还是只能局限在一台机器上,多台机器做相
   同的缓存同样是一种资源的浪费,而且命中率也比较低。   Memcached Server和Clients共同工作,实现跨服务器
   分布式的全局的缓存。并且可以与Web Server共同工作,Web Server对CPU要求高,对内存要求低,
   Memcached Server对CPU要求低,对内存要求高,所以可以搭配使用。

5. 缓存对象同步管理:
   Memcached是遵循LRU(Least Recently Used:最近最少被使用)原则。当然你也可以设置缓存对象的生命周期。

6.Memcached的使用(Win32,.Net)
  具体下载安装过程:http://jehiah.cz/projects/memcached-win32/
  在win32下,memcached就是一个windows service。你可以在windows服务中找到:memcached Server 。这个就是了。
  发现这玩意比较消耗内存。
   
  .Net中使用:
  引用Memcached.ClientLibrary.dll,主要使用其中的几个类:

Memcached.ClientLibrary.SockIOPool pool = Memcached.ClientLibrary.SockIOPool.GetInstance(); ---服务器管理对象
   MemcachedClient mc = new MemcachedClient(); ---客户端

比较感兴趣这个GetInstance方法,具体看看:

 1            // empty constructor
 2         protected SockIOPool() { }
 3 
 4         /// <summary>
 5         /// Factory to create/retrieve new pools given a unique poolName.
 6         /// </summary>
 7         /// <param name="poolName">unique name of the pool</param>
 8         /// <returns>instance of SockIOPool</returns>
 9         [MethodImpl(MethodImplOptions.Synchronized)]
10         public static SockIOPool GetInstance(String poolName)
11         {
12             if(Pools.ContainsKey(poolName))
13                 return (SockIOPool)Pools[poolName];
14 
15             SockIOPool pool = new SockIOPool();
16             Pools[poolName] = pool;
17 
18             return pool;
19         }
20 
21         /// <summary>
22         /// Single argument version of factory used for back compat.
23         /// Simply creates a pool named "default". 
24         /// </summary>
25         /// <returns>instance of SockIOPool</returns>
26         [MethodImpl(MethodImplOptions.Synchronized)]
27         public static SockIOPool GetInstance()
28         {
29             return GetInstance(GetLocalizedString("default instance"));
30         }

string[] serverlist = { "192.168.100.142:11211" };
        pool.SetServers(serverlist);
        pool.InitConnections = 3;
        pool.MinConnections = 3;
        pool.MaxConnections = 5;
上面的代码,可以看到server的配置还是很强的。至于利用client api开发则是相当简单。自带的MemCachedBench_2.0项目就是相当好的一个demo。

有空翻译下:http://www.linuxjournal.com/article/7451

转载于:https://www.cnblogs.com/flyingchen/archive/2007/07/24/829745.html

优秀的缓存工具Memcached相关推荐

  1. redis linux工具安装,linux 安装redis缓存工具

    redis是分布式集群中最优秀的缓存工具,是nosql(非关系型数据库),运用了系统的多路复用技术,是运行最快的单线程缓存技术,所谓多路复用,就是请求统一到达,然后再处理,mybatis是分布在tom ...

  2. .NET下实现分布式缓存系统Memcached

    [IT168 技术文档]在Web应用程序中,数据通常保存在RDBMS中,应用服务器从数据库中读取数据并在浏览器中显示.但随着数据量的增大.访问的集中,就会出现RDBMS的负载加重.数据库响应变慢.网站 ...

  3. 分布式缓存之memcached以及LAMP的搭建

    1.memcached简介 Memcached 是一个自由开源的,高性能,分布式内存对象缓存系统. Memcached 是以 LiveJournal 旗下 Danga Interactive 公司的 ...

  4. Linux分布式缓存系统——memcached+LAMP环境搭建+监控

    概述 memcached简介 Memcached是一个开源.高性能.分布式内存对象缓存系统. Memcached是一种基于内存的key-value存储,用来存储小块的任意数据(字符串.对象),这些数据 ...

  5. 无盘服务器镜像包缓存设多少,【转】谈谈深度无盘缓存工具设置技巧

    提到无盘的缓存设置,我相信论坛上的网管朋友绝对不会陌生,毕竟我们每天在这里聊的人,基本上平常都做过无盘都差不多用过supercache,而我们平常提到的如何提高带机量这些相关话题,什么一台服务器带15 ...

  6. 分布式缓存技术memcached学习(一)——linux环境下编译memcahed

    安装依赖工具 [root@localhost upload]# yum install gcc make cmake autoconf libtool 下载并上传文件 memcached 依赖于 li ...

  7. 分布式缓存系统Memcached简介与实践(.NET memcached client library)

    原文:分布式缓存系统Memcached简介与实践(.NET memcached client library) 缘起: 在数据驱动的web开发中,经常要重复从数据库中取出相同的数据,这种重复极大的增加 ...

  8. 缓存工具类MyCacheUtil

    MyCacheUtil.java package com.sunrise.jop.common.util;import java.io.File; import java.sql.Timestamp; ...

  9. 三分钟学会缓存工具DiskLruCache

    DiskLruCache是一个十分好用的android缓存工具,我们可以从GitHub上下载其源码:https://github.com/JakeWharton/DiskLruCache DiskLr ...

最新文章

  1. CentOS安全配置(转)
  2. 一个用python做的完整项目_我从一个小项目学习Python编程的全过程(二)
  3. 【IT笔试面试题整理】位操作
  4. JAX-RS和JSON-P集成
  5. manjaro linux 教程,Manjaro 使用基础
  6. 正在中止线程 异常处理
  7. webpack3.0 压缩css 但是不在html中引用,webpack怎样压缩css?
  8. ArcMap自定义脚本工具制作
  9. python软件下载百度云-python电子书学习资料打包分享百度云资源下载
  10. spark rdd map java_Spark map 遍历rdd中的每个元素
  11. oracle11g和10的区别,同平台升级 oracle 10 到 oracle11g的一些考虑和实际操作
  12. 超好用的卸载工具——geek
  13. excel常用函数公式及技巧搜集4
  14. java经典算法(三)---zws
  15. 微信小程序开发者工具打不开的问题
  16. 嵌入式行业技术思维导图
  17. python爬取路况信息查询_如何一键获取高德交通态势数据
  18. 微信小程序01:关于错误Page pages/goods_list/index has not been registered yet.的原因
  19. windows可以ping通linux虚拟机的ip,但是ping不通主机名称解决方案
  20. 用easynetty进行服务端回签同步确认

热门文章

  1. SCVMM2008R2学习(八),硬件配置文件
  2. linux 常用的系统信息查看命令
  3. 《微软-统一沟通-UC 2013》-1-部署-基础架构-2-Add a domain controller
  4. 变量相关命令(env,export,set,read, array, declare)
  5. 转学美本半年,我眼里的中美高等教育
  6. 提高开发效率之VS Code基础配置篇
  7. 使用svn控制系统的优缺点和注意事项
  8. C# 7.2和8.0路线图
  9. 基于HT for Web 快速搭建3D机房设备面板
  10. 本日吐槽!“人傻钱多”的P2P公司是否是程序员的合适选择(群聊天记录的娱乐)...