Merged trunk.
[m6w6/libmemcached] / docs / memcached_behavior.rst
1 .. highlight:: perl
2
3
4 ****
5 NAME
6 ****
7
8
9 memcached_behavior_get, memcached_behavior_set - Manipulate behavior
10
11
12 *******
13 LIBRARY
14 *******
15
16
17 C Client Library for memcached (libmemcached, -lmemcached)
18
19
20 ********
21 SYNOPSIS
22 ********
23
24
25
26 .. code-block:: perl
27
28 #include <memcached.h>
29
30 uint64_t
31 memcached_behavior_get (memcached_st *ptr,
32 memcached_behavior flag);
33
34 memcached_return_t
35 memcached_behavior_set (memcached_st *ptr,
36 memcached_behavior flag,
37 uint64_t data);
38
39
40
41 ***********
42 DESCRIPTION
43 ***********
44
45
46 libmemcached(3) behavior can be modified by use memcached_behavior_set().
47 Default behavior is the library strives to be quick and accurate. Some
48 behavior, while being faster, can also result in not entirely accurate
49 behavior (for instance, memcached_set() will always respond with
50 \ ``MEMCACHED_SUCCESS``\ ).
51
52 memcached_behavior_get() takes a behavior flag and returns whether or not
53 that behavior is currently enabled in the client.
54
55 memcached_behavior_set() changes the value of a particular option of the
56 client. It takes both a flag (listed below) and a value. For simple on or
57 off options you just need to pass in a value of 1. Calls to
58 memcached_behavior_set() will flush and reset all connections.
59
60
61 MEMCACHED_BEHAVIOR_USE_UDP
62
63 Causes libmemcached(3) to use the UDP transport when communicating
64 with a memcached server. Not all I/O operations are supported
65 when this behavior is enababled. The following operations will return
66 \ ``MEMCACHED_NOT_SUPPORTED``\ when executed with the MEMCACHED_BEHAVIOR_USE_UDP
67 enabled: memcached_version(), memcached_stat(), memcached_get(),
68 memcached_get_by_key(), memcached_mget(), memcached_mget_by_key(),
69 memcached_fetch(), memcached_fetch_result(), memcached_value_fetch().
70
71 All other operations are supported but are executed in a 'fire-and-forget'
72 mode, in which once the client has executed the operation, no attempt
73 will be made to ensure the operation has been received and acted on by the
74 server.
75
76 libmemcached(3) does not allow TCP and UDP servers to be shared within
77 the same libmemached(3) client 'instance'. An attempt to add a TCP server
78 when this behavior is enabled will result in a \ ``MEMCACHED_INVALID_HOST_PROTOCOL``\ ,
79 as will attempting to add a UDP server when this behavior has not been enabled.
80
81
82
83 MEMCACHED_BEHAVIOR_NO_BLOCK
84
85 Causes libmemcached(3) to use asychronous IO. This is the fastest transport
86 available for storage functions.
87
88
89
90 MEMCACHED_BEHAVIOR_SND_TIMEOUT
91
92 This sets the microsecond behavior of the socket against the SO_SNDTIMEO flag.
93 In cases where you cannot use non-blocking IO this will allow you to still have
94 timeouts on the sending of data.
95
96
97
98 MEMCACHED_BEHAVIOR_RCV_TIMEOUT
99
100 This sets the microsecond behavior of the socket against the SO_RCVTIMEO flag.
101 In cases where you cannot use non-blocking IO this will allow you to still have
102 timeouts on the reading of data.
103
104
105
106 MEMCACHED_BEHAVIOR_TCP_NODELAY
107
108 Turns on the no-delay feature for connecting sockets (may be faster in some
109 environments).
110
111
112
113 MEMCACHED_BEHAVIOR_HASH
114
115 Makes the default hashing algorithm for keys use MD5. The value can be set
116 to either MEMCACHED_HASH_DEFAULT, MEMCACHED_HASH_MD5, MEMCACHED_HASH_CRC, MEMCACHED_HASH_FNV1_64, MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, MEMCACHED_HASH_FNV1A_32, MEMCACHED_HASH_JENKINS, MEMCACHED_HASH_HSIEH, and MEMCACHED_HASH_MURMUR.
117 Each hash has it's advantages and it's weaknesses. If you don't know or don't care, just go with the default.
118 Support for MEMCACHED_HASH_HSIEH is a compile time option that is disabled by default. To enable support for this hashing algorithm, configure and build libmemcached with the --enable-hash_hsieh.
119
120
121
122 MEMCACHED_BEHAVIOR_DISTRIBUTION
123
124 Using this you can enable different means of distributing values to servers.
125 The default method is MEMCACHED_DISTRIBUTION_MODULA. You can enable
126 consistent hashing by setting MEMCACHED_DISTRIBUTION_CONSISTENT.
127 Consistent hashing delivers better distribution and allows servers to be
128 added to the cluster with minimal cache losses. Currently
129 MEMCACHED_DISTRIBUTION_CONSISTENT is an alias for the value
130 MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA.
131
132
133
134 MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
135
136 Memcached can cache named lookups so that DNS lookups are made only once.
137
138
139
140 MEMCACHED_BEHAVIOR_SUPPORT_CAS
141
142 Support CAS operations (this is not enabled by default at this point in the server since it imposes a slight performance penalty).
143
144
145
146 MEMCACHED_BEHAVIOR_KETAMA
147
148 Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
149 and the hash to MEMCACHED_HASH_MD5.
150
151
152
153 MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
154
155 Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA with the weighted support.
156 and the hash to MEMCACHED_HASH_MD5.
157
158
159
160 MEMCACHED_BEHAVIOR_KETAMA_HASH
161
162 Sets the hashing algorithm for host mapping on continuum. The value can be set
163 to either MEMCACHED_HASH_DEFAULT, MEMCACHED_HASH_MD5, MEMCACHED_HASH_CRC, MEMCACHED_HASH_FNV1_64, MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, and MEMCACHED_HASH_FNV1A_32.
164
165
166
167 MEMCACHED_BEHAVIOR_KETAMA_COMPAT
168
169 Sets the compatibility mode. The value can be set to either
170 MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED (this is the default) or
171 MEMCACHED_KETAMA_COMPAT_SPY to be compatible with the SPY Memcached client
172 for Java.
173
174
175
176 MEMCACHED_BEHAVIOR_POLL_TIMEOUT
177
178 Modify the timeout value that is used by poll(). The default value is -1. An signed int pointer must be passed to memcached_behavior_set() to change this value. For memcached_behavior_get() a signed int value will be cast and returned as the unsigned long long.
179
180
181
182 MEMCACHED_BEHAVIOR_USER_DATA
183
184 This allows you to store a pointer to a specifc piece of data. This can be
185 retrieved from inside of memcached_fetch_execute(). Cloning a memcached_st
186
187 will copy the pointer to the clone. This was deprecated in 0.14 in favor
188 of memcached_callback_set(3). This will be removed in 0.15.
189
190
191
192 MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
193
194 Enabling buffered IO causes commands to "buffer" instead of being sent. Any
195 action that gets data causes this buffer to be be sent to the remote
196 connection. Quiting the connection or closing down the connection will also
197 cause the buffered data to be pushed to the remote connection.
198
199
200
201 MEMCACHED_BEHAVIOR_VERIFY_KEY
202
203 Enabling this will cause libmemcached(3) to test all keys to verify that they
204 are valid keys.
205
206
207
208 MEMCACHED_BEHAVIOR_SORT_HOSTS
209
210 Enabling this will cause hosts that are added to be placed in the host list in
211 sorted order. This will defeat consisten hashing.
212
213
214
215 MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
216
217 In non-blocking mode this changes the value of the timeout during socket
218 connection.
219
220
221
222 MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
223
224 Enable the use of the binary protocol. Please note that you cannot toggle
225 this flag on an open connection.
226
227
228
229 MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
230
231 Set this value to enable the server be removed after continuous MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
232 times connection failure.
233
234
235
236 MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
237
238 Set this value to tune the number of messages that may be sent before
239 libmemcached should start to automatically drain the input queue. Setting
240 this value to high, may cause libmemcached to deadlock (trying to send data,
241 but the send will block because the input buffer in the kernel is full).
242
243
244
245 MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK
246
247 Set this value to tune the number of bytes that may be sent before
248 libmemcached should start to automatically drain the input queue (need
249 at least 10 IO requests sent without reading the input buffer). Setting
250 this value to high, may cause libmemcached to deadlock (trying to send
251 data, but the send will block because the input buffer in the kernel is full).
252
253
254
255 MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
256
257 The binary protocol works a bit different than the textual protocol in
258 that a multiget is implemented as a pipe of single get-operations which
259 are sent to the server in a chunk. If you are using large multigets from
260 your application, you may improve the latency of the gets by setting
261 this value so you send out the first chunk of requests when you hit the
262 specified limit. It allows the servers to start processing the requests
263 to send the data back while the rest of the requests are created and
264 sent to the server.
265
266
267
268 MEMCACHED_BEHAVIOR_NOREPLY
269
270 Set this value to specify that you really don't care about the result
271 from your storage commands (set, add, replace, append, prepend).
272
273
274
275 MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
276
277 If you just want "a poor mans HA", you may specify the numbers of
278 replicas libmemcached should store of each item (on different servers).
279 This replication does not dedicate certain memcached servers to store the
280 replicas in, but instead it will store the replicas together with all of the
281 other objects (on the 'n' next servers specified in your server list).
282
283
284
285 MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
286
287 Allows randomizing the replica reads starting point. Normally the read is
288 done from primary server and in case of miss the read is done from primary
289 + 1, then primary + 2 all the way to 'n' replicas. If this option is set
290 on the starting point of the replica reads is randomized between the servers.
291 This allows distributing read load to multiple servers with the expense of
292 more write traffic.
293
294
295
296 MEMCACHED_BEHAVIOR_CORK
297
298 Enable TCP_CORK behavior. This is only available as an option Linux.
299 MEMCACHED_NO_SERVERS is returned if no servers are available to test with.
300 MEMCACHED_NOT_SUPPORTED is returned if we were not able to determine
301 if support was available. All other responses then MEMCACHED_SUCCESS
302 report an error of some sort. This behavior also enables
303 MEMCACHED_BEHAVIOR_TCP_NODELAY when set.
304
305
306
307 MEMCACHED_BEHAVIOR_KEEPALIVE
308
309 Enable TCP_KEEPALIVE behavior.
310
311
312
313 MEMCACHED_BEHAVIOR_KEEPALIVE_IDLE
314
315 Specify time, in seconds, to mark a connection as idle. This is only available as an option Linux.
316
317
318
319 MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
320
321 Find the current size of SO_SNDBUF. A value of 0 means either an error
322 occured or no hosts were available. It is safe to assume system default
323 if this occurs. If an error occurs you can checked the last cached errno statement to find the specific error.
324
325
326
327 MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
328
329 Find the current size of SO_RCVBUF. A value of 0 means either an error
330 occured or no hosts were available. It is safe to assume system default
331 if this occurs. If an error occurs you can checked the last cached errno statement to find the specific error.
332
333
334
335 MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
336
337 This number of times a host can have an error before it is disabled.
338
339
340
341 MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
342
343 If enabled any hosts which have been flagged as disabled will be removed
344 from the list of servers in the memcached_st structure. This must be used
345 in combination with MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT.
346
347
348
349 MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
350
351 When enabled a host which is problematic will only be checked for usage
352 based on the amount of time set by this behavior.
353
354
355
356 MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY
357
358 When enabled the prefix key will be added to the key when determining
359 server by hash.
360
361
362
363
364 ******
365 RETURN
366 ******
367
368
369 memcached_behavior_get() returns either the current value of the get, or 0
370 or 1 on simple flag behaviors (1 being enabled). memcached_behavior_set()
371 returns failure or success.
372
373
374 *****
375 NOTES
376 *****
377
378
379 memcached_behavior_set() in version .17 was changed from taking a pointer
380 to data value, to taking a uin64_t.
381
382
383 ****
384 HOME
385 ****
386
387
388 To find out more information please check:
389 `https://launchpad.net/libmemcached <https://launchpad.net/libmemcached>`_
390
391
392 ******
393 AUTHOR
394 ******
395
396
397 Brian Aker, <brian@tangent.org>
398
399
400 ********
401 SEE ALSO
402 ********
403
404
405 memcached(1) libmemcached(3) memcached_strerror(3)
406