- 浏览: 857070 次
- 性别:
- 来自: 北京
-
文章分类
最新评论
-
zjhzwx1212:
为什么用threadLocal后,输出值是从20开始的,而定义 ...
j2ee的线程安全--threadlocal -
aeoluspu:
不错 mysql 测试部分感觉不详细
用sysbench(或者super-smack)测试mysql性能 -
nanPrivate:
有没有例子,只理论,实践起来还是不会啊
JMS可靠消息传送 -
lwclover:
一个网络工程师 装什么b
postfix 如何删除队列中的邮件 -
maimode:
我也欠缺不少啊
理想的计算机科学知识体系
A Bunch of Great Strategies for Using Memcached an
- 博客分类:
- mysql/postgresql
http://highscalability.com/bunch-great-strategies-using-memcached-and-mysql-better-together
The primero recommendation for speeding up a website is almost always to add cache and more cache. And after that add a little more cache just in case. Memcached is almost always given as the recommended cache to use. What we don't often hear is how to effectively use a cache in our own products. MySQL hosted two excellent webinars (referenced below) on the subject of how to deploy and use memcached. The star of the show, other than MySQL of course, is Farhan Mashraqi of Fotolog. You may recall we did an earlier article on Fotolog in Secrets to Fotolog's Scaling Success, which was one of my personal favorites.
Fotolog, as they themselves point out, is probably the largest site nobody has ever heard of, pulling in more page views than even Flickr. Fotolog has 51 instances of memcached on 21 servers with 175G in use and 254G available. As a large successful photo-blogging site they have very demanding performance and scaling requirements. To meet those requirements they've developed a sophisticated approach to using memcached that others can learn from and emulate. We'll cover some of the highlightable strategies from the webinar down below the fold.
What is Memcached?
The first part of the first webinar gives a good overview of memcached. Just in case the rock you've been hiding under recently disintegrated, you may not have heard about memcached (as if). Memached 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. Memcached essentially creates an in-memory shard on top of a pool of servers from which an application can easily get and set up to 1MB of unstructured data. Memcached is two hash tables, one from the client to the server and another one inside the server. The magic is that none of the memcached servers need know about each other. To scale up you just add more servers and the key hashing algorithm makes it all work out right. Memcached is not redundant, has no failover, and has no authentication. It's simple server for storing and getting data, the complex bits must be implemented by applications.
The rest of the first webinar is Farhan explaining in wonderful detail how they use memcached at Fotolog. The beginning of the second seminar covers much of the same ground as the first. In the last half of the second seminar Farhan gives a number of excellent code examples showing how memcached is installed, used, and managed. If you've never used memcached before there's a lot of good stuff presented.
Memcached and MySQL Go Better Together
There's a little embrace and extend in the webinar as MySQL cluster is presented several times as doing much the same job as memcached, but more reliably. However, the recommended approach for using memcached and MySQL is:
Using this approach you get scalable reads and writes along with high availability.
Given that MySQL has a cache, why is memcached needed at all?
Cache everything that is slow to query, fetch, or calculate.
This is Fotolog's rule of deciding what to cache. What is considered slow depends on your requirements. But when something becomes slow it's a candidate for caching.
Fotolog's Caching Typology
Fotolog has come up with an interesting typology of their different caching strategies:
Non-Deterministic Cache
This is the typical way of using memcached. I think the non-determinism comes in because an application can't depend on data being in the cache. The data may have been evicted because a slab is full or because the data simply hasn't been added yet. Other Fotolog strategies are deterministic, which means the application can assume the data is always present.
Useful For
For example, when a photo is uploaded the photo is uploaded on the page of every friend. These lists are taxing to calculate so they are cached.
Usage Steps
Stats
* ~440 gets per second
* ~40 sets per second
* ~11 gets/set
Fotolog likes to characterize their caching policy in terms of the ratio of gets to sets.
Potential Problems
* 90% CPU usage
* Memory garbage collected nearly once a minute
* Experienced blocking on memcached on app servers
State Cache
Keeps the current state of an application in cache.
Useful For
Usage Steps
It's a form of non-deterministic caching so the same steps apply.
Stats
Deterministic Cache
Keep all data for particular database tables in the cache. An application always assumes that the data they need is in the cache (deterministic), applications never go to the database for data. Applications don't have to check memcached before accessing the data. The data will exist in the cache because the database is essentially loaded into the cache and is always kept in sync.
Useful For
Usage Steps
Stats
Potential Problems
Proactive Caching
Data magically shows up in the cache. As updates happen to the database the cache is populated based on the database change. Since the cache is updated as the database is updated the chances of data being in cache are high. It's non-deterministic caching with a twist.
Useful For
Usage Steps
There are typically three implementation approaches:
File System Caching
NFS has significant overhead when used with a large number of servers. Fotolog originally stored XML files on a SAN and exposed them using NFS. They saw contention on these files so they put files in memcached. Big
performance improvements were seen and it kept NFS mounts open for other requests. Smaller media can also be stored in the cache.
Partial Page Caching
Cache directly displayable page elements. The other caching strategies cache data used to create pages, but some things are still compute intensive and require a lot of work. So instead of just caching objects, prepare and cache entire page elements for reuse. For page elements that are accessed many times per second this can be a big win. For example: calculating top users in a region, popular photo list, and featured photo list. Especially when using sharding it can take some time to calculate these lists, so caching the resulting page elements makes a lot of sense.
Application Based Replication
Write data to the cache through your own API. The API hides implementation details like:
This approach is very fast if not network bound and very cost effective.
Miscellaneous
There were a few suggestions on using memcached that didn't fit in any other section, so they're gathered here for posterity:
Here are some additional strategies from Memcached and MySQL tutorial:
Final Thoughts
Fotolog has obviously put a great deal of thought and effort into creating sophisticated scaling strategies using memcached and MySQL. What I'm struck with is the enormous amount of effort that goes into syncing rows and objects back and forth between the cache and the database. Shouldn't it be easier? What role is the database playing when the application makes such constant use of the object cache? Wouldn't more memory make the disk based storage unnecessary?
发表评论
-
找出mysql中最大的表
2011-08-04 12:41 1702SELECT concat(round(table_rows/ ... -
find 10 largest table in mysql
2010-07-20 11:09 1117SELECT concat(round(table_rows/ ... -
MySQL Back to Basics: Analyze, Check, Optimize, and Repair
2010-07-14 11:35 1202http://www.pythian.com/news/111 ... -
找出mysql中无用的索引
2010-07-13 14:49 1906select t.TABLE_SCHEMA , ... -
xtrabackup timeout bug
2010-06-13 10:21 1103I modified /usr/bin/innobac ... -
Compiling sysbench 0.4.12 for Debian
2010-06-09 10:16 997http://www.randombugs.com/linux ... -
mysql 实用工具集
2010-06-04 00:08 1120这些工具都是从网上搜集来的,对mysql的管理,调优和恢复有很 ... -
gearman for mysql
2010-05-10 18:26 1017http://www.slideshare.net/datac ... -
几个应该被修改的mysql默认值
2010-05-06 15:24 1504wait_timeout = 20 (不适合持久连接) in ... -
How to Perform a Healthcheck on the Database
2010-02-26 10:05 1419http://bbs.chinaunix.net/thread ... -
PostgreSQL与Innodb并发控制大比拼
2010-01-14 11:38 2121http://wangyuanzju.blog.163.com ... -
关于mysql的很好网站
2009-10-21 10:40 959http://www.mysqlperformanceblog ... -
Should you move from MyISAM to Innodb ?
2009-10-17 02:37 1050There is significant portion of ... -
最好的mysql备份工具
2009-08-19 16:45 1230Xtrabackup https://launchpad.n ... -
mysql 增量备份脚本
2009-08-18 09:44 3671根据网上脚本修改而成 mysqlFullBackup.sh ... -
mysql-zrm备份mysql数据库
2009-07-22 13:58 2788MySQL-zrm是用perl脚本写的 ... -
Base: An Acid Alternative
2009-06-18 15:55 1428http://queue.acm.org/detail.cfm ... -
关于innodb插入性能
2009-04-07 10:54 1611根据某网友的测试,innodb在以下条件下插入性能是稳定的: ... -
MySQL主从服务器的一些技巧
2009-03-25 15:18 975http://www.sunnyu.com/?p=150 -
mytop1.6补丁
2009-03-13 17:27 1016mytop是一个实时监控mysql状态的工具,很好用,但是有一 ...
相关推荐
A_bunch_of_shiny_modules_that_let_shiny_sense_the__shinysense
【AI to A Bunch Of Dudes-crx插件】是一个专为英语用户设计的扩展程序,它的主要功能是将文本中的“ai”或“人工智能”这两个词汇替换为“一堆帅哥”。这个独特的插件旨在以幽默的方式对AI进行调侃,同时也能在日常...
They will find a bunch of different projects that are about using the Arduino for doing clever things. There are easy projects you can build in a couple of hours and harder ones that might need a ...
"Focus Group to A Bunch of Talking Ducks" 是一个Chrome浏览器扩展程序,主要功能是对网页上出现的“焦点组”这个词进行幽默化的替换,将其转化为“一堆谈话的鸭子”。这个插件以英文(美国)为操作语言,反映出其...
【标题】:“黄金按钮”新版本发布:引入图片属性与皮肤支持 【正文】: “黄金按钮”(Gold Button)的最新版本已经发布,这款工具为开发者提供了更丰富的功能和自定义选项。新版本的核心更新在于增加了“图片...
Collecting a Bunch of Named Items Recipe 4.19. Assigning and Testing with One Statement Recipe 4.20. Using printf in Python Recipe 4.21. Randomly Picking Items with Given Probabilities Recipe...
Cerenkov wake amplification can be used as an accelerating scheme, in which a trigger bunch of electrons propagating inside a cylindrical waveguide filled with an active medium generates an initial ...
But many organizations’ efforts to move to SOA have been mired–by organizational issues, by conflicting vendor messages, and by architectures that may amount to little more than Just a Bunch of Web...
isn't to add a bunch of elements you can forget about, it's to create a more stable tpt version without many bugs and lots of new features not fit for the officiel version; like multiple tabs, an ...
Each chapter consists of best practices, useful advice, and a bunch of easy-to-follow examples that will build up your skills as you advance. Table of Contents Part 1. Module 1 Chapter 1. Javascript...
JavaScript: Moving to ES2015 by Ved Antani ... Each chapter consists of best practices, useful advice, and a bunch of easy-to-follow examples that will build up your skills as you advance.
10. a bunch of: 用于描述一束或一捆,如 "She received a bunch of flowers on her birthday." 11. a certain: 修饰可数名词单数,表示"某一",如 "There is a certain risk involved in every investment." 12. ...
A_Bunch_of_Code A bunch of code that I wrote before. Comics 检查Naruto漫画是否有更新. Douban_fm 下载豆瓣 FM 的红心歌曲. Forwarder 简单的HTTP请求转发服务器, 配合 KindleEar 使用. Get_GPA 命令行获取成绩...
But many organizations’ efforts to move to SOA have been mired–by organizational issues, by conflicting vendor messages, and by architectures that may amount to little more than Just a Bunch of Web...
But many organizations’ efforts to move to SOA have been mired–by organizational issues, by conflicting vendor messages, and by architectures that may amount to little more than Just a Bunch of Web...
And a bunch more! Get your copy today! Scroll up and hit the buy button to download now! Table of Contents Chapter 1: The Importance of Data Analytics and Why Your Business Should Use it Chapter 2 ...
*Changed a bunch of sample apps to switch from using onPause() and onResume() to using onStop() and onStart(), to be friendlier to multiwindow environments *Various miscellaneous improvements and ...
A bunch of extra hints and tips scattered throughout the chapters. Free beer. Launch Content Code Smart will launch with existing Code Bright content revamped, new Laravel 5 chapters, and almost 400...
This started as a fun experiment and got a bunch of github stars after it got shared through various channels. It works and you're free to use it, but I have no plans for maintaining or improving it....
还有一些词组两者皆可,如"a bunch of grapes"(一串葡萄)和"a bunch of problems"(一堆问题)。 掌握量词的正确使用对提升英语表达的准确性和地道性至关重要。在学习过程中,需要通过大量的阅读和实践来熟悉各种...