¡¡¡¡Õâ´ÎÊÇFotologµÄ¾Ñ飬´«ËµÖбÈFlickr¸ü´óµÄÍøÕ¾£¬FotologÔÚ21̨·þÎñÆ÷Éϲ¿ÊðÁË51¸ömemcachedʵÀý£¬×ܼÆÓÐ254G»º´æ¿Õ¼ä¿ÉÓ㬻º´æÁ˶à´ï175GµÄÄÚÈÝ£¬Õâ¸öÊýÁ¿±ÈºÜ¶àÍøÕ¾µÄÊý¾Ý¿â¶¼Òª´óµÄ¶à£¬ÔÎÄÊÇA Bunch of Great Strategies for Using Memcached and MySQL Better Together£¬ÎÒÕâÀﻹÊÇÑ¡ÔñÐԵķÒëÒÔ¼°°´ÕÕÎÒµÄÀí½â²¹³ä£¬¸ÐлTodd Hoff£¬×ÜÄܸøÎÒÃÇһЩѧϰµÄ°¸Àý£¬´ÓÕâÀïÒ²ÄÜ¿´³ö¹úÍâ¼¼ÊõµÄ¿ª·Å̬¶È£¬²»ËÆÎÒÃÇ£¬Æäʵ¾ÍÄÇôµãС¾Å¾Å»¹²Ø×ÅÒ´×Å£¬ºÃÁË£¬½øÈëÕýÌâ¡£ Ò»¡¢¹ØÓÚmemcached ¡¡¡¡»¹²»ÖªµÀÕâ¸ö£¿ÄÇÄãÈ¥ÃæÊÔµÄʱºòÒª³Ô¿÷ÁË£¬¸Ï½ôÈ¥¹Ù·½ÍøÕ¾¿´Ò»ÏÂhttp://www.danga.com/memcached/£¬ÁíÍâgoogleÒ»ÏÂÓ÷¨£¬Ó²ÅÌ×ÜÊÇÌ«Âý£¬°ÑÊý¾Ý´æÔÚÄÚ´æÀïÃæ°É£¬Èç¹ûÄãÖ»ÓÐһ̨·þÎñÆ÷£¬ÍƼöÓÃÒ»ÏÂAPC(FacebookÔÚÓÃ)»òÕßeaccelerator»òÕßXcache(¹úÈË¿ª·¢µÄ)£¬ÕâЩ²úÆ·µ¥»úЧ¹û¸üºÃ£¬Èç¹ûÄãÐèÒª·Ö²¼Ê½µÄ»º´æ·½°¸£¬ÄÇôÓÃmemcached°É¡£ ¶þ¡¢memcachedÈçºÎÓëmysql²¢¼ç×÷Õ½£¿ ͨ¹ýÊý¾Ý¿â·ÖƬÀ´½â¾öÊý¾Ý¿âдÀ©Õ¹µÄÎÊÌâ°ÑÊý¾Ý¿â·ÖƬ£¬²¿Êðµ½²»Í¬µÄ·þÎñÆ÷ÉÏ£¬ÃâµÃÖ»ÓÐÒ»¸öÖ÷·þÎñÆ÷£¬Ð´²Ù×÷³ÉΪƿ¾±ÒÔ¼°¿ÉÄÜÓеġ°µ¥µã¹ÊÕÏ¡±£¬Ò»°ãµÄÊý¾Ý¿â·ÖƬÖ÷ÒªÊÇ°´ÕÕÒµÎñÀ´·Ö£¬¾¡¿ÉÄܵIJð·ÖÒµÎñ£¬²»Ïà¸ÉµÄ¶¼¶ÀÁ¢ÆðÀ´×ö³É·þÎñÒ²ºÃ Ç°¶ËmysqlºÍÒ»¶Ñmemcached·þÎñÆ÷À´Ó¦¸¶¶ÁµÄÎÊÌâÓ¦ÓóÌÐòÊ×ÏÈ´ÓmemcachedÖлñÈ¡Êý¾Ý£¬»ñÈ¡²»µ½ÔÙ´ÓÊý¾Ý¿âÖлñµÃ²¢±£´æÔÚmemcachedÖУ¬ÒÔÇ°¿´¹ýһƪÎÄÕÂ˵ºÃµÄÓ¦ÓÃ95£¥µÄÊý¾Ý´ÓmemcacheµÄÖлñµÃ£¬3£¥µÄÊý¾Ý´ÓmysqlµÄquery cacheÖлñµÃ£¬Ê£ÏÂ2£¥²ÅÈ¥²é±í£¬¶Ô±ÈÒ»ÏÂÄãµÄÓ¦Ó㬲î¾àÓжàÔ¶£¿ ͨ¹ýmysql¸´ÖÆ£¨master-slave£©À´½â¾ö¶ÁµÄÎÊÌâ Ê×ÏÈmysqlÊý¾Ý¿âͨ¹ýmaster-slave¶Áд·ÖÀ룬¶à¸öslaveÀ´Ó¦¶ÔÓ¦ÓóÌÐò¶ÁµÄ²Ù×÷¡£ Èý¡¢ÎªÊ²Ã´²»ÓÃmysqlµÄquery cache£¿ ¡¡¡¡ÎÒÃǶ¼ÖªµÀmysqlÓиöquery cache£¬¿ÉÒÔ»º´æÉϴβéѯµÄ½á¹û£¬¿Éʵ¼ÊÉÏ°ï²»ÉÏÌ«¶àµÄ棬ÏÂÃæÊÇmysql quety cacheµÄ²»×㣺 Ö»ÄÜÓÐÒ»¸öʵÀý Òâζ×ÅÄãÄÜ´æ´¢ÄÚÈݵÄÉÏÏÞ¾ÍÊÇÄã·þÎñÆ÷µÄ¿ÉÓÃÄڴ棬һ̨·þÎñÆ÷ÄÜÓжàÉÙÄڴ棿ÄãÓÖÄÜ´æ¶àÉÙÄØ£¿ Ö»ÒªÓÐд²Ù×÷£¬mysqlµÄquery cache¾ÍʧЧ Ö»ÒªÊý¾Ý¿âÄÚÈÝÉÔÓиı䣬ÄÇŸıäµÄÊÇÆäËûÐУ¬mysqlµÄquery cacheÒ²»áʧЧ mysqlµÄquery cacheÖ»ÄÜ»º´æÊý¾Ý¿âÊý¾ÝÐÐ Òâζ×ÅÆäËûÄÚÈݶ¼²»ÐУ¬±ÈÈçÊý×飬±ÈÈç¶ÔÏ󣬶ømemcachedÀíÂÛÉÏ¿ÉÒÔ»º´æÈκÎÄÚÈÝ£¬ÉõÖÁÎļþ^_^ ËÄ¡¢FotologµÄ»º´æ¼¼Êõ ·ÇÈ·¶¨ÐÔ»º´æÄ㲻ȷ¶¨ÄãÒªµÄÊý¾Ý»º´æÖÐÓÐûÓУ¬ÄãÒ²²»ÖªµÀÊDz»ÊǹýÆÚÁË£¬ÓÚÊÇÄã¾ÍÊÔ̽ÐÔµÄÎÊmemcached£¬ÎÒÒªµÄʲôʲôÊý¾ÝÄãÄÇÓÐÂð£¿Îҿɲ»Òª¹ýÆÚµÄÊý¾Ý°¡£¬memcached¸æËßÄã˵Óв¢ÇÒ¸øÄ㣬Äã¾Í¿ªÐÄÁË£¬Èç¹ûûÓÐÄØ£¬Äã¾ÍÒª´ÓÊý¾Ý¿â»òÕß±ðµÄµØ·½È¥»ñÈ¡ÁË£¬ÕâÊÇmemcachedµäÐ͵ÄÓ¦Óá£Ö÷ÒªÓ¦ÓÃÔÚ£º1.¸´ÔÓµÄÊý¾ÝÐèÒª¶à´Î¶ÁÈ¡£¬ÄãµÄÊý¾Ý¿â×öÁË·ÖƬ´¦Àí£¬´Ó¶à¸öÊý¾Ý¿âÖлñÈ¡Êý¾Ý²¢×éºÏÆðÀ´ÊÇÒ»¸ö·Ç³£´óµÄ¿ªÏú£¬Äã´ó¿ÉÒÔ°ÑÕâЩÊý¾ÝÈ¡³öÀ´Ö®ºó´æµ½memcachedÖÐ 2.mysql query cacheµÄÒ»¸öºÃµÄÌæ´ú·½°¸£¬ÕâÑùÊý¾Ý¿âÆäËû²¿ÃŸıäÁË£¬Ö»Òª×Ô¼ºÃ»¸Ä±ä¾ÍûÎÊÌ⣨עÒâÊý¾Ý¿â¸üеÄÎÊÌ⣬ºóÃæ»áÌáµ½£© 3.°Ñ¹Øϵ»òÕßÁÐ±í»º´æÆðÀ´£¬±ÈÈçij¸öÀ¸Ä¿ÏµĶàƪÎÄÕÂÁбí 4.±»¶à¸öÒ³Ãæµ÷Óò¢ÇÒ»ñÈ¡ÆðÀ´ºÜÂýµÄÊý¾Ý£¬»òÕßÊǸüкÜÂýµÄÊý¾Ý£¬±ÈÈçÎÄÕÂä¯ÀÀÅÅÐаñ 5.Èç¹ûcacheµÄ¿ªÏú³¬¹ýÖØлñÈ¡µÄ¿ªÏú£¬ÄÇô²»Òª»º´æËü°É 6.±êÇ©ÔƺÍ×Ô¶¯½¨Òé(ÀàËÆgoogle sugest) ÀýÈ磺µ±Ò»¸öÓû§ÉÏ´«Ò»¸öͼƬ£¬Õâ¸öÓû§µÄºÃÓÑÒ³ÃæÉ϶¼ÒªÁгöÕâÕÅͼƬÀ´£¬ÄÇô°ÑËü»º´æÆðÀ´°É¡£ DZÔÚÎÊÌ⣺ memcachedÏûºÄµÄÖ÷ÒªÊÇ·þÎñÆ÷Äڴ棬¶ÔCPUÏûºÄºÜС£¬ËùÒÔFotolog°Ñmemcached²¿ÊðÔÚËûÃǵÄÓ¦Ó÷þÎñÆ÷ÉÏ£¨Ã²ËÆÎÒÃÇÒ²ÊÇÕâÑù£©£¬ËûÃÇÓöµ½ÁËCPU¸ãµ½90£¥µÄʹÓÃÂÊ£¨Ôõô»áÄÇô¸ß£¿ÄijöÎÊÌâÁË°É£©¡¢ÄÚ´æ»ØÊÕ£¨ÕâÊǸö´óÎÊÌ⣩µÈµÈÎÊÌâ¡£ ״̬»º´æ°ÑÓ¦Ó÷þÎñµÄµ±Ç°×´Ì¬´æÔÚmemcachedÖÐÖ÷ÒªÓ¦ÓÃÔÚ£º1.¡°°º¹ó¡±µÄ²Ù×÷£¬¿ªÏú´óµÄ²Ù×÷ 2.sessions»á»°£¬Flickr°Ñsession´æÔÚÊý¾Ý¿âÖУ¬¸öÈ˸оõ»¹ÊÇ´æmemcached±È½Ï¡°±ãÒË¡±Ð©£¬Èç¹ûmemecached·þÎñÆ÷downµôÁË£¬ÄÇôÖØеǼ°É¡£ 3.¼Ç¼Óû§ÔÚÏßÐÅÏ¢(ÎÒÃÇÒ²ÊÇÕâÑù×öµÄ) È·¶¨ÐÔ»º´æ¶ÔÓÚijЩÌض¨Êý¾Ý¿âµÄÈ«²¿ÄÚÈÝ£¬¶¼»º´æµ½memcached£¬ÓÐÒ»¸öרÃŵÄÓ¦Ó÷þÎñÀ´±£ÕÏÄãÒªµÄÊý¾Ý¶¼ÔÚmemcachedÖУ¬ÆäËûÓ¦Ó÷þÎñÖ±½Ó´ÓmemcachedÖлñÈ¡Êý¾Ý¶ø²»È¥È¡Êý¾Ý¿â£¬ÒòΪÊý¾Ý¿âÒѾȫ²¿±£´æµ½memcachedÖв¢±£³Öͬ²½¡£Ö÷ÒªÓ¦ÓÃÔÚ£º1.¶ÁÈ¡ÉìÕ¹£¬ËùÓеĶÁÈ¡¶¼´ÓmemcachedÖлñµÃ£¬Êý¾Ý¿âûÓиºÔØ 2.¡±ÓÀ²»¹ýÆÚ¡°(Ïà¶ÔµÄ)µÄÊý¾Ý£¬±ÈÈçÐÐÕþ¹æ»®Êý¾Ý£¬±ä¶¯ºÜС°É 3.¾³£µ÷ÓõÄÄÚÈÝ 4.Óû§µÄÈÏÖ¤ÐÅÏ¢ 5.Óû§µÄ¸ÅÒªÐÅÏ¢ 6.Óû§µÄ²ÎÊýÉèÖà 7.Óû§µ±Ç°³£ÓõÄýÌåÎļþÁÐ±í£¬±ÈÈçÓû§µÄͼƬ 8.Óû§µÇ¼£¬²»×ßÊý¾Ý¿â£¬Ö»×ßmemcached£¨¸öÈ˾õµÃÕâ¸ö²»Ì«ºÃ£¬µÇ¼ÐÅÏ¢»¹ÊÇÐèÒª³Ö¾Ã»¯µÄ£¬ÓÃÀàËÆBDBÕâÑùЧ¹ûÒ²²»´í£© ʹÓ÷½Ê½£º 1.¶à¸öרÃŵĻº´æ³Ø¶ø²»ÊÇÒ»¸ö´óµÄ»º´æ·þÎñÆ÷£¬¶à¸ö»º´æ³Ø±£ÕÏÁ˸߿ÉÓÃÐÔ£¬Ò»¸ö»º´æʵÀý¹ÒµôÁË×ßÆäËûµÄ»º´æʵÀý£¬ËùÓеĻº´æʵÀý¹ÒµôÁË£¬×ßÊý¾Ý¿â£¨¹À¼ÆÊý¾Ý¿â¿¹²»×¡^_^£© 2.ËùÓеĻº´æ³Ø¶¼ÓóÌÐòÀ´Î¬»¤£¬±ÈÈçÊý¾Ý¿âÓиüÐÂʱ£¬³ÌÐò×Ô¶¯°Ñ¸üкóµÄÄÚÈÝͬ²½µ½¶à¸ö»º´æʵÀýÖÐ 3.·þÎñÆ÷ÖØÆôÖ®ºó£¬»º´æÒª±ÈÍøÕ¾ÏÈÆô¶¯£¬Õâ¾ÍÒâζ×ŵ±ÍøÕ¾ÒѾÆô¶¯ÁË£¬ËùÓеĻº´æ¶¼¿ÉÓà 4.¶ÁÈ¡µÄÇëÇó¿ÉÒÔ¸ºÔؾùºâµ½¶à¸ö»º´æʵÀýÖÐÈ¥£¬¸ßÐÔÄÜ£¬¸ß¿É¿¿ÐÔ Ç±ÔÚµÄÎÊÌ⣺ 1.ÄãÐèÒª×ã¹»¶àµÄÄÚ´æÀ´´æ´¢ÄÇô¶àµÄÊý¾Ý 2.Êý¾ÝÒÔÐмǼÊý¾Ý£¬¶ømemcachedÒÔ¶ÔÏóÀ´´æ´¢Êý¾Ý£¬ÄãµÄÂß¼Òª°ÑÐÐÁеÄÊý¾Ýת»»³É»º´æ¶ÔÏó 3.Ҫά»¤¶à¸ö»º´æʵÀý·Ç³£Âé·³,FotologÓÃJava/Hibernate£¬ËûÃÇ×Ô¼ºÐ´Á˸ö¿Í»§¶ËÀ´ÂÖѯ 4.¹ÜÀí¶à¸ö»º´æʵÀý»áÔö¼ÓÓ¦ÓóÌÐòµÄÐí¶à¿ªÏú£¬µ«ÕâЩ¿ªÏúÏà¶ÔÓÚ¶à¸ö»º´æµÃµ½µÄºÃ´¦À´ËµËã²»ÁËʲô Ö÷¶¯»º´æÊý¾Ýħ·¨°ãµÄ³öÏÖÔÚ»º´æÖУ¬µ±Êý¾Ý¿âÖÐÓиüеÄʱºò£¬»º´æÁ¢ÂíÌî³ä£¬¸üеÄÊý¾Ý±»µ÷ÓõĿÉÄÜÐÔ¸ü¸ß£¨±ÈÈçһƪÐÂÎÄÕ£¬¿´µÄµÄÈ˵±È»¶à£©£¬ÊÇ·ÇÈ·¶¨ÐÔ»º´æµÄÒ»ÖÖ±äÐÎ(ÔÎÄÊÇIt¡¯s non-deterministic caching with a twist.ÎÒ¾õµÃÕâÑù·Òë¹Ö¹ÖµÄ)¡£Ö÷ÒªÓ¦ÓÃÔÚ£º1.Ô¤Ìî³ä»º´æ£ºÈÃmemcached¾¡¿ÉÄܵÄÉÙµ÷ÓÃmysqlÈç¹ûÄÚÈݲ»Õ¹ÏֵĻ°¡£ 2.¡°Ô¤ÈÈ¡±»º´æ£ºµ±ÄãÐèÒª¿çÊý¾ÝÖÐÐĸ´ÖƵÄʱºò ʹÓò½Ö裺s 1.½âÎöÊý¾Ý¿â¸üеĶþ½øÖÆÈÕÖ¾£¬·¢ÏÖÊý¾Ý¿â¸üÐÂʱ¶ÔmemcachedÒ²½øÐÐͬÑùµÄ¸üР2.Ö´ÐÐÓû§×Ô¶¨Ò庯Êý£¬ÉèÖô¥·¢Æ÷µ÷ÓÃUDF¸üУ¬¾ßÌå²Î¿¼http://tangent.org/586/Memcached_Functions_for_MySQL.html 3.ʹÓÃBLACKHOLE²ßÂÔ£¬´«ËµÖÐFacebookÒ²ÓÃmysqlµÄBlackhole´æ´¢ÒýÇæÀ´Ìî³ä»º´æ£¬Ð´µ½BlackholeµÄÊý¾Ý¸´ÖƵ½»º´æÖУ¬FacebookÓÃÕâÀ´ÉèÖÃÊý¾Ý×÷·ÏÒÔ¼°¿ç¹ú½çµÄ¸´ÖÆ£¬ºÃ´¦ÊÇÊý¾Ý¿âµÄ¸´ÖƲ»×ßmysql£¬Õâ¾ÍÒâζ×ÅûÓжþ½øÖÆÈÕÖ¾ÒÔ¼°¶ÔCPUʹÓò»ÄÇô¶à£¨°¡£¿ÄѵÀͨ¹ýmemcached´æ´¢¶þ½øÖÆÈÕÖ¾£¬È»ºó¸´ÖƵ½²»Í¬µÄÊý¾Ý¿â£¿ÓоÑéµÄͬ־ÔÚÕâ¸ö»°ÌâÉÏ¿ÉÒÔ²¹³ä¡££© Îļþϵͳ»º´æ°ÑÎļþÖ±½Ó»º´æÔÚmemcachedÖУ¬ÍÛ£¬¹»BTµÄ£¬¼õÇáNFSµÄ¸ºµ££¬¹À¼ÆÖ»»º´æÄÇЩ¹ýÓÚÈÈÃŵÄͼƬ°É¡£ ²¿·ÖÒ³ÃæÄÚÈÝ»º´æÈç¹ûÒ³ÃæµÄijЩ²¿·Ö»ñÈ¡ÆðÀ´·Ç³£·Ñ¾¢£¬ÒÔÆ仺´æÒ³ÃæµÄÔʼÊý¾Ý»¹²»Èç°ÑÒ³ÃæµÄ²¿·ÖÄÚÈÝÖ±½Ó»º´æÆðÀ´Ö±½Óµ÷Óà ӦÓóÌÐò¼¶±ðµÄ¸´ÖÆͨ¹ýAPIÀ´¸üлº´æ£¬APIµÄÖ´ÐÐϸ½ÚÈçÏ£º1.Ò»¸öÓ¦ÓðÑÊý¾Ýдµ½Ä³¸ö»º´æʵÀý£¬Õâ¸ö»º´æʵÀý°ÑÄÚÈݸ´ÖƵ½ÆäËû»º´æʵÀý£¨memcachedͬ²½£©2.×Ô¶¯»ñµÃ»º´æ³ØµØÖ·ÒÔ¼°ÊµÀý¸öÊý 3.ͬʱ¶Ô¶à¸ö»º´æʵÀý¸üР4.Èç¹ûij¸ö»º´æʵÀýdownµôÁË£¬Ìøµ½ÏÂÒ»¸öʵÀý£¬Ö±µ½¸üгɹ¦ Õû¸ö¹ý³Ì·Ç³£¸ßЧÒÔ¼°µÍ¿ªÏú ÆäËû¼¼ÇÉ1.¶à½ÚµãÒÔÓ¦¶Ô¡±µ¥µã¹ÊÕÏ¡±2.ʹÓÃÈȱ¸¼¼Êõ£¬µ±Ä³¸ö½ÚµãdownµôÁË£¬ÁíÍâһ̨·þÎñ×Ô¶¯Ìæ»»³ÉËüµÄIP£¬ÕâÑù¿Í»§¶Ë²»ÓøüÐÂmemcachedµÄIPµØÖ·3.memcached¿ÉÒÔͨ¹ýTCP/UDP·ÃÎÊ£¬³ÖÐøÁ¬½Ó¿ÉÒÔ¼õÇḺÔØ£¬ÏµÍ³Éè¼Æ³É¿Éͬʱ³ÐÊÜ1000¸öÁ¬½Ó 4.²»Í¬µÄÓ¦Ó÷þÎñ£¬²»Í¬µÄ»º´æ·þÎñÆ÷Ⱥ 5.¼ì²éÒ»ÏÂÄãµÄÊý¾Ý´óСÊÇ·ñÆ¥ÅäÄã·ÖÅäµÄ»º´æ£¬¸ü¶àÇë²Î¿¼http://download.tangent.org/talks/Memcached%20Study.pdf 6.²»Òª¿¼ÂÇÊý¾ÝÐлº´æ£¬»º´æ¸´ÔӵĶÔÏó 7.²»ÒªÔÚÄãµÄÊý¾Ý¿â·þÎñÆ÷ÉÏÅÜmemcached£¬Á½¸ö¶¼ÊdzÔÄÚ´æµÄ¹ÖÊÞ 8.²»Òª±»TCPÑÓ³ÙÀ§ÈÅ£¬±¾µØµÄTCP/IP¶ÔÄڴ渴ÖÆÊÇ×öÁËÓÅ»¯µÄ 9.¾¡¿ÉÄܵIJ¢Ðд¦ÀíÊý¾Ý 10.²¢²»ÊÇËùÓеÄmemcachedµÄ¿Í»§¶Ë¶¼ÊÇÒ»ÑùµÄ£¬×ÐϸÑо¿ÄãÓõÄÓïÑÔËù¶ÔÓ¦µÄ£¨ºÃÏñphpºÍmemcachedÅäºÏµÄ²»´í£© 11.¾¡¿ÉÄܵÄÊÇÊý¾Ý¹ýÆÚ¶ø²»ÊÇʹÊý¾ÝÎÞЧ£¬memcached¿ÉÒÔÉ趨¹ýÆÚʱ¼ä 12.Ñ¡ÔñÒ»¸öºÃµÄ»º´æ±êʶkey£¬±ÈÈç¸üеÄʱºò¼ÓÉÏ°æ±¾ºÅ 13.°Ñ°æ±¾ºÅ´æ´¢ÔÚmemcachedÖÐ
|