MySQL 5.6ã® RC çãåºã¾ããããé åçãªæ©è½ãæºè¼ã§çããwktkãã¦ãããã¨ã¨æãã¾ããæ©éãå人çã«æ°ã«ãªã£ã¦ãã memcached plugin ã試ãã¦ã¿ã¾ããã
æåã«çµè«ããè¨ãã¾ãããç¾æç¹ (5.6.7rc) ã§ã¯ HandlerSocket ã®ä»£ããã«ä½¿ãããããªãã®ã§ã¯ãªãããã§ãã
memcached protocol ã§ã¢ã¯ã»ã¹ã§ããã®ã¯å ¨ä½ã§ 1 ãã¼ãã«ã®ã¿è¨æ£: namespace ã¨ããä»çµã¿ã§è¤æ°ãã¼ãã«ã«mapãå¯è½ã§ããã¼ãã«ã®æåã³ã¼ã㯠latin1 ã§ããå¿ è¦ããã
ã2012-11-22 追è¨ã5.6.8RCã§ã¯ãæåã³ã¼ãã latin1 ã§ããã¨ããå¶éã¯æ¤å»ããã¾ãã
ãMySQL ã®ãã¼ãã«ã« memcached protocol ã§ã¢ã¯ã»ã¹ã§ãããã¨ããããã¯ããmemcached ã®ã¹ãã¬ã¼ã¸ã InnoDB ã«ã§ããããããªãã®ã¨èãã¦ããã ããã°ããã®ã§ã¯ãªããã¨ã
使ã£ã¦ã¿ã
ã§ã¯ä½¿ã£ã¦ã¿ã¾ããã¨ãã£ã¦ãã½ã¼ã¹ã«å«ã¾ãã plugin/innodb_memcached/README-innodb_memcached ã®ã¾ã¾ã§ããâ¦
è¨å®ã®ããã® SQL ãæµãè¾¼ãã§ã
$ mysql < scripts/innodb_memcached_config.sql
plugin ãèªã¿è¾¼ã¿ã¾ãã
mysql> install plugin daemon_memcached soname "libmemcached.so"; mysql> show plugins; +----------------------------+----------+--------------------+-----------------+---------+ | Name | Status | Type | Library | License | +----------------------------+----------+--------------------+-----------------+---------+ (ç¥) | daemon_memcached | ACTIVE | DAEMON | libmemcached.so | GPL | +----------------------------+----------+--------------------+-----------------+---------+
ãã㧠mysqld ã TCP/UDP 11211 ã listen ãã¾ããè¨å®ã¯ innodb_memcache ã¨ãããã¼ã¿ãã¼ã¹ã«ä¿åããã¾ãã
mysql [localhost] (innodb_memcache) > show tables; +---------------------------+ | Tables_in_innodb_memcache | +---------------------------+ | cache_policies | | config_options | | containers | +---------------------------+ 3 rows in set (0.00 sec) mysql [localhost] (innodb_memcache) > desc containers; +------------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+--------------+------+-----+---------+-------+ | name | varchar(50) | NO | PRI | NULL | | | db_schema | varchar(250) | NO | | NULL | | | db_table | varchar(250) | NO | | NULL | | | key_columns | varchar(250) | NO | | NULL | | | value_columns | varchar(250) | YES | | NULL | | | flags | varchar(250) | NO | | 0 | | | cas_column | varchar(250) | YES | | NULL | | | expire_time_column | varchar(250) | YES | | NULL | | | unique_idx_name_on_key | varchar(250) | NO | | NULL | | +------------------------+--------------+------+-----+---------+-------+ 9 rows in set (0.00 sec) mysql [localhost] (innodb_memcache) > select * from containers\G *************************** 1. row *************************** name: aaa db_schema: test db_table: demo_test key_columns: c1 value_columns: c2 flags: c3 cas_column: c4 expire_time_column: c5 unique_idx_name_on_key: PRIMARY 1 row in set (0.00 sec)
containers ã¨ãããã¼ãã«ã«ãmemcached plugin çµç±ã§å®éã«ã¢ã¯ã»ã¹ãããã¼ãã«ã®æ å ±ãä¿åãã¾ãã
ãã®ä¾ã ã¨ãtest.demo_test ã¨ãããã¼ãã«ã§ key ã c1, value ã c2 ã«ä¿åããããã¨ãããã¨ã«ãªãã¾ãã
mysql [localhost] (test) > select * from demo_test; +----+--------------+------+------+------+ | c1 | c2 | c3 | c4 | c5 | +----+--------------+------+------+------+ | AA | HELLO, HELLO | 8 | 0 | 0 | +----+--------------+------+------+------+ 1 row in set (0.00 sec)
telnet 㧠port 11211 ã«æ¥ç¶ã㦠get ãã¦ã¿ã¾ãã
$ telnet localhost 11211 Connected to localhost. get AA VALUE AA 8 12 HELLO, HELLO END
åãã¾ãããï¼ telnet 㧠set ãã¦ã¿ã¾ãã
$ telnet localhost 11211 Connected to localhost. set BB 0 0 3 BBB STORED
mysql [localhost] (test) > select * from demo_test; +----+--------------+------+------+------+ | c1 | c2 | c3 | c4 | c5 | +----+--------------+------+------+------+ | AA | HELLO, HELLO | 8 | 0 | 0 | | BB | BBB | 0 | 2 | 0 | +----+--------------+------+------+------+ 2 rows in set (0.00 sec)
ä¿åããã¦ãã¾ãã
注æç¹
- flags, cas_column, expire_time_column ã®ã«ã©ã 㯠NULL ã§ã¯ãããªã (memcached protocolã§åå¾ã§ããªã)
- ãã¼ã¿ãä¿åãããã¼ãã«ã®æåã³ã¼ã㯠latin1
- ä»ã®æåã³ã¼ãã«ããã¨ãmysqld èµ·åæã« "Failed to initialize instance. Error code: 13" ã¨ããã¨ã©ã¼ãåºåããã¦ãmemcached plugin ãæå¹ã«ãªããªã
- â 5.6.7RCã¾ã§ã5.6.8RCã§ã¯ UTF-8 ãªã©ã§åé¡ããã¾ãã
軽ããã³ããã¼ã¯
memslap ã使ã£ã¦ã¿ã¾ããã
$ memslap --servers=127.0.0.1:11211 --test set Took 14.781 seconds to load data $ memslap --servers=127.0.0.1:11211 --test get Took 1.232 seconds to read data
æ¬ç©ã® memcached
$ memslap --servers=127.0.0.1:11222 --test set Took 0.533 seconds to load data $ memslap --servers=127.0.0.1:11222 --test get Took 0.655 seconds to read data
daemon_memcached_w_batch_size ã¨ãããã©ã¡ã¼ã¿ã§æ¸ãè¾¼ã¿ãã¾ã¨ãã¦æ§è½ãä¸ãããã¨ãã§ãã¾ãã
# my.cnf [mysqld] daemon_memcached_w_batch_size = 100
$ memslap --servers=127.0.0.1:11211 --test set Took 4.512 seconds to load data
memstat ã®åºå
curr_items, total_items, bytes ãããã®æ°å¤ã¯åããªãããã§ãã
$ memstat --servers=127.0.0.1:11211 Server: 127.0.0.1 (11211) pid: 11353 uptime: 286 time: 1349335741 version: 5.6.7-rc pointer_size: 64 rusage_user: 8.724673 rusage_system: 10.740367 curr_items: 0 total_items: 0 bytes: 0 curr_connections: 3 total_connections: 12 connection_structures: 3 cmd_get: 30000 cmd_set: 60000 get_hits: 30000 get_misses: 0 evictions: 0 bytes_read: 0 bytes_written: 0 limit_maxbytes: 67108864 threads: 4
ã¾ã¨ã
æ®éã«åãã¾ã ããå
¨ä½ã§1ãã¼ãã«ãã使ããªãã¨ã¡ãã£ã¨ä½¿ãã©ãããé£ããã§ããã
ä¸å¿ã innodb_memcache.containers ãã¼ãã«ã«ã¯ name ã«ã©ã ããã£ã¦ããã®ã«ã©ã ã«ãã£ã¦èªã¿è¾¼ãè¨å®ãåãããããªãã¨ã¯æ³å®ããã¦ããããã§ããããç¾ç¶ã¯æåã®1è¡ã決ããã¡ã§èªã¿è¾¼ãã§ããã®ã§ãè¤æ°è¡å
¥ãã¦ãæåã®è¡ã®è¨å®ããæå¹ã«ãªãã¾ããã (è¨æ£): containers ã® name ã«å
¥ããå¤ã使ã£ã¦ãå¥ãã¼ãã«ã«ã¢ã¯ã»ã¹å¯è½ã§ãããnamespaceã使ããã«ããã©ã«ãã§ã¢ã¯ã»ã¹ããã®ãæåã®1è¡ã§å®ç¾©ããã¦ãããã¼ãã«ã§ãã
+------+-----------+------------+-------------+---------------+-------+------------+--------------------+------------------------+ | name | db_schema | db_table | key_columns | value_columns | flags | cas_column | expire_time_column | unique_idx_name_on_key | +------+-----------+------------+-------------+---------------+-------+------------+--------------------+------------------------+ | aaa | test | demo_test | c1 | c2 | c3 | c4 | c5 | PRIMARY | | bbb | test | demo_test2 | c1 | c2 | c3 | c4 | c5 | PRIMARY | +------+-----------+------------+-------------+---------------+-------+------------+--------------------+------------------------+
ãã®ç¶æ ã§ãmemcached protocol ã§ã¢ã¯ã»ã¹ãã key ã @@aaa.foo ã¨ãã㨠demo_test.c1='foo' ã«ã@@bbb.foo ã¨ãã㨠demo_test2.c1='foo' ã«ã¢ã¯ã»ã¹ãããã¨ãã§ãã¾ãã