my $memd = Cache::Memcached::Fast->new({
	   servers => [qw!192.168.67.31:11211 192.168.67.32:11211!]
});

if ( my $nickna...
% ./memstrike -l localhost -p 11211 -t 10 -k 8 -v 8 50000
number of threads    : 10
number of requests   : 50000
requests ...
VS
VS
memcached   ×
% sudo ./memcached -c 262144 -u nobody
4532 int maxfiles = settings.maxconns;
4533 if (rlim.rlim_cur < maxfiles)
4534     rlim.rlim_cur = maxfiles;
4535 if (rlim...
% ./memcached -l 127.0.0.1
% ./memcached -l 192.168.67.31
% ./memcached -l 192.168.67.31

..

% ssh myserver
% telnet localhost 11211
Trying ::1...
Trying 127.0.0.1...
telnet: Unab...
% sudo ./memcached -c 262144 -u nobody
% ./memcached -vvv
slab class   1: chunk size       96 perslab    10922


slab class 40: chunk size    1048576 perslab    ...
% ./memcached -p 11211 -U 0
% ./memcached -U 0




% ./memcached -U 12345
% ./memcached -m 16G
% ./memcached -C -m 16G
% ./memcached -c 32768 -u nobody 
              -C -m 16G -p 11211 -U 0
% telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
stats settings
STAT   maxbytes 16...
define host{
  use         generic-host
  host_name    memserver
  alias        memserver
  address      192.168.67.30
}
d...
define command {
  command_name    check_memcached
  command_line    $USER1$/check_tcp 
    -H $HOSTADDRESS$ 
    -p 11211...
define command {
  command_name    check_memcached
  command_line      $USER1$/check_tcp
    -H $HOSTADDRESS$ 
    -p 1121...
stats                             STAT   decr_misses 0
STAT pid 4825                     STAT   decr_hits 0
STAT uptime 78...
#!/usr/local/bin/activeperl

use   strict;
use   warnings;
use   Getopt::Long;
use   IO::Socket::INET;

GetOptions(
   'H=...
define command {
  command_name   check_memcached
  command_line   $USER1$/check_memkey.pl
    -H $HOSTADDRESS$ 
    -p 11...
$ sudo yum install net-snmp net-snmp-perl 
                   rrdtool rrdtool-perl

$   git clone git://github.com/kazebur...
#
$ cp cloudforecast_sample.yaml cloudforecast.yaml

#
$ cat server_list.yaml
--- #Memcached
servers:
 - config: memcached...
# Web      port 5000   Listen
$ ./cloudforecast_web -p 5000 
         -c cloudforecast.yaml -l server_list.yaml


#       ...
STAT   1:chunk_size 80            STAT   2:cmd_set 34606948
STAT   1:chunks_per_page 13107    STAT   2:delete_hits 19083
S...
STAT   items:1:number 3               STAT   items:3:number 1541997
STAT   items:1:age 7841268            STAT   items:3:a...
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
gumiStudy#2 実践 memcached
Upcoming SlideShare
Loading in …5
×

gumiStudy#2 実践 memcached

1,554
-1

Published on

memcachedは既に多くのWebサービスやソーシャルアプリで利用されスケーラビリティの向上に役立っています。さらに効率よく安全にmemcachedを運用するための実践的なテクニックを紹介します

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,554
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
34
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide





















































































  • gumiStudy#2 実践 memcached

    1. 1. my $memd = Cache::Memcached::Fast->new({ servers => [qw!192.168.67.31:11211 192.168.67.32:11211!] }); if ( my $nickname = $memd->get('nickname:1') ) { return $nickname; } my $dbh = DBI->connect('DBI:mysql:boofy:host=localhost'); my $nickname = $dbh->selectrow_array( 'SELECT nickname FROM user WHERE id=?', undef, 1); if ( $nickname ) { $memd->add('nickname:1', $nickname, 24*60*60); return $nickname; } return;
    2. 2. % ./memstrike -l localhost -p 11211 -t 10 -k 8 -v 8 50000 number of threads : 10 number of requests : 50000 requests per thread : 5000 get multiplex : 1 size of key : 8 bytes size of value : 8 bytes ---- [gggggggggg] ... 0.683260 sec 0.762939 MB 9.366859 Mbps 73178.585019 req/sec 13.665200 usec/req
    3. 3. VS
    4. 4. VS
    5. 5. memcached ×
    6. 6. % sudo ./memcached -c 262144 -u nobody
    7. 7. 4532 int maxfiles = settings.maxconns; 4533 if (rlim.rlim_cur < maxfiles) 4534 rlim.rlim_cur = maxfiles; 4535 if (rlim.rlim_max < rlim.rlim_cur) 4536 rlim.rlim_max = rlim.rlim_cur; 4537 if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) { 4538 fprintf(stderr, "failed to set rlimit for open files. Try running as root or requesting smaller maxconns value.n"); 4539 exit(EX_OSERR); 4540 }
    8. 8. % ./memcached -l 127.0.0.1 % ./memcached -l 192.168.67.31
    9. 9. % ./memcached -l 192.168.67.31 .. % ssh myserver % telnet localhost 11211 Trying ::1... Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused
    10. 10. % sudo ./memcached -c 262144 -u nobody
    11. 11. % ./memcached -vvv slab class 1: chunk size 96 perslab 10922 slab class 40: chunk size 1048576 perslab 1 <26 server listening (auto-negotiate) <27 server listening (auto-negotiate) <28 send buffer was 124928, now 268435456 <28 server listening (udp) <28 server listening (udp) <28 server listening (udp) <28 server listening (udp) <29 send buffer was 124928, now 268435456 <29 server listening (udp) <29 server listening (udp) <29 server listening (udp) <29 server listening (udp)
    12. 12. % ./memcached -p 11211 -U 0
    13. 13. % ./memcached -U 0 % ./memcached -U 12345
    14. 14. % ./memcached -m 16G
    15. 15. % ./memcached -C -m 16G
    16. 16. % ./memcached -c 32768 -u nobody -C -m 16G -p 11211 -U 0
    17. 17. % telnet localhost 11211 Trying ::1... Connected to localhost. Escape character is '^]'. stats settings STAT maxbytes 16777216 STAT maxconns 32768 STAT tcpport 11211 STAT udpport 0 STAT inter NULL STAT verbosity 0 STAT oldest 0 STAT evictions on STAT growth_factor 1.25 STAT chunk_size 48 STAT num_threads 4 STAT cas_enabled no STAT tcp_backlog 4096 STAT binding_protocol auto-negotiate STAT auth_enabled_sasl no STAT item_size_max 1048576 END
    18. 18. define host{ use generic-host host_name memserver alias memserver address 192.168.67.30 } define service{ use generic-service host_name memserver service_description memcached check_command check_memcached } define command { command_name check_memcached command_line ... }
    19. 19. define command { command_name check_memcached command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p 11211 -t 5 }
    20. 20. define command { command_name check_memcached command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p 11211 -t 5 -s 'statsrnquitrn' -E -e 'uptime' -M crit }
    21. 21. stats STAT decr_misses 0 STAT pid 4825 STAT decr_hits 0 STAT uptime 7842604 STAT cas_misses 0 STAT time 1284432055 STAT cas_hits 0 STAT version 1.4.4 STAT cas_badval 0 STAT pointer_size 32 STAT auth_cmds 0 STAT rusage_user 23623.394698 STAT auth_errors 0 STAT rusage_system 31550.652571 STAT bytes_read 219935315170 STAT curr_connections 1243 STAT bytes_written 788448026716 STAT total_connections 30886226 STAT limit_maxbytes 1073741824 STAT connection_structures 1373 STAT accepting_conns 1 STAT cmd_get 730786415 STAT listen_disabled_num 0 STAT cmd_set 345660130 STAT threads 4 STAT cmd_flush 0 STAT conn_yields 146 STAT get_hits 455135951 STAT bytes 740742845 STAT get_misses 275650464 STAT curr_items 3623646 STAT delete_misses 17887026 STAT total_items 347251509 STAT delete_hits 10283848 STAT evictions 6986784 STAT incr_misses 4281893 END STAT incr_hits 111734935
    22. 22. #!/usr/local/bin/activeperl use strict; use warnings; use Getopt::Long; use IO::Socket::INET; GetOptions( 'H=s' => my $HOST, 'p=s' => my $PORT, 'k=s' => my $KEY ); my $sock = IO::Socket::INET->new( PeerAddr => $HOST, PeerPort => $PORT ); if ( !$sock ) { print "Couldnt connect to $HOST:$PORT: $!n"; exit(3); } $sock->syswrite("get $KEYrn"); $sock->sysread( my $result, 16 ); if ( $result =~ m!^VALUE! ) { exit(0); #OK } print "Not found $KEY on $HOST:$PORTn"; exit(2);
    23. 23. define command { command_name check_memcached command_line $USER1$/check_memkey.pl -H $HOSTADDRESS$ -p 11211 -k dankogai }
    24. 24. $ sudo yum install net-snmp net-snmp-perl rrdtool rrdtool-perl $ git clone git://github.com/kazeburo/cloudforecast.git $ cd cloudforecast $ curl -L -o cpanm http://cpanmin.us/ $ chmod u+x cpanm $ ./cpanm -l extlib --installdeps .
    25. 25. # $ cp cloudforecast_sample.yaml cloudforecast.yaml # $ cat server_list.yaml --- #Memcached servers: - config: memcached.yaml hosts: - 192.168.67.30 memserver memcached server - 192.168.67.31 memserver memcached server # $ cat host_config/memcached.yaml resources: - traffic:eth1 - basic - memcached:11211
    26. 26. # Web port 5000 Listen $ ./cloudforecast_web -p 5000 -c cloudforecast.yaml -l server_list.yaml # 5 $ ./cloudforecast_radar -c cloudforecast.yaml -l server_list.yaml
    27. 27. STAT 1:chunk_size 80 STAT 2:cmd_set 34606948 STAT 1:chunks_per_page 13107 STAT 2:delete_hits 19083 STAT 1:total_pages 1 STAT 2:incr_hits 283422 STAT 1:total_chunks 13107 STAT 2:decr_hits 0 STAT 1:used_chunks 3 STAT 2:cas_hits 0 STAT 1:free_chunks 32 STAT 2:cas_badval 0 STAT 1:free_chunks_end 13072 .. STAT 1:mem_requested 220 STAT 42:chunk_size 1048576 STAT 1:get_hits 4438 STAT 42:chunks_per_page 1 STAT 1:cmd_set 11998 STAT 42:total_pages 1 STAT 1:delete_hits 0 STAT 42:total_chunks 1 STAT 1:incr_hits 0 STAT 42:used_chunks 1 STAT 1:decr_hits 0 STAT 42:free_chunks 0 STAT 1:cas_hits 0 STAT 42:free_chunks_end 0 STAT 1:cas_badval 0 STAT 42:mem_requested 779480 STAT 2:chunk_size 104 STAT 42:get_hits 81 STAT 2:chunks_per_page 10082 STAT 42:cmd_set 665 STAT 2:total_pages 16 STAT 42:delete_hits 0 STAT 2:total_chunks 161312 STAT 42:incr_hits 0 STAT 2:used_chunks 116168 STAT 42:decr_hits 0 STAT 2:free_chunks 45144 STAT 42:cas_hits 0 STAT 2:free_chunks_end 0 STAT 42:cas_badval 0 STAT 2:mem_requested 11573385 STAT active_slabs 40 STAT 2:get_hits 29690676 STAT total_malloced 1073454184
    28. 28. STAT items:1:number 3 STAT items:3:number 1541997 STAT items:1:age 7841268 STAT items:3:age 6285649 STAT items:1:evicted 0 STAT items:3:evicted 2546432 STAT items:1:evicted_nonzero 0 STAT items:3:evicted_nonzero 0 STAT items:1:evicted_time 0 STAT items:3:evicted_time 1557089 STAT items:1:outofmemory 0 STAT items:3:outofmemory 0 STAT items:1:tailrepairs 0 STAT items:3:tailrepairs 0 STAT items:2:number 116210 ... STAT items:2:age 6150456 STAT items:42:number 1 STAT items:2:evicted 269 STAT items:42:age 7834430 STAT items:2:evicted_nonzero 0 STAT items:42:evicted 0 STAT items:2:evicted_time 1594950 STAT items:42:evicted_nonzero 0 STAT items:2:outofmemory 0 STAT items:42:evicted_time 0 STAT items:2:tailrepairs 0 STAT items:42:outofmemory 0 STAT items:42:tailrepairs 0
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×