MySQL5.6から利用出来る、memcached pluginの動作確認になります。
Webサイトではユーザーセッション管理などでmemacheとrepcachedを利用して、
高速データ処理をしてました。MySQLでもPluginとしてmemcachedが使えるようになり、
NOSQL処理も出来るようになりました。mysqlのmemcachedはACID対応可能で、
innodbと連携出来るので、整合性を保ったNOSQLとして利用出来る事が特徴になります。
また、SETコマンドなどで処理したデータはテーブルに保存されるので、
再起動しても残す事が出来ます。

Pluginのインストール

root@localhost [(none)]>system cat /usr/local/mysql/share/innodb_memcached_config.sql
create database innodb_memcache;

use innodb_memcache;


-- ------------------------------------------------------------------------
-- Following are set of "configuration tables" that used to configure
-- the InnoDB Memcached.
-- ------------------------------------------------------------------------

-- ------------------------------------------------------------------------
-- Table `cache_policies`
--
-- Each record in this table represents a named caching policy, specifying:
--  * How the memcache GET command is executed, including whether to get
--    records from local cache only, from InnoDB only, from local cache if
--    present (treating InnoDB as a backing store), or not at all.
--  * Similarly, how memcache SET commands are executed.
--  * How memcache DELETE commands are executed.
--  * Whether flushing the cache should cause a mass delete from NDB.
--
-- ------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `cache_policies` (
        `policy_name` VARCHAR(40) PRIMARY KEY,
        `get_policy` ENUM('innodb_only', 'cache_only', 'caching','disabled')
         NOT NULL ,
        `set_policy` ENUM('innodb_only', 'cache_only','caching','disabled')
         NOT NULL ,
        `delete_policy` ENUM('innodb_only', 'cache_only', 'caching','disabled')
         NOT NULL,
        `flush_policy` ENUM('innodb_only', 'cache_only', 'caching','disabled')
         NOT NULL
) ENGINE = innodb;


-- ------------------------------------------------------------------------
-- Table `containers`
--
-- A container record describes an InnoDB table used for data storage by
-- InnoDB Memcache.
-- There must be a unique index on the `key column`, and unique index name
-- is specified in the `unique_idx_name_on_key` column of the table
-- `value_columns` are comma-separated lists of the columns that make up
-- the memcache key and value. Each column width is defined such that they
-- are in consistent with NDB memcached.
-- ------------------------------------------------------------------------

CREATE  TABLE IF NOT EXISTS `containers` (
        `name` varchar(50) not null primary key,
        `db_schema` VARCHAR(250) NOT NULL,
        `db_table` VARCHAR(250) NOT NULL,
        `key_columns` VARCHAR(250) NOT NULL,
        `value_columns` VARCHAR(250),
        `flags` VARCHAR(250) NOT NULL DEFAULT "0",
        `cas_column` VARCHAR(250),
        `expire_time_column` VARCHAR(250),
        `unique_idx_name_on_key` VARCHAR(250) NOT NULL
) ENGINE = InnoDB;

CREATE  TABLE IF NOT EXISTS `config_options` (
        `name` varchar(50) not null primary key,
        `value` varchar(50)) ENGINE = InnoDB;

-- ------------------------------------------------------------------------
-- This is an example
-- We create a InnoDB table `demo_test` is the `test` database
-- and insert an entry into contrainers' table to tell InnoDB Memcache
-- that we has such InnoDB table as back store:
-- c1 -> key
-- c2 -> value
-- c3 -> flags
-- c4 -> cas
-- c5 -> exp time
-- PRIMARY -> use primary key to search
-- ------------------------------------------------------------------------

INSERT INTO containers VALUES ("aaa", "test", "demo_test",
                               "c1", "c2",  "c3", "c4", "c5", "PRIMARY");

INSERT INTO cache_policies VALUES("cache_policy", "innodb_only",
                                  "innodb_only", "innodb_only", "innodb_only");

INSERT INTO config_options VALUES("separator", "|");
INSERT INTO config_options VALUES("table_map_delimiter", ".");

