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