Chat to memcached by "memcached-cli" #memcached

Chat to memcached by "memcached-cli" #memcached

58ee824b00315b969fc893b3eb5f5c38?s=128

YASUTAKE Kiyoshi

March 30, 2016
Tweet

Transcript

  1. 2.

    Who am I ? ❏ @key_amb ❏ Software Engineer ❏

    Serverside, Web ❏ https://github.com/key-amb ❏ https://metacpan.org/author/KEYAMB
  2. 3.

    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!
  3. 4.

    Motivation • Do you remember how to “set” a data

    into Memcached? • Do you know the way to investigate when there are evictions on Memcached?
  4. 5.

    “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
  5. 6.

    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.
  6. 7.

    In “memcached-cli” • Interactive, friendly Interface. • So powerfull that

    it covers most commands of Memcached. • Useful features for Ops and Admin.
  7. 8.

    Run “memcached-cli” // Interactive Mode % memcached-cli [localhost] Type '\h'

    or 'help' to show help. memcached@127.0.0.1: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
  8. 10.

    get, gets memcached@127.0.0.1:11211> gets bar key: bar value: Bar length:

    3B flags: 0 cas: 2 memcached@127.0.0.1:11211> get foo baz Key:foo Value:Foo Length:3B Flags:0 Key:baz Value:Baz Length:3B Flags:0
  9. 11.

    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
  10. 12.

    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
  11. 14.

    What is “stats” commands? ❏ Built-in Memcached commands to get

    server internal statistics ❏ stats … general statistics ❏ stats <args> … 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
  12. 15.

    display(\d) <= memcached-tool “stats items + stats slabs” memcached@127.0.0.1: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
  13. 16.

    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
  14. 17.

    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
  15. 19.

    Other Commands & Features ❏ randomset … random data generator

    ❏ dump_all / restore_dump … dump / restore whole data in server ❏ call <command> [<args>] … execute any command to server ❏ Term::ReadLine … support command history
  16. 20.