Slide 1

Slide 1 text

Chat to memcached by “memcached-cli” @key_amb In Gotanda.pm #8

Slide 2

Slide 2 text

Who am I ? ❏ @key_amb ❏ Software Engineer ❏ Serverside, Web ❏ https://github.com/key-amb ❏ https://metacpan.org/author/KEYAMB

Slide 3

Slide 3 text

Overview of “memcached-cli” ❏ https://github.com/key-amb/perl5-App- Memcached-CLI ❏ `cpanm App::Memcached::CLI` to install ❏ Interactive and Batch interface ❏ Based on Memcached Text Protocol ❏ Covers ALL commands described in memcached/protocol.txt ❏ And More!

Slide 4

Slide 4 text

Motivation ● Do you remember how to “set” a data into Memcached? ● Do you know the way to investigate when there are evictions on Memcached?

Slide 5

Slide 5 text

“set” by telnet is difficult % telnet localhost 11211 ...Escape character is ‘^]’ set foo 0 0 3 Foo STORED get foo VALUE foo 0 3 Foo END

Slide 6

Slide 6 text

When evictions detected 1. `memcached-tool SERVER:PORT` to check in which class evictions are. 2. `stats cachedump CLASS NUM` via telnet to see keys and expiration time 3. `get KEY` to see data value 4. And so on. … Needs some efforts.

Slide 7

Slide 7 text

In “memcached-cli” ● Interactive, friendly Interface. ● So powerfull that it covers most commands of Memcached. ● Useful features for Ops and Admin.

Slide 8

Slide 8 text

Run “memcached-cli” // Interactive Mode % memcached-cli [localhost] Type '\h' or 'help' to show help. [email protected]:11211> \q // quit // Batch mode % memcached-cli get foo bar Key:foo Value:Foo Length:3B Flags:0 Key:bar Value:Bar Length:3B Flags:0

Slide 9

Slide 9 text

Basic Commands

Slide 10

Slide 10 text

get, gets [email protected]:11211> gets bar key: bar value: Bar length: 3B flags: 0 cas: 2 [email protected]:11211> get foo baz Key:foo Value:Foo Length:3B Flags:0 Key:baz Value:Baz Length:3B Flags:0

Slide 11

Slide 11 text

set, add, replace memcached@~> set foo Foo OK memcached@~> add foo Whooah! Failed to add item. KEY foo, VALUE Whooah! memcached@~> replace foo Hoohoo. OK memcached@~> get foo key: foo value: Hoohoo. length: 7B flags: 0

Slide 12

Slide 12 text

Other data manipulation commands ❏ append, prepend … add prefix/suffix to data ❏ cas … check-and-set for transaction ❏ touch … update expiration time ❏ incr, decr … add or reduce numeric data value ❏ delete … remove data

Slide 13

Slide 13 text

Stats Commands

Slide 14

Slide 14 text

What is “stats” commands? ❏ Built-in Memcached commands to get server internal statistics ❏ stats … general statistics ❏ stats … various stats ❏ settings … server settings ❏ items … number / eviction / expire, etc. ❏ slabs … chunk / page / memory used ❏ conns … state / peer addr of active connections ❏ cachedump … sample some data of a slab ❏ sizes … item count per size ※Hold Lock ❏ detail … get / hit / set / del stats per namespace

Slide 15

Slide 15 text

display(\d) <= memcached-tool “stats items + stats slabs” [email protected]:11211> \d # Item_Size Max_age Pages Count Full? Evicted Evict_Time OOM 1 96B 242s 1 387 yes 0 0 0 2 120B 242s 1 651 yes 0 0 0 3 152B 242s 1 903 yes 0 0 0 4 192B 242s 1 1104 yes 0 0 0 5 240B 242s 1 1372 yes 0 0 0 6 304B 242s 1 1739 yes 0 0 0 7 384B 242s 1 1845 yes 0 0 0 : 31 80.9K 135s 1 12 yes 6 1 0 32 101.1K 134s 1 10 yes 16 0 0 33 126.3K 134s 1 8 yes 21 0 0 34 157.9K 134s 1 6 yes 33 0 0

Slide 16

Slide 16 text

cachedump (RAW) memcached@~> call stats cachedump 1 6 ITEM piyo [4 b; 1459330139 s] ITEM fuga [4 b; 1459330139 s] ITEM hoge [4 b; 1459330139 s] ITEM baz [3 b; 1459330139 s] ITEM bar [3 b; 1459330139 s] ITEM foo [3 b; 1459330139 s] END

Slide 17

Slide 17 text

cachedump(\cd) in “memcached-cli” memcached@~> \cd 1 Key:piyo Value:Piyo Length:4B Expire:2016-03-30 18:28:59 Flags:0 Cas:1106 Key:baz Value:Baz Length:3B Expire:2016-03-30 18: 28:59 Flags:0 Cas:1103 Key:fuga Value:Fuga Length:4B Expire:2016-03-30 18:28:59 Flags:0 Cas:1105 Key:bar Value:Bar Length:3B Expire:2016-03-30 18: 28:59 Flags:0 Cas:1102 Key:foo Value:Foo Length:3B Expire:2016-03-30 18: 28:59 Flags:0 Cas:1101 Key:hoge Value:Hoge Length:4B Expire:2016-03-30 18:28:59 Flags:0 Cas:1104

Slide 18

Slide 18 text

Other Features

Slide 19

Slide 19 text

Other Commands & Features ❏ randomset … random data generator ❏ dump_all / restore_dump … dump / restore whole data in server ❏ call [] … execute any command to server ❏ Term::ReadLine … support command history

Slide 20

Slide 20 text

DEMO

Slide 21

Slide 21 text

Conclusion Enjoy chatting to memcached by “memcached-cli” !!

Slide 22

Slide 22 text

Thank you!

Slide 23

Slide 23 text

Appendix: Related softwares ❏ andrewgross/memcache-cli (Python) ❏ libmemcached#client-apps (C)