USE test

-- ------------------------------------------------------------------------
-- Key (c1) must be VARCHAR or CHAR type, memcached supports key up to 255
-- Bytes
-- Value (c2) must be VARCHAR or CHAR type
-- Flag (c3) is a 32 bits integer
-- CAS (c4) is a 64 bits integer, per memcached define
-- Exp (c5) is again a 32 bits integer
-- ------------------------------------------------------------------------
CREATE TABLE demo_test (c1 VARCHAR(32),
                        c2 VARCHAR(1024),
                        c3 INT, c4 BIGINT UNSIGNED, c5 INT, primary key(c1))
ENGINE = INNODB;

INSERT INTO demo_test VALUES ("AA", "HELLO, HELLO", 8, 0, 0);
root@localhost [(none)]>


root@localhost [(none)]>source /usr/local/mysql/share/innodb_memcached_config.sql
Query OK, 1 row affected (0.02 sec)

Database changed
Query OK, 0 rows affected (0.07 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 1 row affected (0.02 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.01 sec)

Query OK, 1 row affected (0.00 sec)

Database changed
Query OK, 0 rows affected (0.03 sec)

Query OK, 1 row affected (0.01 sec)

root@localhost [test]>


root@localhost [(none)]>show variables like 'plugin%';
+---------------+------------------------------+
| Variable_name | Value                        |
+---------------+------------------------------+
| plugin_dir    | /usr/local/mysql/lib/plugin/ |
+---------------+------------------------------+
1 row in set (0.00 sec)

root@localhost [(none)]>install plugin daemon_memcached soname "libmemcached.so";
Query OK, 0 rows affected (0.16 sec)

root@localhost [(none)]>


root@localhost [information_schema]>select PLUGIN_NAME,PLUGIN_VERSION,PLUGIN_STATUS,LOAD_OPTION from PLUGINS
    -> where PLUGIN_NAME like '%memcached';
+------------------+----------------+---------------+-------------+
| PLUGIN_NAME      | PLUGIN_VERSION | PLUGIN_STATUS | LOAD_OPTION |
+------------------+----------------+---------------+-------------+
| daemon_memcached | 1.0            | ACTIVE        | ON          |
+------------------+----------------+---------------+-------------+
1 row in set (0.00 sec)

root@localhost [information_schema]>



root@localhost [(none)]>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| innodb_memcache    |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)


root@localhost [innodb_memcache]>use innodb_memcache
Database changed
root@localhost [innodb_memcache]>show tables;
+---------------------------+
| Tables_in_innodb_memcache |
+---------------------------+
| cache_policies            |
| config_options            |
| containers                |
+---------------------------+
3 rows in set (0.00 sec)

root@localhost [innodb_memcache]>

root@localhost [innodb_memcache]>desc cache_policies;
+---------------+-------------------------------------------------------+------+-----+---------+-------+
| Field         | Type                                                  | Null | Key | Default | Extra |
+---------------+-------------------------------------------------------+------+-----+---------+-------+
| policy_name   | varchar(40)                                           | NO   | PRI | NULL    |       |
| get_policy    | enum('innodb_only','cache_only','caching','disabled') | NO   |     | NULL    |       |
| set_policy    | enum('innodb_only','cache_only','caching','disabled') | NO   |     | NULL    |       |
| delete_policy | enum('innodb_only','cache_only','caching','disabled') | NO   |     | NULL    |       |
| flush_policy  | enum('innodb_only','cache_only','caching','disabled') | NO   |     | NULL    |       |
+---------------+-------------------------------------------------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

root@localhost [innodb_memcache]>desc config_options;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name  | varchar(50) | NO   | PRI | NULL    |       |
| value | varchar(50) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

root@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)

root@localhost [innodb_memcache]>

root@localhost [innodb_memcache]>select * from cache_policies;
+--------------+-------------+-------------+---------------+--------------+
| policy_name  | get_policy  | set_policy  | delete_policy | flush_policy |
+--------------+-------------+-------------+---------------+--------------+
| cache_policy | innodb_only | innodb_only | innodb_only   | innodb_only  |
+--------------+-------------+-------------+---------------+--------------+
1 row in set (0.00 sec)

