SlideShare a Scribd company logo
1 of 30
Download to read offline
Tricking out
                     your
                 Memcached
                    Setup



Wednesday, July 28, 2010
Chaos Factor
Wednesday, July 28, 2010
ASCII Protocol
                     [brian@gaz libmemcached]$ memcp foo --servers=localhost
                     [brian@gaz libmemcached]$ telnet localhost 11211
                     Trying 127.0.0.1...
                     Connected to localhost.
                     Escape character is '^]'.
                     get foo
                     VALUE foo 0 4
                     bar

                     END
                     version
                     VERSION 1.4.5




Wednesday, July 28, 2010
Binary Protocol
                            MAGIC          Opcode              Key Length
                             (1 byte)       (1 byte)             (2 bytes)

                           Extra Length       Data Type           Reserved
                               (1 byte)           (1 byte)           (2 bytes)

                                           Total Body Length
                                                   (4 bytes)

                                                 Opaque
                                                   (4 bytes)

                                        CAS (Compare and Swap)
                                                   (8 bytes)




Wednesday, July 28, 2010
Pipelining!

                           GET FOO      GET DOG    GET HELP



                                        PACKET




Wednesday, July 28, 2010
New Record




                                       Item goes into nearest node




                           Consistent Hashing
Wednesday, July 28, 2010
libhashkit

                    • One_at_a_time
                    • MD5
                    • HSIES (patents anyone?)
                    • CRC
                    • murmur (pretty simple)

Wednesday, July 28, 2010
Replica
                                  Node:       Node:
                                   B           C
                       Node:
                        A

                                                      Node:
                                                       D

                                  Store:
                               Shopping_key




Wednesday, July 28, 2010
Replica
                                  Node:       Node:
                                   B           C
                       Node:
                        A

                                                      Node:
                                                       D

                                   GET:
                               Shopping_key




Wednesday, July 28, 2010
STAT!

                    • memstat --servers=localhost “args”
                     • slab
                     • items
                     • sizes

Wednesday, July 28, 2010
slab
                           STAT   1:chunk_size 104
                           STAT   1:chunks_per_page 10082
                           STAT   1:total_pages 1
                           STAT   1:total_chunks 10082
                           STAT   1:used_chunks 10081
                           STAT   1:free_chunks 1
                           STAT   1:free_chunks_end 10079
                           STAT   9:chunk_size 696
                           STAT   9:chunks_per_page 1506
                           STAT   9:total_pages 63
                           STAT   9:total_chunks 94878
                           STAT   9:used_chunks 94878
                           STAT   9:free_chunks 0
                           STAT   9:free_chunks_end 0
                           STAT   active_slabs 2
                           STAT   total_malloced 67083616
                           END



Wednesday, July 28, 2010
items
                           STAT   items:2:number 1
                           STAT   items:2:age 452
                           STAT   items:2:evicted 0
                           STAT   items:2:evicted_nonzero 0
                           STAT   items:2:evicted_time 2
                           STAT   items:2:outofmemory 0
                           STAT   items:2:tailrepairs 0
                           ...
                           STAT   items:27:number 1
                           STAT   items:27:age 452
                           STAT   items:27:evicted 0
                           STAT   items:27:evicted_nonzero 0
                           STAT   items:27:evicted_time 2
                           STAT   items:27:outofmemory 0
                           STAT   items:27:tailrepairs 0




Wednesday, July 28, 2010
sizes
                           96 35
                           128 38
                           160 807
                           192 804
                           224 410
                           256 222
                           288 83
                           320 39
                           352 53
                           384 33
                           416 64
                           448 51
                           480 30
                           512 54
                           544 39
                           576 10065




Wednesday, July 28, 2010
Dump your data?

                    • memdump
                    • memcached_dump(memcached_st *ptr,
                           memcached_dump_fn *function, void
                           *context, uint32_t number_of_callbacks);




Wednesday, July 28, 2010
Drain
                           for (items= memdump())
                           {
                             store(items);
                             memcached_delete();
                           }



Wednesday, July 28, 2010
libmemcachedutil

                    • libmemcached_util_ping();
                    • libmemcached_util_version_check();
                    • memcached_pool_st


