Memcached source code Analysis starting from the SET command.

Source: Internet
Author: User
Tags memcached php memcached

Calix

If directly the source of memcached from the main function to say, I am afraid there will be a nod, so here with a classic "SET" command simply open a head, is a recall of the role of memcached, the structure of the later part of the command parsing is mainly around the SET command to expand the analysis , I believe that a set command behind the things to make clear, then memcached most of the source code is known to 7788.

So, recall, what did the set command do?

It is simply a value set to a key above, stored in memory.

Refine it again:

1) memcached is a cache server, we use it often through a client, such as PHP memcached client, or directly on the Linux terminal via Telnet, either way, the first behavior is "establish a connection." (Note that although memcached is a distributed cache server, its real distribution algorithm is implemented on the client side, so the distributed logic is not within the scope of this source analysis.) So, how does memcached handle network requests? Is it a multi-process or asynchronous approach?

2) When the connection is completed, we are sending a set command, for example, after the terminal telnet succeeds, knock down: "Set name 0 0 3\r\n tom\r\n" (This is the memcached set protocol), then memcached how to obtain this command and data, How to parse and what modules to execute after obtaining?

3) After parsing to the set command, know how to save a K-V structure of data to memory, then how does it allocate memory? How can we ensure that the next time we take it, we can get "value" by "key" soon? How do you ensure atomicity and consistency in a concurrency scenario?

With the above question, I have divided the memcached source analysis structure into three main parts:

A) memcached source code Analysis of the threading model

II) memcached Source Analysis request processing (state machine)

c) memory management of memcached source analysis

Reprint Please specify: calix»memcached source analysis from the SET command start speaking

Memcached source code Analysis starting from the SET command.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.