root@localhost [innodb_memcache]>select * from config_options;
+---------------------+-------+
| name                | value |
+---------------------+-------+
| separator           | |     |
| table_map_delimiter | .     |
+---------------------+-------+
2 rows in set (0.00 sec)

root@localhost [innodb_memcache]>select * from containers;
+------+-----------+-----------+-------------+---------------+-------+------------+--------------------+------------------------+
| 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                |
+------+-----------+-----------+-------------+---------------+-------+------------+--------------------+------------------------+
1 row in set (0.00 sec)

root@localhost [innodb_memcache]>select * from test.demo_test;
+----+--------------+------+------+------+
| c1 | c2           | c3   | c4   | c5   |
+----+--------------+------+------+------+
| AA | HELLO, HELLO |    8 |    0 |    0 |
+----+--------------+------+------+------+
1 row in set (0.00 sec)

root@localhost [innodb_memcache]>

TELENETでmemcachedのDefault Portに接続してデータ操作してみる
set, replace, append, prepend
<コマンド>

get, gets, delete
<コマンド> <キー>

[root@misc admin]# telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
get AA
VALUE AA 8 12
HELLO, HELLO
END
quit
Connection closed by foreign host.
[root@misc admin]#

[root@misc admin]# telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
set a11 10 0 9
123456789
STORED
get a11
VALUE a11 10 9
123456789
[root@misc admin]#


root@localhost [innodb_memcache]>select * from test.demo_test;
+-----+--------------+------+------+------+
| c1  | c2           | c3   | c4   | c5   |
+-----+--------------+------+------+------+
| a11 | 123456789    |   10 |    3 |    0 |
| AA  | HELLO, HELLO |    8 |    0 |    0 |
+-----+--------------+------+------+------+
2 rows in set (0.00 sec)

root@localhost [innodb_memcache]>

root@localhost [test]>delete from test.demo_test;
Query OK, 2 rows affected (0.07 sec)

root@localhost [test]>select * from test.demo_test;
Empty set (0.00 sec)

[root@misc admin]# telnet localhost 11211 
Trying ::1...
Connected to localhost.
Escape character is '^]'.
set a11 10 0 9
123456789
STORED
set AA 0 0 12
HELLO, HELLO
STORED
get all
END
get AA
VALUE AA 0 12
HELLO, HELLO
END
set BB 0 0 12
HELLO, MEMCA
STORED
get BB
VALUE BB 0 12
HELLO, MEMCA
END
quit
Connection closed by foreign host.
[root@misc admin]# 

root@localhost [test]>select * from test.demo_test;
+-----+--------------+------+------+------+
| c1  | c2           | c3   | c4   | c5   |
+-----+--------------+------+------+------+
| a11 | 123456789    |   10 |    1 |    0 |
| AA  | HELLO, HELLO |    0 |    2 |    0 |
| BB  | HELLO, MEMCA |    0 |    3 |    0 |
+-----+--------------+------+------+------+
3 rows in set (0.00 sec)

root@localhost [test]>

DB側の設定とmemcachedのステータス

root@localhost [test]>show variables like '%memcached%';
+----------------------------------+------------------+
| Variable_name                    | Value            |
+----------------------------------+------------------+
| daemon_memcached_enable_binlog   | OFF              |
| daemon_memcached_engine_lib_name | innodb_engine.so |
| daemon_memcached_engine_lib_path |                  |
| daemon_memcached_option          |                  |
| daemon_memcached_r_batch_size    | 1                |
| daemon_memcached_w_batch_size    | 1                |
+----------------------------------+------------------+
6 rows in set (0.00 sec)

root@localhost [test]>

