ãããã
PHPã®Ketamuã§ãå°ãªããšãã¢ã¯ã»ã¹ã¯äœã ã£ãã®ã§ããããã
ç§ã¯PHPã«ã€ããŠè©±ããŠããŸããã ã¢ã¯ã»ã¹ã«é¢ããŠã ãŸããPHPãããã
ãããå§ããŸãããã
äœããããŸããã
InetãGoogle ...
...ãã¹ãŠ:(
ãããã»ãšãã©å¿ããŠããŸããã æãéèŠãªããšã 倩äºãªã®ã§ãèŠã€ããã®ã¯æãã ã£ãã
ã ããã°ãŒã°ã«ã
PHPã«ã¯ã±ã¿ã ã¯ãããŸããã ããã¯ã©ãã§ããã
Geeãlast.fmã§ã
www.lastfm.ru/user/RJ/journal/2007/04/10/rz_libketama_-_a_consistent_hashing_algo_for_memcache_clientsãããã2007幎4æ10æ¥ä»¥éã«ã®ã¿ããŒãžã§ã³0.1.1ãæŽæ°ãããããšã¯ãªããæ©èœã®ã»ããã¯äœãšãäžè¶³ããŠããŸãã ãã³ã¬ã comã¯ãã§ã«gets'yãcas'yãªã©ã§ãã ãŽãã ããã ã§ããããšã¯ã§ããŸãããããã¯ç Žå£ãç解ããããšã§ãã
ããã«Google ...
tangent.orgäœããããŸããã
MySQLã®Memcachedé¢æ°
libmemcached 0.23
ããã!!!!ã©ã€ãã©ãªã䜿çšããã¯ã©ã€ã¢ã³ãïŒ
RubyïŒ
github.com/fauna/memcached/tree/masterPerlïŒ
code.google.com/p/perl-libmemcachedPythonïŒ
code.google.com/p/python-libmemcachedPHPïŒïŒæ¥æ¬èªïŒ
labs.gree.jp/Top/OpenSource/libmemcached.htmlPHPã®ããå Žæã«è¡ããŸãã
ã«ã©ãŠã«!!! å°å±ã
ãããŒãšããŒãžã§ã³0.1.0ã ããããæ°é®®ãªã2008幎9æ18æ¥ããã èŠããã«ã誰ãããããæ¢ãæéããªãã£ãã®ã§ããã®äžã®äžå
·åã¯ãŸã ä¿®æ£ãããŠããŸããã
...ãã¹ãŠã
ãã以äžã
ããŠãè©ŠããŠã¿ãŸãã
ããããå°å±ããå§ããªãã»ããããã§ãããã
ç§ã¯ãã«ãžã§ã¢ã«ããããèªåœå
šäœã¯ïŒããã«ã¡ã¯ãã¯ããããããåé¡ãããããšããããã ãã§ãã
...ãŸãããã¡ãããã¹ãŠã§ã¯ãããŸããããŸã æ§äº€ããããŸããã圌ã¯ç§ãå©ããŸããã
æ¥æ¬èªã§ã¯ã圌ã¯ããããç¹ã§èãäœãã
MySQLçšã®libmemcachedããã³Memcachedé¢æ°ãããŒã¿ããŒã¹ãµãŒããŒã«é
眮ããŸããã WebãµãŒããŒlibmemcachedã«ã
4ã€ã®memcachedããŒã¢ã³ãéžæããŸãã WebãµãŒããŒäžã«1ã€ãããŒã¿ããŒã¹ãµãŒããŒäžã«3ã€ã ãªãã§ïŒ ãããŠFIGã¯ç¥ã£ãŠããŸããããã¯èµ·ãããŸããã
æ©èœãã€ã³ã¹ããŒã«ããŸãã
ããŒãããªã¹ãã¯å°è±¡çã§ã
memc_add
memc_add_by_key
memc_servers_set
memc_server_count
memc_set
memc_set_by_key
memc_cas
memc_cas_by_key
memc_get
memc_get_by_key
memc_delete
memc_delete_by_key
memc_append
memc_append_by_key
memc_prepend
memc_prepend_by_key
memc_increment
memc_decrement
memc_replace
memc_replace_by_key
memc_servers_behavior_set
memc_udf_version
memc_list_behaviors
memc_stats
memc_stat_get_keys
memc_stat_get_value
ããããŸããã casãããå ŽåïŒ ã©ãã«è¡ããŸããïŒ ãªãcasã¯gets'aãªãã§ç§ã«éäŒããïŒ
ããŠããããèŠããŠããŸãã ããããã
ãµãŒããŒã決å®ããŸã
SELECT memc_servers_set('192.168.0.10:11211, 192.168.0.11:11211, 192.168.0.11:11212, 192.168.0.11:11213);
ãã£ãã·ã¥ã«12åã®ããŒãæŒã蟌ã¿ãŸã
SELECT memc_set('key1', 'val1');
âŠ
SELECT memc_set('key10', 'val10');
ãã£ãã·ã¥ããããããåããŸã
SELECT memc_get('key1');
âŠ
SELECT memc_get('key10');
ããã¯æ®éã®ããã§ã圌ãã眮ãããã®ãäžããŸãã
çŸåšãmemcachedããŒã¢ã³ã1ã€åé€ããŠããŸãã äºæ³ã©ããã2ã€ã®ããŒãã«ããŒãããŸããã å床ãåãããŒã10åãã£ãã·ã¥ã«å
¥ããŸãã
ã€ããžã¯ã ãããã®2ã€ã®è¡æ¹äžæã¯çŸããŸããã§ããã ã±ã¿ãã¯èããããŸããã ãŸããäœããç§ã«èªãã readmeã¯zapadloã§ã¯ãããŸããã
Memcached Functions for MySQLã¯äœãå·§åŠãªãã®ãèŠã€ããŸããã§ããã
Tangent.orgã«è¡ããŸãããã
ãããŒããã¹ãŠãå®è¡ãããŠããæ¹æ³ã
ãããããã§ã¯ããã«ã€ããŠã®ããã§ã
docs.tangent.org/libmemcached/memcached_behavior.htmltranslate.ruã®åäœã«ãããšããã®åäœã§ãã
ããã©ã«ãã§ã¯ãMEMCACHED_BEHAVIOR_DISTRIBUTIONã®ã³ã¹ãã¯MEMCACHED_DISTRIBUTION_MODULAã§ãããMEMCACHED_DISTRIBUTION_CONSISTENTãšMEMCACHED_BEHAVIOR_HASHãå¿
èŠãªã®ã§ãMEMCACHED_HASH_KETAMAã«ãªããŸãã
ãããŠãmemcached_behavior_setïŒïŒãè¡ããŸãã MySQLã§ã¯ãããã¯memc_servers_behavior_setã§ãããšæ³å®ããå¿
èŠããããŸãã
ãã㊠ãããŠãããmemcached_behavior.podãããã¯ã«ãããã®ã§ã
=ã¢ã€ãã MEMCACHED_BEHAVIOR_DISTRIBUTION
ããã䜿çšããŠããµãŒããŒã«å€ãé
åžããããŸããŸãªæ段ãæå¹ã«ããããšãã§ããŸãã
ããã©ã«ãã®æ¹æ³ã¯MEMCACHED_DISTRIBUTION_MODULAã§ãã æå¹ã«ã§ããŸã
MEMCACHED_DISTRIBUTION_CONSISTENTãèšå®ããããšã«ããäžè²«ããããã·ã¥ã
äžè²«æ§ã®ããããã·ã¥ã«ãããããè¯ãåæ£ãå®çŸãããµãŒããŒã
æå°éã®ãã£ãã·ã¥æ倱ã§ã¯ã©ã¹ã¿ãŒã«è¿œå ãããŸãã çŸåš
MEMCACHED_DISTRIBUTION_CONSISTENTã¯å€ã®ãšã€ãªã¢ã¹ã§ã
MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMAã
=ã¢ã€ãã MEMCACHED_BEHAVIOR_KETAMA
ããã©ã«ãã®ååžãMEMCACHED_DISTRIBUTION_CONSISTENT_KETAMAã«èšå®ããŸã
MEMCACHED_HASH_MD5ãžã®ããã·ã¥ã
ç§ã®é ã®äžã®æ··ä¹±ãå§ãŸããŸãã
ãããç§ã¯ããããç解ããŠããŸããMEMCACHED_BEHAVIOR_KETAMAãè¡ãå¿
èŠããããŸã...
ã©ãïŒ
ããã«èªã¿ãŸãããã ãã¹ãŠãå¿
èŠãšããã®ã¯ã°ãããŠããããã§ãã ãŸã ãã«ãžã§ã¢ã¯byyyyãç解ããŠããŸãã
ããã¯ããã®ããã«èŠããŸã
åçŽãªãªã³ãŸãã¯ãªããªãã·ã§ã³ã®å Žåãå€1ãæž¡ãã ãã§ãã
ãããã£ãŠãMEMCACHED_BEHAVIOR_KETAMAã»ãã1ãå¿
èŠã§ãã
ããŠãè©ŠããŠã¿ãŸãããã
SELECT memc_servers_behavior_set ('MEMCACHED_BEHAVIOR_KETAMA', 1);
Mdaaaã ã«ãŒãã£ã¯ããã£ã±ãã§ãã
mysql>SELECT memc_servers_behavior_set('MEMCACHED_BEHAVIOR_KETAMA', 1);
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql>
MySQLãµãŒããŒãåèµ·åããã ãã§åŠçãããŸã...
ãŸãã éçºè
ãžã®æžã蟌ã¿
forums.mysql.com/read.php?150ã231325,231325ïŒmsg-231325ããã«...æªç»é²
forums.mysql.com/read.php?150ã231325,231359ïŒmsg-231359ãããããªã
forums.mysql.com/read.php?150ã231325,231442ïŒmsg-231442ããã¯åãã§ãã
ä¹
ãã¶ãã§ããã
æãã«ã倩äºãèŠãªããã°ãªããŸããã ãã¶ãããã«äœãããããŸããïŒ
ããã ã ãããŸãã ä»ã ãããã€ãã®èãã¯ã¹ããŒãã§ã¯ãªããæ±ãã§ãã
ã©ãããã§ãå¿
èŠãªãã®ã§ã¯ãªãå Žå ã ããã©ããã«çœ®ããã ã©ããã§ãããèŠã€ããŠãå¿
èŠãªãã®ãããã«çœ®ãã ãã§ãã
ã㌠ãœãŒã¹ã«ç»ããŸãã ãããŠã圌ãã¯äžŠãã§ããŸãã ãããŠãç§ã¯Cã«ã€ããŠã®ååããç¥ããŸããã èšèªããããšåŒã°ãããšããæå³ã§ã
ãŸãã äœãããå¿
èŠã¯ãããŸããã銎æã¿ã®ããèšèãæ¢ããŸãã
MySQLã©ã€ãã©ãªã¯ãããã䟡å€ããããŸããã libmemcachedèªäœã«ç»ããŸãã
ãããããã«ããã memcached.cã§ã 29è¡ç®
ptr-> distribution = MEMCACHED_DISTRIBUTION_MODULA;
2ã€ã®ããç¥ãããèšèã
ãããŠãååã®æ§æã«ã¯ææã§ãïŒmemcached_st * memcached_createïŒmemcached_st * ptrïŒã
ã§ã¯ãmemcached_stã誰ã§ããããç解ããŠã¿ãŸãããã
ããããç解ã§ããã libmemcached.podã«ãããšãtranslate.ruããã¹ãŠãæ£ãã説æããŠãããå Žåãããã¯ç§ãå¿
èŠãšãããã®ã§ã¯ãªãå Žæã§ãã
åã³
tangent.orgã«è¡ããŸãã Confã¯ããã«ãããŸããããMaylinã¯ãŒã
lists.tangent.org/mailman/listinfo/libmemcachedããããŸãã 倧ããããšã¯ãããŸããã ããªãã¿ã®èšèãæãã«æ¢ããŸãã
äœããããŸãã
lists.tangent.org/pipermail/libmemcached/2008-September/000434.htmlæ£ããç解ããŠããå Žåã¯ãMEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMITãèšå®ããå¿
èŠããããŸãã 圌ãã¯10ãæžããŸããç§ã¯3ãè©Šã¿ãŸãã
lists.tangent.org/pipermail/libmemcached/2008-August/000429.htmlãŸããç§ãã¡ã¯åãããšãããŸãã
ã ããã ãœãŒã¹ãä¿®æ£ããŠã¿ãŸãããã å¿
èŠãªãã®ã眮ããšããæå³ã§ã
代ããã«ãptr-> distribution = MEMCACHED_DISTRIBUTION_MODULA;
ptr-> distribution = MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA;ãšæžããŸãã
ãã Cã§ã®ç§ã®äººçã®æåã®0.5è¡
代ããã«ãptr-> retry_timeout = 0;
ptr-> retry_timeout = 60;ãšæžããŸãã
Yyyyyyyyyã 代ããã«MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMITã«ã€ããŠæžãã®ã¯ãªãã§ããïŒ
ç¹°ãè¿ããŸãããç§ãã¡ã¯æãã«å€©äºãèŠãŠããŸãã
ãããèŠãŠã ãœãŒã¹ã§SERVER_FAILURE_LIMITã«ã€ããŠæ€çŽ¢ããŸãã
ãããŸãã memcached_behavior.cã§ã ããŒãž166ãptr-> server_failure_limitãšåŒã°ããŸãã
æ®ããšã®é¡æšã§è¿œå
ptr-> server_failure_limit = 3;
ãã¶ãä¹è»ã ååãšããŠããµãŒããŒã¯çã«ãªããŸãã ã ããç§ãã¡ãããã眮ããŸãã
ãããèµ·ãã£ãããšã§ã
memcached_st *memcached_create(memcached_st *ptr)
{
memcached_result_st *result_ptr;
if (ptr == NULL)
{
ptr= (memcached_st *)malloc(sizeof(memcached_st));
if (!ptr)
return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
memset(ptr, 0, sizeof(memcached_st));
ptr->is_allocated= MEMCACHED_ALLOCATED;
}
else
{
memset(ptr, 0, sizeof(memcached_st));
}
result_ptr= memcached_result_create(ptr, &ptr->result);
WATCHPOINT_ASSERT(result_ptr);
ptr->poll_timeout= MEMCACHED_DEFAULT_TIMEOUT;
ptr->connect_timeout= MEMCACHED_DEFAULT_TIMEOUT;
ptr->retry_timeout= 60;
ptr->distribution= MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA;
ptr->server_failure_limit= 3;
return ptr;
}
ããã ãã§ã åã³ã³ãã€ã«ãŸãã¯ç¶è¡ããŸãã ãªãããå§ããŸããã...ãŸããããªãã¯ç解ããŠããŸããå埩ã
ãµãŒããŒã決å®ããŸã
SELECT memc_servers_set('192.168.0.10:11211, 192.168.0.11:11211, 192.168.0.11:11212, 192.168.0.11:11213);
ãã£ãã·ã¥ã«12åã®ããŒãæŒã蟌ã¿ãŸã
SELECT memc_set('key1', 'val1');
âŠ
SELECT memc_set('key10', 'val10');
ãã£ãã·ã¥ããããããåããŸã
SELECT memc_get('key1');
âŠ
SELECT memc_get('key10');
ããã¯æ®éã®ããã§ã圌ãã眮ãããã®ãäžããŸãã
memcachedããŒã¢ã³ã1ã€åé€ããŠããŸãã
ããããŸããã ãªããŠãã£ãã ãªã圌ãã¯ãã¹ãŠçããŠããã®ã§ããïŒ ããã¯ããã£ãã·ã¥ã«å
¥ããããŒã¿ã«ã€ããŠã®ç§ã§ãã
ããã£ã 2çªç®ã®Valimã
ãŸããç§ãã¡ã¯åæããŸããã§ããã 圌ãã¯ãã¹ãŠçããŠããŸãã
ãŸãã3çªç®ã®å Žåã
ãããŒãã¿ããªçããŠããã
ãŸããããªãã¯ç§ãã¡ãåãããšã¯ã§ããŸããã ã¹ã¯ã©ããã«å¯Ÿããåä»ã¯ãããŸããã æåŸã®4çªç®ã®memcachedããŒã¢ã³ãååŸããŸãã
åãããšã çåè
ã¯ããŸããã
ç§ãã¡ã¯æ®ºããè²ãŠãæãåºããæãåºãå§ããŸã...
...çãå埩ã
殺ããªã!!!
ããŒãã åäœããŸãã ãã以äžã
ãããã ããªãã¯ç§ãã¡ãé£ããŠè¡ããªãã§ãããã
ãã¹ãŠæ®ºãããïŒ
圌ã¯1ã€ã®ããŒããçãæ®ã£ãã éãã«2çªç®ã«çºçããŸããã memcachedãžã®åŒã³åºããæé
ããããšãªãã圌ã¯æåã®åŒã³åºãããã³ãããŸããã
ãã¹ãŠãçãæ®ã£ãããã§ã¯ãããŸããã ããªããçã眮ããã人ãç¥ã£ãŠãã ããã
ãã ç§ã¯äœã«ã€ããŠè©±ããŠããã®ã§ããã
å®éã«ã¯PHPã«ã€ããŠã
ããŠãå°å±
labs.gree.jp/Top/OpenSource/libmemcached.htmlã«è¡ããŸããã
ã ãããå°ãªããšããœãŒã¹ã¯å°å±ã«ããªãç¥ã«æè¬
github.com/kajidai/php-libmemcached/tree/masterãã蟌ã¿ãŸãã
labs.gree.jp/Top/OpenSource/libmemcached/Document.htmlè©ŠããŠ
<?php
$memcached = new Memcached();
$memcached->addserver('192.168.0.10', 11211);
$memcached->addserver('192.168.0.11', 11211);
$memcached->addserver('192.168.0.11', 11212);
$memcached->addserver('192.168.0.11', 11213);
$memcached->set('key1', 'val1');
$ret = $memcached->get('key1');
Echo $ret. â<br>â;
âŠ
ããã§ãªããåããŠããŸã...
MySQLã§åäœããŸãã
æ£ç¢ºã«ã¯ãããŒã¿ã¯ãã¢ã§åŠçãããŸãã
ç§ãã¡ã¯åããæã¡äžããæžããèªã¿ãŸã-ãã¹ãŠãæ£ããã§ãã
ããããšããã§ã WebãµãŒããŒäžã§ãåæãããlibmemcachedããã蟌ãŸããŸããã
ãŸããããã«ããæ©èœã«ã€ããŠã¯ã©ãã§ããããïŒ
æªããªã
memcached_ctor
memcached_server_add
memcached_add
memcached_add_by_key
memcached_append
memcached_append_by_key
memcached_behavior_get
memcached_behavior_set
memcached_cas
memcached_cas_by_key
memcached_delete
memcached_delete_by_key
memcached_get
memcached_get_by_key
memcached_set
memcached_set_by_key
memcached_increment
memcached_decrement
memcached_prepend
memcached_prepend_by_key
memcached_replace
memcached_replace_by_key
memcached_server_list
memcached_mget
memcached_fetch
memcached_server_list_append
memcached_server_push
ããã«ãè¡ããŸãã
ãããŠãã°ãªããã¯ã©ãã§ãã...
ãããŠFIGã¯åœŒãç¥ã£ãŠããŸãã
èŠã€ããããã«ã å®ã¯ããã·ã¢èªã®è±èªã§åãèè
ãæ¥æ¬ã«æžããŠã¯ãããŸããã çµå±ã®ãšããã圌ã¯æ¥æ¬èªã®è±èªã§çããŠãããã§ãããã
ãããŠãæŠäºãå§ãŸããŸãã
ããŠããœãŒã¹ã«å
¥ããŸãããã çµå±ãç§ã¯ãã§ã«åèšã§2.5è¡ãã®CãæžããŠããŸãã
ãããŒãããã¯ãšãŠãç°¡åã§ã...
ãããé転ããã 圌ã¯åã«zendã§åŒã³åºãããããŒããã£ã¹ãããããã®ã©ãããŒãäœæããŸããã ãããŒããããããããããå Žæã¯ä»ã«ãªãã§ãããã
ãŸãäœã
ãŸãšãããšã
第äžã«ã ç§ã¯Cã§æåã®2.5è¡ãæžããŸããã
第äºã«ã PHPã«ã¯ã±ã¿ã ããããŸãã
第äžã«ã ãã®ãã£ãã·ã¥ãç°¡åã«ãã³ãããŠãã ããã
4çªç®ã memcachedã®ããŒã¿ãžã®éåžžã®ã¢ã¯ã»ã¹ãããå°ãªããšãCãããå°ãªããšãPerlãããå°ãªããšãMySQLã䜿çšããPHPããä¿åããŸãã 1ã€ã¯åã§ããã©ãã§èª°ãæ£ããèªãããæ°ã«ããŸããã
PSã ãã©ã€ã¢ã³ã»ã¢ãŒã«ãŒã«
æ¬æãè¡šããbrian.krow.net