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.