Wednesday, July 28, 2010
memcached_pool_st* pool= memcached_pool_create(memc, 5, 10);
                memcached_st* mmc[10];

              for (size_t x= 0; x < 10; ++x)
              {
                mmc[x]= memcached_pool_pop(pool, false, &rc);
                …;
              }
              memcached_pool_push(pool, mmc[x])




Wednesday, July 28, 2010
...and now for
                              databases


Wednesday, July 28, 2010
Wednesday, July 28, 2010
Setting via SELECT
          select id, url, memc_set(concat('feeds', md5(url)), url) from feeds;

          select memc_get(concat('feeds', md5(url))) from feeds;
          +-------------------------------------------------------+
          | memc_get(concat('feeds', md5(url)))                   |
          +-------------------------------------------------------+
          | http://feeds.feedburner.com/littlegreenfootballs/Ilds |
          | http://del.icio.us/rss/jacomien                       |
          | http://del.icio.us/rss/tags/rmj20                     |
          | http://www.jihadwatch.org/index.rdf                   |
          | http://www.connotea.org/rss/user/rmj20                |
          | http://devblog.grazr.com/?feed=rss2x                  |
          | http://feeds.feedburner.com/littlegreenfootballs/kyeH |
          +-------------------------------------------------------+




Wednesday, July 28, 2010
Trigger
         DROP TRIGGER IF EXISTS feed_insert;
         CREATE TRIGGER feed_insert BEFORE INSERT ON feeds FOR EACH ROW
         BEGIN   SET @mm= memc_set(concat('feeds:',md5(NEW.url)),
         NEW.url);END |


         insert into feeds (url) values ('http://grazr.com/feedlist.xml');

         select memc_get(concat('feeds:', md5('http://grazr.com/feedlist.xml')));
         +------------------------------------------------------------------+|
         memc_get(concat('feeds:', md5('http://grazr.com/feedlist.xml'))) |
         +------------------------------------------------------------------+|
         http://grazr.com/feedlist.xml                                    |
         +------------------------------------------------------------------+




Wednesday, July 28, 2010
Memcached Replication
                     via MySQL

                 INSERT INTO table_a VALUES (“key”, “value”, “values”);
                 INSERT INTO blackhole_table VALUES (memc_delete(“key”));




Wednesday, July 28, 2010
drizzle> select table_name
               -> from information_schema.tables
               -> where table_name like '%MEMCACHED%';
           +--------------------+
           | table_name          |
           +--------------------+
           | MEMCACHED_STATS     |
           | MEMCACHED_ANALYSIS |
           +--------------------+
           2 rows in set (0 sec)




Wednesday, July 28, 2010
drizzle> desc information_schema.memcached_stats;
                       +-----------------------+-------------+------+-----+---------+-------+
                       | Field                 | Type        | Null | Key | Default | Extra |
                       +-----------------------+-------------+------+-----+---------+-------+
                       | NAME                  | varchar(32) | NO   |     |         |       |
                       | PORT_NUMBER           | bigint      | NO   |     | 0       |       |
                       | PROCESS_ID            | bigint      | NO   |     | 0       |       |
                       | UPTIME                | bigint      | NO   |     | 0       |       |
                       | TIME                  | bigint      | NO   |     | 0       |       |
                       | VERSION               | varchar(8) | NO    |     |         |       |
                       | POINTER_SIZE          | bigint      | NO   |     | 0       |       |
                       | RUSAGE_USER           | bigint      | NO   |     | 0       |       |
                       | RUSAGE_SYSTEM         | bigint      | NO   |     | 0       |       |
                       | CURRENT_ITEMS         | bigint      | NO   |     | 0       |       |




Wednesday, July 28, 2010
drizzle> desc information_schema.memcached_analysis;
              +--------------------------------+-------------+------+-----+---------+-------+
              | Field                          | Type        | Null | Key | Default | Extra |
              +--------------------------------+-------------+------+-----+---------+-------+
              | SERVERS_ANALYZED               | bigint      | NO   |     | 0       |       |
              | AVERAGE_ITEM_SIZE              | bigint      | NO   |     | 0       |       |
              | NODE_WITH_MOST_MEM_CONSUMPTION | varchar(32) | NO   |     |         |       |
              | USED_BYTES                     | bigint      | NO   |     | 0       |       |
              | NODE_WITH_LEAST_FREE_SPACE     | varchar(32) | NO   |     |         |       |
              | FREE_BYTES                     | bigint      | NO   |     | 0       |       |
              | NODE_WITH_LONGEST_UPTIME       | varchar(32) | NO   |     |         |       |
              | LONGEST_UPTIME                 | bigint      | NO   |     | 0       |       |
              | POOL_WIDE_HIT_RATIO            | bigint      | NO   |     | 0       |       |
              +--------------------------------+-------------+------+-----+---------+-------+




