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