[root@misc admin]# telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
stats
STAT pid 3646
STAT uptime 913
STAT time 1420435227
STAT version 5.6.22
STAT libevent 5.6.22
STAT pointer_size 64
STAT rusage_user 0.467361
STAT rusage_system 0.858934
STAT daemon_connections 2
STAT curr_connections 3
STAT total_connections 4
STAT connection_structures 3
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT auth_cmds 0
STAT auth_errors 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT bytes_read 24
STAT bytes_written 7
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT rejected_conns 0
STAT threads 4
STAT conn_yields 0
STAT evictions 0
STAT curr_items 0
STAT total_items 0
STAT bytes 0
STAT reclaimed 0
STAT engine_maxbytes 67108864
END

MySQL側でデータを追加してMemcached側で確認してみる。
set-memcached

14.18.3.2 Installing and Configuring the InnoDB memcached Plugin
http://dev.mysql.com/doc/refman/5.6/en/innodb-memcached-installing.html
14.18.7 Internals of the InnoDB memcached Plugin
http://dev.mysql.com/doc/refman/5.6/en/innodb-memcached-internals.html
14.18.2 Architecture of InnoDB and memcached Integration
http://dev.mysql.com/doc/refman/5.6/en/innodb-memcached-intro.html


PerlからMemcachedを使ってみる
前回は、memcached基本設定でmemcachedのインストールのみ
しておいたのでPerlから簡易処理して動作確認してみる。

ファイルに書かれた設定やDBのデータをメモリ上にのせておくことで高速にデータの
取得を行うことが出来るようになります。

Memcachedのサービスを落とすとデータは消えます。何らかの理由でmemcachedが落ちてしまうと
データが全部消えて無くなってしまうので、もし永続的に利用したい場合は、
IO Driveなどを利用すると良いかと思います。

CPANでCache::Memcached::Fastをインストール