Wednesday, July 28, 2010
libmemcachedprotocol


                    • Ascii
                    • Binary


Wednesday, July 28, 2010
memcached_binary_protocol_callback_st interface_v1_impl= {
                    .interface_version= MEMCACHED_PROTOCOL_HANDLER_V1,
                    .interface.v1= {
                      .add= add_handler,
                      .append= append_handler,
                      .decrement= decrement_handler,
                      .delete= delete_handler,
                      .flush= flush_handler,
                      .get= get_handler,
                      .increment= increment_handler,
                      .noop= noop_handler,
                      .prepend= prepend_handler,
                      .quit= quit_handler,
                      .replace= replace_handler,
                      .set= set_handler,
                      .stat= stat_handler,
                      .version= version_handler
                    }
                  };



Wednesday, July 28, 2010
./examples/memcached_light
             (everyone needs their own persistent Memcached server)




Wednesday, July 28, 2010
Examples!


                    • tests/mem_functions.c
                    • man “libmemcached_examples”


Wednesday, July 28, 2010
Brian Aker (brian.aker@datadifferential.com)
          twitter:brianaker
          url: Krow.net




                                          http://DataDifferential.com



Wednesday, July 28, 2010

More Related Content

More from Brian Aker

Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyBrian Aker
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyBrian Aker
 
Gearman, from the worker's perspective
Gearman, from the worker's perspectiveGearman, from the worker's perspective
Gearman, from the worker's perspectiveBrian Aker
 
Drizzle Keynote from O'Reilly's MySQL's Conference
Drizzle Keynote from O'Reilly's MySQL's ConferenceDrizzle Keynote from O'Reilly's MySQL's Conference
Drizzle Keynote from O'Reilly's MySQL's ConferenceBrian Aker
 
Drizzle 7.0, Future of Virtualizing
Drizzle 7.0, Future of VirtualizingDrizzle 7.0, Future of Virtualizing
Drizzle 7.0, Future of VirtualizingBrian Aker
 
Drizzle Keynote at the MySQL User's Conference
Drizzle Keynote at the MySQL User's ConferenceDrizzle Keynote at the MySQL User's Conference
Drizzle Keynote at the MySQL User's ConferenceBrian Aker
 
Drizzle @OpenSQL Camp
Drizzle @OpenSQL CampDrizzle @OpenSQL Camp
Drizzle @OpenSQL CampBrian Aker
 

More from Brian Aker (9)

Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
 
Gearman, from the worker's perspective
Gearman, from the worker's perspectiveGearman, from the worker's perspective
Gearman, from the worker's perspective
 
Drizzle Keynote from O'Reilly's MySQL's Conference
Drizzle Keynote from O'Reilly's MySQL's ConferenceDrizzle Keynote from O'Reilly's MySQL's Conference
Drizzle Keynote from O'Reilly's MySQL's Conference
 
Drizzle 7.0, Future of Virtualizing
Drizzle 7.0, Future of VirtualizingDrizzle 7.0, Future of Virtualizing
Drizzle 7.0, Future of Virtualizing
 
Drizzle Keynote at the MySQL User's Conference
Drizzle Keynote at the MySQL User's ConferenceDrizzle Keynote at the MySQL User's Conference
Drizzle Keynote at the MySQL User's Conference
 
Drizzle @OpenSQL Camp
Drizzle @OpenSQL CampDrizzle @OpenSQL Camp
Drizzle @OpenSQL Camp
 
No SQL Talk
No SQL TalkNo SQL Talk
No SQL Talk
 
Drizzle Talk
Drizzle TalkDrizzle Talk
Drizzle Talk
 

