设为首页 收藏本站
查看: 967|回复: 0

[经验分享] #Memcached系列#(1)初识Memcached

[复制链接]

尚未签到

发表于 2018-12-24 13:59:45 | 显示全部楼层 |阅读模式
  本文主要是介绍Memcached,它的本质是在内存中进行缓存。
  原文地址:MEMCACHED FOR C# - A WALKTHROUGH
  一、在谈Memcahced之前,先来谈谈Object caching in .NET 4的缺点
  Caching is the process of storing frequently used data on the server to fulfil subsequent requests. Object Caching in .NET 4 is a great tool to use for caching and literally takes minutes to get up and running.
  缓存的目的,是将一些数据存储于服务器的内存中,而不必每次都向数据库中查询数据,从而提高服务器的响应速度。Object Caching in .Net就是对缓存的实现,但是Object Caching也有缺点:当应用程序池进行回收的时候会丢失数据,同时也不支持“负载均衡”。
  However, one of the downsides of using the System.Runtime.Caching in .NET 4 is that every time your application pool recycles in IIS, you lose the objects in cache. The same happens if you make a change to your web.config or redeploy your application.
  This isn't a problem if you are running smaller applications and cached data isn't vital to their performance. However, for high-traffic applications that need to have the cache up all the time, this becomes a problem.
  Another thing to consider is the possibility of load-balanced servers - using the Object Caching in .NET 4 isn't distributed. That means it will only store its cache per application pool. If you have two servers it means that you will have two different cache stores.
  二、针对Object Caching的缺点,再来谈谈Memcached
  Memcached is a free & open source, high-performance, distributed memory object caching system intended for use in speeding up dynamic web applications by alleviating database load. You can think of it as a short-term memory for your applications. The brilliant thing aboutMemcached is that you run it on one server and point all the applications to the Memcached server. This way all servers use the same cache!
  Another bonus is that even if you redeploy your app, or recycle the app pool in any way - the cached objects are still there. This is great news for larger applications that need to be online constantly and can't afford any downtime with regards to it's cache.
  Memcached是一个开源的、免费的memory object caching system,它有两个特点:high-performance和distributed。它的high-performance特点,是通过将数据存储于内存当中,从而从而alleviating database load,由于“从内存读取数据” 比 “从数据库读取数据”要快,所以能够提高速度。
  三、Memcached的两部分:服务器端和客户端API
  The advantages of using Memcached are endless and getting it setup on your machine is really simple. There are two parts to getting Memcached setup - you need the Memcached server and then you need to get the client API. There are few client API available for most of the common languages out there (Ruby, C#, PHP, C, Java).
  要想安装Memcached,需要两部分:Memcached Server和Memcached Client(API)
  四、Memcached的原理(对于这一部分,不太了解,不过先粘贴过来)
  (1)Socket 服务器端 【这里有篇文章:简单理解Socket  http://www.cnblogs.com/dolphinX/p/3460545.html】
  (2)数据:键值对存储 【key item】
  (3)内存处理的算法:
  本质就是一个大的哈希表。key最大长度是255个字符。
  内存模型:Memcache预先将可支配的内存空间进行分区(Slab),每个分区里再分成多个块(Chunk)最大1MB,但同一个分区里:块的长度(bytes)是固定的。
  插入数据:查找适合自己长度的块,然后插入,会有内存浪费。
  LRU,闲置>过期  >最少访问   (LRU是Least Recently Used 近期最少使用算法)
  惰性删除:它并没有提供监控数据过期的机制,而是惰性的,当查询到某个key数据时,如果过期那么直接抛弃。
  (4)集群搭建原理:
  Memcache服务器端并没有提供集群功能,但是通过客户端的驱动程序实现了集群配置。
  客户端实现集群的原理:首先客户端配置多台集群机器的ip和端口的列表。然后客户端驱动程序在写入之前,首先对key做哈希处理得到哈希值后对总的机器的个数进行取余然后就选择余数对应的机器。
  这部分内容来自http://www.cnblogs.com/peter-peng/p/3187826.html
  对于“集群搭建原理”参考下面的说法
How does it work
  Memcached is a distributed memory object cache, so how does it actually distribute?
  Effectively the Memcached server is simply a key value store so it is up to the client to pick the correct server to put the object on. The way it picks is to hash the key for the item you want to store and compute from that which server that item should be placed on. If you had two servers the split of items between the two should be approximately 50-50.
  一些参考链接:
  Memcached Clients- Which ones best https://sysdot.wordpress.com/2011/03/08/memcached-clients-which-ones-best/
  下一篇文章,就要讲如何安装Memcached Server如何安装


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-655362-1-1.html 上篇帖子: Memcached 主主复制+ Keepalived 实现 Memcached 高可用架构集群 下篇帖子: Memcached 小结
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表