Cache::Memcahced::Fast is a Perl client for memcached,
a memory cache daemon (http://www.danga.com/memcached/).
Module core is implemented in C and tries hard to minimize number of system calls
and to avoid any key/value copying for speed. As a result, it has very low CPU consumption.

API is largely compatible with Cache::Memcached, original pure Perl client,
most users of the original module may start using this module by installing it
and adding “::Fast” to the old name in their scripts
(see “Compatibility with Cache::Memcached” below for full details).


[root@colinux mem]$ perl -MCPAN -e 'install Cache::Memcached::Fast'
CPAN: Storable loaded ok
Going to read /home/user/.cpan/Metadata
Database was generated on Fri, 10 Aug 2012 08:03:04 GMT
Cache::Memcached::Fast is up to date.
[root@colinux mem]$

[root@colinux mem]# cat memcached_fast.pl
#!/usr/bin/perl

use strict;
#use warnings;
use Cache::Memcached::Fast;

my $key = "key";
my $cache = Cache::Memcached::Fast->new({servers=>["localhost:11211"]});

$cache->set($key,"This is Memcache test by Perl");
if( my $val = $cache->get($key) ) { print "[ GET DATA FROM CACHE ] ".$val."\n";}

$cache->replace($key,"This is 2nd  Memcache test by Perl");
if( my $val = $cache->get($key) ) { print "[ GET DATA FROM CACHE ] ".$val."\n";}

$cache->delete($key);
if( my $val = $cache->get($key) ) { print "[ GET DATA FROM CACHE ] ".$val."\n";}
print "[ GET DATA FROM CACHE ] Data is deleted!! Please use flush_all to delete all data.\n";
[root@colinux mem]#


[root@colinux mem]$ ./memcached_fast.pl
[ GET DATA FROM CACHE ] This is Memcache test by Perl
[ GET DATA FROM CACHE ] This is 2nd Memcache test by Perl
[ GET DATA FROM CACHE ] Data is deleted!! Please use flush_all to delete all data.
[root@colinux mem]$

memcached

関連リンク
memcached基本設定

参考サイト
Cache::Memcached::Fast
Memcachedのインストール・利用方法
Perl Hackers Hub
memcachedを知り尽くす


memcached は、データとオブジェクトをメモリ内にキャッシュすることで、
データベースなどからデータを頻繁に取りにいくことを減らしてパフォーマンスを改善させたり、
セッションをmemcached上に載せる事で、高速なセッション管理を行ったりする事が出来る。

The latest stable memcached release is
v1.4.13
memcached.org

Free & open source, high-performance, distributed memory object caching system,
generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

libeventのインストール

[root@ Sun May 27]# yum install libevent libevent-devel
Loaded plugins: fastestmirror, priorities, security, update-motd
Loading mirror speeds from cached hostfile
* amzn-main: packages.ap-northeast-1.amazonaws.com
* amzn-updates: packages.ap-northeast-1.amazonaws.com
amzn-main | 2.1 kB 00:00
amzn-updates | 2.3 kB 00:00
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package libevent.x86_64 0:1.4.13-1.6.amzn1 will be installed
—> Package libevent-devel.x86_64 0:1.4.13-1.6.amzn1 will be installed
–> Finished Dependency Resolution

省略…
Dependencies ResolvedDownloading Packages:
(1/2): libevent-1.4.13-1.6.amzn1.x86_64.rpm | 114 kB 00:00
(2/2): libevent-devel-1.4.13-1.6.amzn1.x86_64.rpm | 386 kB 00:00

MEMCACHEDインストール

[root@ Sun May 27]# wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
–2012-05-27 17:56:05– http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
Resolving memcached.googlecode.com… 72.14.203.82
Connecting to memcached.googlecode.com|72.14.203.82|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 320751 (313K) [application/x-gzip]
Saving to: “memcached-1.4.13.tar.gz”

100%[==========================================================================>] 320,751 1.37M/s in 0.2s

2012-05-27 17:56:06 (1.37 MB/s) – “memcached-1.4.13.tar.gz” saved [320751/320751]

[root@ Sun May 27]#

[root@ Sun May 27]# tar zxf memcached-1.4.13.tar.gz
[root@ Sun May 27]# ls -l
total 320
drwxr-xr-x 6 1000 1000 4096 Feb 3 06:24 memcached-1.4.13
-rw-r–r– 1 root root 320751 Feb 3 06:27 memcached-1.4.13.tar.gz
[root@ Sun May 27]# cd memcached-1.4.13
[root@ Sun May 27]# ./configure
checking build system type… x86_64-unknown-linux-gnu
checking host system type… x86_64-unknown-linux-gnu
checking target system type… x86_64-unknown-linux-gnu
checking for a BSD-compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking for a thread-safe mkdir -p… /bin/mkdir -p
checking for gawk… gawk
checking whether make sets $(MAKE)… yes
checking for gcc… gcc
checking whether the C compiler works… yes
checking for C compiler default output file name… a.out
checking for suffix of executables…
checking whether we are cross compiling… no
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes

[省略]……………………………………..

[root@ Sun May 27]# make
make all-recursive
make[1]: Entering directory `/home/ec2-user/memcached/memcached-1.4.13′
Making all in doc
make[2]: Entering directory `/home/ec2-user/memcached/memcached-1.4.13/doc’
make all-am
make[3]: Entering directory `/home/ec2-user/memcached/memcached-1.4.13/doc’
make[3]: Nothing to be done for `all-am’.
make[3]: Leaving directory `/home/ec2-user/memcached/memcached-1.4.13/doc’
make[2]: Leaving directory `/home/ec2-user/memcached/memcached-1.4.13/doc’
make[2]: Entering directory `/home/ec2-user/memcached/memcached-1.4.13′
gcc -std=gnu99 -DHAVE_CONFIG_H -I. -DNDEBUG -g -O2 -pthread -Wall -Werror -pedantic
-Wmissing-prototypes -Wmissing-declarations -Wredundant -decls -fno-strict-aliasing -MT memcached-memcached.o
-MD -MP -MF .deps/memcached-memcached.Tpo -c -o memcached-memcached.o `test -f ‘memcached.c’ || echo ‘./’`memcached.c

[root@ Sun May 27]# make install
make install-recursive
make[1]: Entering directory `/home/ec2-user/memcached/memcached-1.4.13′
Making install in doc
make[2]: Entering directory `/home/ec2-user/memcached/memcached-1.4.13/doc’
make install-am
make[3]: Entering directory `/home/ec2-user/memcached/memcached-1.4.13/doc’
make[4]: Entering directory `/home/ec2-user/memcached/memcached-1.4.13/doc’
make[4]: Nothing to be done for `install-exec-am’.
test -z “/usr/local/share/man/man1” || /bin/mkdir -p “/usr/local/share/man/man1”
/usr/bin/install -c -m 644 memcached.1 ‘/usr/local/share/man/man1′
make[4]: Leaving directory `/home/ec2-user/memcached/memcached-1.4.13/doc’
make[3]: Leaving directory `/home/ec2-user/memcached/memcached-1.4.13/doc’
make[2]: Leaving directory `/home/ec2-user/memcached/memcached-1.4.13/doc’
make[2]: Entering directory `/home/ec2-user/memcached/memcached-1.4.13′
make[3]: Entering directory `/home/ec2-user/memcached/memcached-1.4.13′
test -z “/usr/local/bin” || /bin/mkdir -p “/usr/local/bin”
/usr/bin/install -c memcached ‘/usr/local/bin’
test -z “/usr/local/include/memcached” || /bin/mkdir -p “/usr/local/include/memcached”
/usr/bin/install -c -m 644 protocol_binary.h ‘/usr/local/include/memcached’
make[3]: Leaving directory `/home/ec2-user/memcached/memcached-1.4.13′
make[2]: Leaving directory `/home/ec2-user/memcached/memcached-1.4.13′
make[1]: Leaving directory `/home/ec2-user/memcached/memcached-1.4.13′
[root@ Sun May 27]#

[root@ Sun May 27]# whereis memcached
memcached: /usr/local/bin/memcached
[root@ Sun May 27]#

基本起動確認

[ec2-user@ Sun May 27]$ /usr/local/bin/memcached -p 11211 -m 10m -vv
slab class 1: chunk size 96 perslab 10922
slab class 2: chunk size 120 perslab 8738
slab class 3: chunk size 152 perslab 6898
slab class 4: chunk size 192 perslab 5461
slab class 5: chunk size 240 perslab 4369
slab class 6: chunk size 304 perslab 3449
slab class 7: chunk size 384 perslab 2730
slab class 8: chunk size 480 perslab 2184
slab class 9: chunk size 600 perslab 1747
slab class 10: chunk size 752 perslab 1394
slab class 11: chunk size 944 perslab 1110
slab class 12: chunk size 1184 perslab 885
slab class 13: chunk size 1480 perslab 708
slab class 14: chunk size 1856 perslab 564
slab class 15: chunk size 2320 perslab 451
slab class 16: chunk size 2904 perslab 361
slab class 17: chunk size 3632 perslab 288
slab class 18: chunk size 4544 perslab 230
slab class 19: chunk size 5680 perslab 184
slab class 20: chunk size 7104 perslab 147
slab class 21: chunk size 8880 perslab 118
slab class 22: chunk size 11104 perslab 94
slab class 23: chunk size 13880 perslab 75
slab class 24: chunk size 17352 perslab 60
slab class 25: chunk size 21696 perslab 48
slab class 26: chunk size 27120 perslab 38
slab class 27: chunk size 33904 perslab 30
slab class 28: chunk size 42384 perslab 24
slab class 29: chunk size 52984 perslab 19
slab class 30: chunk size 66232 perslab 15
slab class 31: chunk size 82792 perslab 12
slab class 32: chunk size 103496 perslab 10
slab class 33: chunk size 129376 perslab 8
slab class 34: chunk size 161720 perslab 6
slab class 35: chunk size 202152 perslab 5
slab class 36: chunk size 252696 perslab 4
slab class 37: chunk size 315872 perslab 3
slab class 38: chunk size 394840 perslab 2
slab class 39: chunk size 493552 perslab 2
slab class 40: chunk size 616944 perslab 1
slab class 41: chunk size 771184 perslab 1
slab class 42: chunk size 1048576 perslab 1
<26 server listening (auto-negotiate) <27 server listening (auto-negotiate) <28 send buffer was 229376, now 268435456 <29 send buffer was 229376, now 268435456 <28 server listening (udp) <29 server listening (udp)

バックグラウンド起動し動作検証

デーモンとしてバックグラウンド起動
[ec2-user@ Sun May 27]$ /usr/local/bin/memcached -p 11211 -m 10m -d
[ec2-user@ Sun May 27]$ ps -ef | grep mem
ec2-user 18639 1 0 18:04 ? 00:00:00 /usr/local/bin/memcached -p 11211 -m 10m -d
ec2-user 18646 17197 0 18:04 pts/0 00:00:00 grep mem
[ec2-user@ Sun May 27]$

[ec2-user@ Sun May 27]$ /usr/local/bin/memcached -h
memcached 1.4.13
-p TCP port number to listen on (default: 11211)
-U UDP port number to listen on (default: 11211, 0 is off)
-s UNIX socket path to listen on (disables network support)
-a access mask for UNIX socket, in octal (default: 0700)
-l interface to listen on (default: INADDR_ANY, all addresses)
may be specified as host:port. If you don’t specify
a port number, the value you specified with -p or -U is
used. You may specify multiple addresses separated by comma
or by using -l multiple times
-d run as a daemon
-r maximize core file limit
-u assume identity of (only when run as root)
-m max memory to use for items in megabytes (default: 64 MB)
-M return error on memory exhausted (rather than removing items)
-c max simultaneous connections (default: 1024)
-k lock down all paged memory. Note that there is a
limit on how much memory you may lock. Trying to
allocate more than that would fail, so be sure you
set the limit correctly for the user you started
the daemon with (not for -u user;
under sh this is done with ‘ulimit -S -l NUM_KB’).
-v verbose (print errors/warnings while in event loop)
-vv very verbose (also print client commands/reponses)
-vvv extremely verbose (also print internal state transitions)
-h print this help and exit
-i print memcached and libevent license
-P save PID in , only used with -d option
-f chunk size growth factor (default: 1.25)
-n minimum space allocated for key+value+flags (default: 48)
-L Try to use large memory pages (if available). Increasing
the memory page size could reduce the number of TLB misses
and improve the performance. In order to get large pages
from the OS, memcached will allocate the total item-cache
in one large chunk.
-D Use as the delimiter between key prefixes and IDs.
This is used for per-prefix stats reporting. The default is
“:” (colon). If this option is specified, stats collection
is turned on automatically; if not, then it may be turned on
by sending the “stats detail on” command to the server.
-t number of threads to use (default: 4)
-R Maximum number of requests per event, limits the number of
requests process for a given connection to prevent
starvation (default: 20)
-C Disable use of CAS
-b Set the backlog queue limit (default: 1024)
-B Binding protocol – one of ascii, binary, or auto (default)
-I Override the size of each slab page. Adjusts max item size
(default: 1mb, min: 1k, max: 128m)
-o Comma separated list of extended or experimental options
– (EXPERIMENTAL) maxconns_fast: immediately close new
connections if over maxconns limit
– hashpower: An integer multiplier for how large the hash
table should be. Can be grown at runtime if not big enough.
Set this based on “STAT hash_power_level” before a
restart.
[ec2-user@ Sun May 27]$

telnet経由でデータの入力などの基本動作検証

[ec2-user@ Sun May 27]$ telnet localhost 11211
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
stats
STAT pid 18639
STAT uptime 1139
STAT time 1338110621
STAT version 1.4.13
STAT libevent 1.4.13-stable
STAT pointer_size 64
STAT rusage_user 0.015997
STAT rusage_system 0.015997
STAT curr_connections 10
STAT total_connections 11

set key01 0 0 5
00001
set key02 0 0 5
00002
set key03 0 0 5
00003

memcached

memcached