Recently uploaded

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Tricking out your Memcached Setup

  • 1. Tricking out your Memcached Setup Wednesday, July 28, 2010
  • 3. ASCII Protocol [brian@gaz libmemcached]$ memcp foo --servers=localhost [brian@gaz libmemcached]$ telnet localhost 11211 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. get foo VALUE foo 0 4 bar END version VERSION 1.4.5 Wednesday, July 28, 2010
  • 4. Binary Protocol MAGIC Opcode Key Length (1 byte) (1 byte) (2 bytes) Extra Length Data Type Reserved (1 byte) (1 byte) (2 bytes) Total Body Length (4 bytes) Opaque (4 bytes) CAS (Compare and Swap) (8 bytes) Wednesday, July 28, 2010
  • 5. Pipelining! GET FOO GET DOG GET HELP PACKET Wednesday, July 28, 2010
  • 6. New Record Item goes into nearest node Consistent Hashing Wednesday, July 28, 2010
  • 7. libhashkit • One_at_a_time • MD5 • HSIES (patents anyone?) • CRC • murmur (pretty simple) Wednesday, July 28, 2010
  • 8. Replica Node: Node: B C Node: A Node: D Store: Shopping_key Wednesday, July 28, 2010
  • 9. Replica Node: Node: B C Node: A Node: D GET: Shopping_key Wednesday, July 28, 2010
  • 10. STAT! • memstat --servers=localhost “args” • slab • items • sizes Wednesday, July 28, 2010
  • 11. slab STAT 1:chunk_size 104 STAT 1:chunks_per_page 10082 STAT 1:total_pages 1 STAT 1:total_chunks 10082 STAT 1:used_chunks 10081 STAT 1:free_chunks 1 STAT 1:free_chunks_end 10079 STAT 9:chunk_size 696 STAT 9:chunks_per_page 1506 STAT 9:total_pages 63 STAT 9:total_chunks 94878 STAT 9:used_chunks 94878 STAT 9:free_chunks 0 STAT 9:free_chunks_end 0 STAT active_slabs 2 STAT total_malloced 67083616 END Wednesday, July 28, 2010
  • 12. items STAT items:2:number 1 STAT items:2:age 452 STAT items:2:evicted 0 STAT items:2:evicted_nonzero 0 STAT items:2:evicted_time 2 STAT items:2:outofmemory 0 STAT items:2:tailrepairs 0 ... STAT items:27:number 1 STAT items:27:age 452 STAT items:27:evicted 0 STAT items:27:evicted_nonzero 0 STAT items:27:evicted_time 2 STAT items:27:outofmemory 0 STAT items:27:tailrepairs 0 Wednesday, July 28, 2010
  • 13. sizes 96 35 128 38 160 807 192 804 224 410 256 222 288 83 320 39 352 53 384 33 416 64 448 51 480 30 512 54 544 39 576 10065 Wednesday, July 28, 2010
  • 14. Dump your data? • memdump • memcached_dump(memcached_st *ptr, memcached_dump_fn *function, void *context, uint32_t number_of_callbacks); Wednesday, July 28, 2010
  • 15. Drain for (items= memdump()) { store(items); memcached_delete(); } Wednesday, July 28, 2010
  • 16. libmemcachedutil • libmemcached_util_ping(); • libmemcached_util_version_check(); • memcached_pool_st Wednesday, July 28, 2010
  • 17. memcached_pool_st* pool= memcached_pool_create(memc, 5, 10); memcached_st* mmc[10]; for (size_t x= 0; x < 10; ++x) { mmc[x]= memcached_pool_pop(pool, false, &rc); …; } memcached_pool_push(pool, mmc[x]) Wednesday, July 28, 2010
  • 18. ...and now for databases Wednesday, July 28, 2010
  • 20. Setting via SELECT select id, url, memc_set(concat('feeds', md5(url)), url) from feeds; select memc_get(concat('feeds', md5(url))) from feeds; +-------------------------------------------------------+ | memc_get(concat('feeds', md5(url))) | +-------------------------------------------------------+ | http://feeds.feedburner.com/littlegreenfootballs/Ilds | | http://del.icio.us/rss/jacomien | | http://del.icio.us/rss/tags/rmj20 | | http://www.jihadwatch.org/index.rdf | | http://www.connotea.org/rss/user/rmj20 | | http://devblog.grazr.com/?feed=rss2x | | http://feeds.feedburner.com/littlegreenfootballs/kyeH | +-------------------------------------------------------+ Wednesday, July 28, 2010
  • 21. Trigger DROP TRIGGER IF EXISTS feed_insert; CREATE TRIGGER feed_insert BEFORE INSERT ON feeds FOR EACH ROW BEGIN SET @mm= memc_set(concat('feeds:',md5(NEW.url)), NEW.url);END | insert into feeds (url) values ('http://grazr.com/feedlist.xml'); select memc_get(concat('feeds:', md5('http://grazr.com/feedlist.xml'))); +------------------------------------------------------------------+| memc_get(concat('feeds:', md5('http://grazr.com/feedlist.xml'))) | +------------------------------------------------------------------+| http://grazr.com/feedlist.xml | +------------------------------------------------------------------+ Wednesday, July 28, 2010
  • 22. Memcached Replication via MySQL INSERT INTO table_a VALUES (“key”, “value”, “values”); INSERT INTO blackhole_table VALUES (memc_delete(“key”)); Wednesday, July 28, 2010
  • 23. drizzle> select table_name -> from information_schema.tables -> where table_name like '%MEMCACHED%'; +--------------------+ | table_name | +--------------------+ | MEMCACHED_STATS | | MEMCACHED_ANALYSIS | +--------------------+ 2 rows in set (0 sec) Wednesday, July 28, 2010
  • 24. drizzle> desc information_schema.memcached_stats; +-----------------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+-------------+------+-----+---------+-------+ | NAME | varchar(32) | NO | | | | | PORT_NUMBER | bigint | NO | | 0 | | | PROCESS_ID | bigint | NO | | 0 | | | UPTIME | bigint | NO | | 0 | | | TIME | bigint | NO | | 0 | | | VERSION | varchar(8) | NO | | | | | POINTER_SIZE | bigint | NO | | 0 | | | RUSAGE_USER | bigint | NO | | 0 | | | RUSAGE_SYSTEM | bigint | NO | | 0 | | | CURRENT_ITEMS | bigint | NO | | 0 | | Wednesday, July 28, 2010
  • 25. drizzle> desc information_schema.memcached_analysis; +--------------------------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------------------------+-------------+------+-----+---------+-------+ | SERVERS_ANALYZED | bigint | NO | | 0 | | | AVERAGE_ITEM_SIZE | bigint | NO | | 0 | | | NODE_WITH_MOST_MEM_CONSUMPTION | varchar(32) | NO | | | | | USED_BYTES | bigint | NO | | 0 | | | NODE_WITH_LEAST_FREE_SPACE | varchar(32) | NO | | | | | FREE_BYTES | bigint | NO | | 0 | | | NODE_WITH_LONGEST_UPTIME | varchar(32) | NO | | | | | LONGEST_UPTIME | bigint | NO | | 0 | | | POOL_WIDE_HIT_RATIO | bigint | NO | | 0 | | +--------------------------------+-------------+------+-----+---------+-------+ Wednesday, July 28, 2010
  • 26. libmemcachedprotocol • Ascii • Binary Wednesday, July 28, 2010
  • 27. memcached_binary_protocol_callback_st interface_v1_impl= { .interface_version= MEMCACHED_PROTOCOL_HANDLER_V1, .interface.v1= { .add= add_handler, .append= append_handler, .decrement= decrement_handler, .delete= delete_handler, .flush= flush_handler, .get= get_handler, .increment= increment_handler, .noop= noop_handler, .prepend= prepend_handler, .quit= quit_handler, .replace= replace_handler, .set= set_handler, .stat= stat_handler, .version= version_handler } }; Wednesday, July 28, 2010
  • 28. ./examples/memcached_light (everyone needs their own persistent Memcached server) Wednesday, July 28, 2010
  • 29. Examples! • tests/mem_functions.c • man “libmemcached_examples” Wednesday, July 28, 2010
  • 30. Brian Aker (brian.aker@datadifferential.com) twitter:brianaker url: Krow.net http://DataDifferential.com Wednesday, July 28, 2010