init
This commit is contained in:
3
wcmtools/memcached/doc/Makefile.am
Executable file
3
wcmtools/memcached/doc/Makefile.am
Executable file
@@ -0,0 +1,3 @@
|
||||
man_MANS = memcached.1
|
||||
|
||||
EXTRA_DIST = *.txt
|
||||
86
wcmtools/memcached/doc/memcached.1
Executable file
86
wcmtools/memcached/doc/memcached.1
Executable file
@@ -0,0 +1,86 @@
|
||||
.TH MEMCACHED 1 "April 11, 2005"
|
||||
.SH NAME
|
||||
memcached \- high-performance memory object caching system
|
||||
.SH SYNOPSIS
|
||||
.B memcached
|
||||
.RI [ options ]
|
||||
.br
|
||||
.SH DESCRIPTION
|
||||
This manual page documents briefly the
|
||||
.B memcached
|
||||
memory object caching daemon.
|
||||
.PP
|
||||
.B memcached
|
||||
is a flexible memory object caching daemon designed to alleviate database load
|
||||
in dynamic web applications by storing objects in memory. It's based on
|
||||
libevent to scale to any size needed, and is specifically optimized to avoid
|
||||
swapping and always use non-blocking I/O.
|
||||
.br
|
||||
.SH OPTIONS
|
||||
These programs follow the usual GNU command line syntax. A summary of options
|
||||
is included below.
|
||||
.TP
|
||||
.B \-l <ip_addr>
|
||||
Listen on <ip_addr>; default to INDRR_ANY. This is an important option to
|
||||
consider as there is no other way to secure the installation. Binding to an
|
||||
internal or firewalled network interface is suggested.
|
||||
.TP
|
||||
.B \-d
|
||||
Run memcached as a daemon.
|
||||
.TP
|
||||
.B \-u <username>
|
||||
Assume the identity of <username> (only when run as root).
|
||||
.TP
|
||||
.B \-m <num>
|
||||
Use <num> MB memory max to use for object storage; the default is 64 megabytes.
|
||||
.TP
|
||||
.B \-c <num>
|
||||
Use <num> max simultaneous connections; the default is 1024.
|
||||
.TP
|
||||
.B \-k
|
||||
Lock down all paged memory. This is a somewhat dangerous option with large
|
||||
caches, so consult the README and memcached homepage for configuration
|
||||
suggestions.
|
||||
.TP
|
||||
.B \-p <num>
|
||||
Listen on port <num>, the default is port 11211.
|
||||
.TP
|
||||
.B \-M
|
||||
Disable automatic removal of items from the cache when out of memory.
|
||||
Additions will not be possible until adequate space is freed up.
|
||||
.TP
|
||||
.B \-r
|
||||
Raise the core file size limit to the maximum allowable.
|
||||
.TP
|
||||
.B \-h
|
||||
Show the version of memcached and a summary of options.
|
||||
.TP
|
||||
.B \-v
|
||||
Be verbose during the event loop; print out errors and warnings.
|
||||
.TP
|
||||
.B \-vv
|
||||
Be even more verbose; same as \-v but also print client commands and
|
||||
responses.
|
||||
.TP
|
||||
.B \-i
|
||||
Print memcached and libevent licenses.
|
||||
.TP
|
||||
.B \-P <filename>
|
||||
Print pidfile to <filename>, only used under -d option.
|
||||
.br
|
||||
.SH LICENSE
|
||||
The memcached daemon is copyright Danga Interactive and is distributed under
|
||||
the BSD license. Note that daemon clients are licensed separately.
|
||||
.br
|
||||
.SH SEE ALSO
|
||||
The README file that comes with memcached
|
||||
.br
|
||||
.B http://www.danga.com/memcached
|
||||
.SH AUTHOR
|
||||
The memcached daemon was written by Anatoly Vorobey
|
||||
.B <mellon@pobox.com>
|
||||
and Brad Fitzpatrick
|
||||
.B <brad@danga.com>
|
||||
and the rest of the crew of Danga Interactive
|
||||
.B http://www.danga.com
|
||||
.br
|
||||
83
wcmtools/memcached/doc/memory_management.txt
Executable file
83
wcmtools/memcached/doc/memory_management.txt
Executable file
@@ -0,0 +1,83 @@
|
||||
Date: Fri, 5 Sep 2003 20:31:03 +0300
|
||||
From: Anatoly Vorobey <mellon@pobox.com>
|
||||
To: memcached@lists.danga.com
|
||||
Subject: Re: Memory Management...
|
||||
|
||||
On Fri, Sep 05, 2003 at 12:07:48PM -0400, Kyle R. Burton wrote:
|
||||
> prefixing keys with a container identifier). We have just begun to
|
||||
> look at the implementation of the memory management sub-system with
|
||||
> regards to it's allocation, de-allocation and compaction approaches.
|
||||
> Is there any documentation or discussion of how this subsystem
|
||||
> operates? (slabs.c?)
|
||||
|
||||
There's no documentation yet, and it's worth mentioning that this
|
||||
subsystem is the most active area of memcached under development at the
|
||||
moment (however, all the changes to it won't modify the way memcached
|
||||
presents itself towards clients, they're primarily directed at making
|
||||
memcached use memory more efficiently).
|
||||
|
||||
Here's a quick recap of what it does now and what is being worked
|
||||
on.
|
||||
|
||||
The primary goal of the slabs subsystem in memcached was to eliminate
|
||||
memory fragmentation issues totally by using fixed-size memory chunks
|
||||
coming from a few predetermined size classes (early versions of
|
||||
memcached relied on malloc()'s handling of fragmentation which proved
|
||||
woefully inadequate for our purposes). For instance, suppose
|
||||
we decide at the outset that the list of possible sizes is: 64 bytes,
|
||||
128 bytes, 256 bytes, etc. - doubling all the way up to 1Mb. For each
|
||||
size class in this list (each possible size) we maintain a list of free
|
||||
chunks of this size. Whenever a request comes for a particular size,
|
||||
it is rounded up to the closest size class and a free chunk is taken
|
||||
from that size class. In the above example, if you request from the
|
||||
slabs subsystem 100 bytes of memory, you'll actually get a chunk 128
|
||||
bytes worth, from the 128-bytes size class. If there are no free chunks
|
||||
of the needed size at the moment, there are two ways to get one: 1) free
|
||||
an existing chunk in the same size class, using LRU queues to free the
|
||||
least needed objects; 2) get more memory from the system, which we
|
||||
currently always do in _slabs_ of 1Mb each; we malloc() a slab, divide
|
||||
it to chunks of the needed size, and use them.
|
||||
|
||||
The tradeoff is between memory fragmentation and memory utilisation. In
|
||||
the scheme we're now using, we have zero fragmentation, but a relatively
|
||||
high percentage of memory is wasted. The most efficient way to reduce
|
||||
the waste is to use a list of size classes that closely matches (if
|
||||
that's at all possible) common sizes of objects that the clients
|
||||
of this particular installation of memcached are likely to store.
|
||||
For example, if your installation is going to store hundreds of thousands of objects of the size exactly 120 bytes, you'd be much better
|
||||
off changing, in the "naive" list of sizes outlined above, the class
|
||||
of 128 bytes to something a bit higher (because the overhead of
|
||||
storing an item, while not large, will push those 120-bytes objects over
|
||||
128 bytes of storage internally, and will require using 256 bytes for
|
||||
each of them in the naive scheme, forcing you to waste almost 50% of
|
||||
memory). Such tinkering with the list of size classes is not currently
|
||||
possible with memcached, but enabling it is one of the immediate goals.
|
||||
|
||||
Ideally, the slabs subsystem would analyze at runtime the common sizes
|
||||
of objects that are being requested, and would be able to modify the
|
||||
list of sizes dynamically to improve memory utilisation. This is not
|
||||
planned for the immediate future, however. What is planned is the
|
||||
ability to reassign slabs to different classes. Here's what this means.
|
||||
Currently, the total amount of memory allocated for each size class is
|
||||
determined by how clients interact with memcached during the initial
|
||||
phase of its execution, when it keeps malloc()'ing more slabs and
|
||||
dividing them into chunks, until it hits the specified memory limit
|
||||
(say, 2Gb, or whatever else was specified). Once it hits the limit, to
|
||||
allocate a new chunk it'll always delete an existing chunk of the same
|
||||
size (using LRU queues), and will never malloc() or free() any memory
|
||||
from/to the system. So if, for example, during those initial few hours
|
||||
of memcached's execution your clients mainly wanted to store very small
|
||||
items, the bulk of memory allocated will be divided to small-sized
|
||||
chunks, and the large size classes will get fewer memory, therefore the
|
||||
life-cycle of large objects you'll store in memcached will henceforth
|
||||
always be much shorter, with this instance of memcached (their LRU
|
||||
queues will be shorter and they'll be pushed out much more often). In
|
||||
general, if your system starts producing a different pattern of common
|
||||
object sizes, the memcached servers will become less efficient, unless
|
||||
you restart them. Slabs reassignment, which is the next feature being
|
||||
worked on, will ensure the server's ability to reclaim a slab (1Mb of
|
||||
memory) from one size class and put it into another class size, where
|
||||
it's needed more.
|
||||
|
||||
--
|
||||
avva
|
||||
389
wcmtools/memcached/doc/protocol.txt
Executable file
389
wcmtools/memcached/doc/protocol.txt
Executable file
@@ -0,0 +1,389 @@
|
||||
Protocol
|
||||
--------
|
||||
|
||||
Clients of memcached communicate with server through TCP
|
||||
connections. A given running memcached server listens on some
|
||||
(configurable) port; clients connect to that port, send commands to
|
||||
the server, read responses, and eventually close the connection.
|
||||
|
||||
There is no need to send any command to end the session. A client may
|
||||
just close the connection at any moment it no longer needs it. Note,
|
||||
however, that clients are encouraged to cache their connections rather
|
||||
than reopen them every time they need to store or retrieve data. This
|
||||
is because memcached is especially designed to work very efficiently
|
||||
with a very large number (many hundreds, more than a thousand if
|
||||
necessary) of open connections. Caching connections will eliminate the
|
||||
overhead associated with establishing a TCP connection (the overhead
|
||||
of preparing for a new connection on the server side is insignificant
|
||||
compared to this).
|
||||
|
||||
There are two kinds of data sent in the memcache protocol: text lines
|
||||
and unstructured data. Text lines are used for commands from clients
|
||||
and responses from servers. Unstructured data is sent when a client
|
||||
wants to store or retrieve data. The server will transmit back
|
||||
unstructured data in exactly the same way it received it, as a byte
|
||||
stream. The server doesn't care about byte order issues in
|
||||
unstructured data and isn't aware of them. There are no limitations on
|
||||
characters that may appear in unstructured data; however, the reader
|
||||
of such data (either a client or a server) will always know, from a
|
||||
preceding text line, the exact length of the data block being
|
||||
transmitted.
|
||||
|
||||
Text lines are always terminated by \r\n. Unstructured data is _also_
|
||||
terminated by \r\n, even though \r, \n or any other 8-bit characters
|
||||
may also appear inside the data. Therefore, when a client retrieves
|
||||
data from a server, it must use the length of the data block (which it
|
||||
will be provided with) to determine where the data block ends, and not
|
||||
the fact that \r\n follows the end of the data block, even though it
|
||||
does.
|
||||
|
||||
Keys
|
||||
----
|
||||
|
||||
Data stored by memcached is identified with the help of a key. A key
|
||||
is a text string which should uniquely identify the data for clients
|
||||
that are interested in storing and retrieving it. Currently the
|
||||
length limit of a key is set at 250 characters (of course, normally
|
||||
clients wouldn't need to use such long keys); the key must not include
|
||||
control characters or whitespace.
|
||||
|
||||
Commands
|
||||
--------
|
||||
|
||||
There are three types of commands.
|
||||
|
||||
Storage commands (there are three: "set", "add" and "replace") ask the
|
||||
server to store some data identified by a key. The client sends a
|
||||
command line, and then a data block; after that the client expects one
|
||||
line of response, which will indicate success or faulure.
|
||||
|
||||
Retrieval commands (there is only one: "get") ask the server to
|
||||
retrieve data corresponding to a set of keys (one or more keys in one
|
||||
request). The client sends a command line, which includes all the
|
||||
requested keys; after that for each item the server finds it sends to
|
||||
the client one response line with information about the item, and one
|
||||
data block with the item's data; this continues until the server
|
||||
finished with the "END" response line.
|
||||
|
||||
All other commands don't involve unstructured data. In all of them,
|
||||
the client sends one command line, and expects (depending on the
|
||||
command) either one line of response, or several lines of response
|
||||
ending with "END" on the last line.
|
||||
|
||||
A command line always starts with the name of the command, followed by
|
||||
parameters (if any) delimited by whitespace. Command names are
|
||||
lower-case and are case-sensitive.
|
||||
|
||||
Expiration times
|
||||
----------------
|
||||
|
||||
Some commands involve a client sending some kind of expiration time
|
||||
(relative to an item or to an operation requested by the client) to
|
||||
the server. In all such cases, the actual value sent may either be
|
||||
Unix time (number of seconds since January 1, 1970, as a 32-bit
|
||||
value), or a number of seconds starting from current time. In the
|
||||
latter case, this number of seconds may not exceed 60*60*24*30 (number
|
||||
of seconds in 30 days); if the number sent by a client is larger than
|
||||
that, the server will consider it to be real Unix time value rather
|
||||
than an offset from current time.
|
||||
|
||||
|
||||
Error strings
|
||||
-------------
|
||||
|
||||
Each command sent by a client may be answered with an error string
|
||||
from the server. These error strings come in three types:
|
||||
|
||||
- "ERROR\r\n"
|
||||
|
||||
means the client sent a nonexistent command name.
|
||||
|
||||
- "CLIENT_ERROR <error>\r\n"
|
||||
|
||||
means some sort of client error in the input line, i.e. the input
|
||||
doesn't conform to the protocol in some way. <error> is a
|
||||
human-readable error string.
|
||||
|
||||
- "SERVER_ERROR <error>\r\n"
|
||||
|
||||
means some sort of server error prevents the server from carrying
|
||||
out the command. <error> is a human-readable error string. In cases
|
||||
of severe server errors, which make it impossible to continue
|
||||
serving the client (this shouldn't normally happen), the server will
|
||||
close the connection after sending the error line. This is the only
|
||||
case in which the server closes a connection to a client.
|
||||
|
||||
|
||||
In the descriptions of individual commands below, these error lines
|
||||
are not again specifically mentioned, but clients must allow for their
|
||||
possibility.
|
||||
|
||||
|
||||
Storage commands
|
||||
----------------
|
||||
|
||||
First, the client sends a command line which looks like this:
|
||||
|
||||
<command name> <key> <flags> <exptime> <bytes>\r\n
|
||||
|
||||
- <command name> is "set", "add" or "replace"
|
||||
|
||||
"set" means "store this data".
|
||||
|
||||
"add" means "store this data, but only if the server *doesn't* already
|
||||
hold data for this key".
|
||||
|
||||
"replace" means "store this data, but only if the server *does*
|
||||
already hold data for this key".
|
||||
|
||||
- <key> is the key under which the client asks to store the data
|
||||
|
||||
- <flags> is an arbitrary 16-bit unsigned integer (written out in
|
||||
decimal) that the server stores along with the data and sends back
|
||||
when the item is retrieved. Clients may use this as a bit field to
|
||||
store data-specific information; this field is opaque to the server.
|
||||
|
||||
- <exptime> is expiration time. If it's 0, the item never expires
|
||||
(although it may be deleted from the cache to make place for other
|
||||
items). If it's non-zero (either Unix time or offset in seconds from
|
||||
current time), it is guaranteed that clients will not be able to
|
||||
retrieve this item after the expiration time arrives (measured by
|
||||
server time).
|
||||
|
||||
- <bytes> is the number of bytes in the data block to follow, *not*
|
||||
including the delimiting \r\n. <bytes> may be zero (in which case
|
||||
it's followed by an empty data block).
|
||||
|
||||
After this line, the client sends the data block:
|
||||
|
||||
<data block>\r\n
|
||||
|
||||
- <data block> is a chunk of arbitrary 8-bit data of length <bytes>
|
||||
from the previous line.
|
||||
|
||||
After sending the command line and the data blockm the client awaits
|
||||
the reply, which may be:
|
||||
|
||||
- "STORED\r\n", to indicate success.
|
||||
|
||||
- "NOT_STORED\r\n" to indicate the data was not stored, but not
|
||||
because of an error. This normally means that either that the
|
||||
condition for an "add" or a "replace" command wasn't met, or that the
|
||||
item is in a delete queue (see the "delete" command below).
|
||||
|
||||
|
||||
Retrieval command:
|
||||
------------------
|
||||
|
||||
The retrieval command looks like this:
|
||||
|
||||
get <key>*\r\n
|
||||
|
||||
- <key>* means one or more key strings separated by whitespace.
|
||||
|
||||
After this command, the client expects zero or more items, each of
|
||||
which is received as a text line followed by a data block. After all
|
||||
the items have been transmitted, the server sends the string
|
||||
|
||||
"END\r\n"
|
||||
|
||||
to indicate the end of response.
|
||||
|
||||
Each item sent by the server looks like this:
|
||||
|
||||
VALUE <key> <flags> <bytes>\r\n
|
||||
<data block>\r\n
|
||||
|
||||
- <key> is the key for the item being sent
|
||||
|
||||
- <flags> is the flags value set by the storage command
|
||||
|
||||
- <bytes> is the length of the data block to follow, *not* including
|
||||
its delimiting \r\n
|
||||
|
||||
- <data block> is the data for this item.
|
||||
|
||||
If some of the keys appearing in a retrieval request are not sent back
|
||||
by the server in the item list this means that the server does not
|
||||
hold items with such keys (because they were never stored, or stored
|
||||
but deleted to make space for more items, or expired, or explicitly
|
||||
deleted by a client).
|
||||
|
||||
|
||||
|
||||
Deletion
|
||||
--------
|
||||
|
||||
The command "delete" allows for explicit deletion of items:
|
||||
|
||||
delete <key> <time>\r\n
|
||||
|
||||
- <key> is the key of the item the client wishes the server to delete
|
||||
|
||||
- <time> is the amount of time in seconds (or Unix time until which)
|
||||
the client wishes the server to refuse "add" and "replace" commands
|
||||
with this key. For this amount of item, the item is put into a
|
||||
delete queue, which means that it won't possible to retrieve it by
|
||||
the "get" command, but "add" and "replace" command with this key
|
||||
will also fail (the "set" command will succeed, however). After the
|
||||
time passes, the item is finally deleted from server memory.
|
||||
|
||||
The parameter <time> is optional, and, if absent, defaults to 0
|
||||
(which means that the item will be deleted immediately and further
|
||||
storage commands with this key will succeed).
|
||||
|
||||
The response line to this command can be one of:
|
||||
|
||||
- "DELETED\r\n" to indicate success
|
||||
|
||||
- "NOT_FOUND\r\n" to indicate that the item with this key was not
|
||||
found.
|
||||
|
||||
See the "flush_all" command below for immediate invalidation
|
||||
of all existing items.
|
||||
|
||||
|
||||
Increment/Decrement
|
||||
-------------------
|
||||
|
||||
Commands "incr" and "decr" are used to change data for some item
|
||||
in-place, incrementing or decrementing it. The data for the item is
|
||||
treated as decimal representation of a 32-bit unsigned integer. If the
|
||||
current data value does not conform to such a representation, the
|
||||
commands behave as if the value were 0. Also, the item must already
|
||||
exist for incr/decr to work; these commands won't pretend that a
|
||||
non-existent key exists with value 0; instead, they will fail.
|
||||
|
||||
The client sends the command line:
|
||||
|
||||
incr <key> <value>\r\n
|
||||
|
||||
or
|
||||
|
||||
decr <key> <value>\r\n
|
||||
|
||||
- <key> is the key of the item the client wishes to change
|
||||
|
||||
- <value> is the amount by which the client wants to increase/decrease
|
||||
the item. It is a decimal representation of a 32-bit unsigned integer.
|
||||
|
||||
The response will be one of:
|
||||
|
||||
- "NOT_FOUND\r\n" to indicate the item with this value was not found
|
||||
|
||||
- <value>\r\n , where <value> is the new value of the item's data,
|
||||
after the increment/decrement operation was carried out.
|
||||
|
||||
Note that underflow in the "decr" command is caught: if a client tries
|
||||
to decrease the value below 0, the new value will be 0. Overflow in
|
||||
the "incr" command is not checked.
|
||||
|
||||
|
||||
Statistics
|
||||
----------
|
||||
|
||||
The command "stats" is used to query the server about statistics it
|
||||
maintains and other internal data. It has two forms. Without
|
||||
arguments:
|
||||
|
||||
stats\r\n
|
||||
|
||||
it causes the server to output general-purpose statistics and
|
||||
settings, documented below. In the other form it has some arguments:
|
||||
|
||||
stats <args>\r\n
|
||||
|
||||
Depending on <args>, various internal data is sent by the server. The
|
||||
kinds of arguments and the data sent are not documented in this vesion
|
||||
of the protocol, and are subject to change for the convenience of
|
||||
memcache developers.
|
||||
|
||||
|
||||
General-purpose statistics
|
||||
--------------------------
|
||||
|
||||
Upon receiving the "stats" command without arguments, the server sents
|
||||
a number of lines which look like this:
|
||||
|
||||
STAT <name> <value>\r\n
|
||||
|
||||
The server terminates this list with the line
|
||||
|
||||
END\r\n
|
||||
|
||||
In each line of statistics, <name> is the name of this statistic, and
|
||||
<value> is the data. The following is the list of all names sent in
|
||||
response to the "stats" command, together with the type of the value
|
||||
sent for this name, and the meaning of the value.
|
||||
|
||||
In the type column below, "32u" means a 32-bit unsigned integer, "64u"
|
||||
means a 64-bit unsigner integer. '32u:32u' means two 32-but unsigned
|
||||
integers separated by a colon.
|
||||
|
||||
|
||||
Name Type Meaning
|
||||
----------------------------------
|
||||
pid 32u Process id of this server process
|
||||
uptime 32u Number of seconds this server has been running
|
||||
time 32u current UNIX time according to the server
|
||||
version string Version string of this server
|
||||
rusage_user 32u:32u Accumulated user time for this process
|
||||
(seconds:microseconds)
|
||||
rusage_system 32u:32u Accumulated system time for this process
|
||||
(seconds:microseconds)
|
||||
curr_items 32u Current number of items stored by the server
|
||||
total_items 32u Total number of items stored by this server
|
||||
ever since it started
|
||||
bytes 64u Current number of bytes used by this server
|
||||
to store items
|
||||
curr_connections 32u Number of open connections
|
||||
total_connections 32u Total number of connections opened since
|
||||
the server started running
|
||||
connection_structures 32u Number of connection structures allocated
|
||||
by the server
|
||||
cmd_get 32u Cumulative number of retrieval requests
|
||||
cmd_set 32u Cumulative number of storage requests
|
||||
get_hits 32u Number of keys that have been requested and
|
||||
found present
|
||||
get_misses 32u Number of items that have been requested
|
||||
and not found
|
||||
bytes_read 64u Total number of bytes read by this server
|
||||
from network
|
||||
bytes_written 64u Total number of bytes sent by this server to
|
||||
network
|
||||
limit_maxbytes 32u Number of bytes this server is allowed to
|
||||
use for storage.
|
||||
|
||||
|
||||
|
||||
Other commands
|
||||
--------------
|
||||
|
||||
"flush_all" is a command with no arguments. It always succeeds,
|
||||
and the server sends "OK\r\n" in response. Its effect is to immediately
|
||||
invalidate all existing items: none of them will be returned in
|
||||
response to a retrieval command (unless it's stored again under the
|
||||
same key *after* flush_all has been executed). flush_all doesn't
|
||||
actually free all the memory taken up by existing items; that will
|
||||
happen gradually as new items are stored. The most precise definition
|
||||
of what flush_all does is the following: it causes all items whose
|
||||
update time is earlier than the time at which flush_all was executed
|
||||
to be ignored for retrieval purposes.
|
||||
|
||||
"version" is a command with no arguments:
|
||||
|
||||
version\r\n
|
||||
|
||||
In response, the server sends
|
||||
|
||||
"VERSION <version>\r\n", where <version> is the version string for the
|
||||
server.
|
||||
|
||||
|
||||
"quit" is a command with no arguments:
|
||||
|
||||
quit\r\n
|
||||
|
||||
Upon receiving this command, the server closes the
|
||||
connection. However, the client may also simply close the connection
|
||||
when it no longer needs it, without issuing this command.
|
||||
Reference in New Issue
Block a user