doc-exports/docs/dms/umn/Kafka-client-parameter.html
Chen, Junjie ca9677b121 DMS UMN 20230201 Version
Reviewed-by: Antonova, Ekaterina <ekantono@noreply.gitea.eco.tsi-dev.otc-service.com>
Co-authored-by: Chen, Junjie <chenjunjie@huawei.com>
Co-committed-by: Chen, Junjie <chenjunjie@huawei.com>
2024-07-22 13:20:04 +00:00

136 lines
17 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<a name="Kafka-client-parameter"></a><a name="Kafka-client-parameter"></a>
<h1 class="topictitle1">Setting Parameters for Kafka Clients</h1>
<div id="body0000001880476980"><p id="Kafka-client-parameter__p85386816474">This section provides recommendations on configuring common parameters for Kafka producers and consumers. Kafka clients in different versions may have different parameter names. The following parameters are supported in v1.1.0 and later. For details about other parameters and versions, see <a href="https://kafka.apache.org/documentation/#configuration" target="_blank" rel="noopener noreferrer">Kafka Configuration</a>.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="Kafka-client-parameter__table1323919491438" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Producer parameters</caption><thead align="left"><tr id="Kafka-client-parameter__row024116495310"><th align="left" class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.3.2.2.5.1.1"><p id="Kafka-client-parameter__p92901917413"><strong id="Kafka-client-parameter__b17290711249">Parameter</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.3.2.2.5.1.2"><p id="Kafka-client-parameter__p1029021448"><strong id="Kafka-client-parameter__b192905118412">Default Value</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.3.2.2.5.1.3"><p id="Kafka-client-parameter__p142901517413"><strong id="Kafka-client-parameter__b72901417413">Recommended Value</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="57.99999999999999%" id="mcps1.3.2.2.5.1.4"><p id="Kafka-client-parameter__p18290201244"><strong id="Kafka-client-parameter__b162901511144">Description</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="Kafka-client-parameter__row1324110492312"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.1 "><p id="Kafka-client-parameter__p2515684118">acks</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.2 "><p id="Kafka-client-parameter__p15661412">1</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.3 "><p id="Kafka-client-parameter__p1157644113"><strong id="Kafka-client-parameter__b84371256812">all</strong> or <strong id="Kafka-client-parameter__b1043715514817">1</strong> (if high reliability mode is selected)</p>
<p id="Kafka-client-parameter__p14596134120"><strong id="Kafka-client-parameter__b106061516186">1</strong> (if high throughput mode is selected)</p>
</td>
<td class="cellrowborder" valign="top" width="57.99999999999999%" headers="mcps1.3.2.2.5.1.4 "><p id="Kafka-client-parameter__p2518644110">Indicates the number of acknowledgments the producer requires the server to return before considering a request complete. This controls the durability of records that are sent. The value of this parameter can be any of the following:</p>
<p id="Kafka-client-parameter__p85961413"><strong id="Kafka-client-parameter__b1148610482089">0</strong>: The producer will not wait for any acknowledgment from the server at all. The record will be immediately added to the socket buffer and considered sent. No guarantee can be made that the server has received the record, and the retries configuration will not take effect (as the client generally does not know of any failures). The offset given back for each record will always be set to 1.</p>
<p id="Kafka-client-parameter__p165860414"><strong id="Kafka-client-parameter__b1144712438915">1</strong>: The leader will write the record to its local log but will respond without waiting until receiving full acknowledgement from all followers. If the leader fails immediately after acknowledging the record but before the followers have replicated it, the record will be lost.</p>
<p id="Kafka-client-parameter__p185168414"><strong id="Kafka-client-parameter__b949965095316">all</strong> or <strong id="Kafka-client-parameter__b2049995055315">-1</strong>: The leader needs to wait until all backups in the ISR are written into logs. As long as any backup survives, data will not be lost. <strong id="Kafka-client-parameter__b365612801416">min.insync.replicas</strong> specifies the minimum number of replicas that must acknowledge a write for the write to be considered successful.</p>
</td>
</tr>
<tr id="Kafka-client-parameter__row192411349738"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.1 "><p id="Kafka-client-parameter__p47126174110">retries</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.2 "><p id="Kafka-client-parameter__p17766134110">0</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.3 "><p id="Kafka-client-parameter__p1772615419">/</p>
</td>
<td class="cellrowborder" valign="top" width="57.99999999999999%" headers="mcps1.3.2.2.5.1.4 "><p id="Kafka-client-parameter__p199551521656">Number of times that the client resends a message. Setting this parameter to a value greater than zero will cause the client to resend any record that failed to be sent.</p>
<p id="Kafka-client-parameter__p27186124110">Note that this retry is no different than if the client re-sent the record upon receiving the error. Allowing retries will potentially change the ordering of records because if two batches are sent to the same partition, and the first fails and is retried but the second succeeds, then the records in the second batch may appear first.</p>
<p id="Kafka-client-parameter__p9128133514119">You are advised to configure producers so that they can be able to retry in case of network disconnections. Set <strong id="Kafka-client-parameter__b524084417183">retries</strong> to <strong id="Kafka-client-parameter__b182401944111813">3</strong> and the retry interval <strong id="Kafka-client-parameter__b924119446184">retry.backoff.ms</strong> to <strong id="Kafka-client-parameter__b11241184481817">1000</strong>.</p>
</td>
</tr>
<tr id="Kafka-client-parameter__row82411449935"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.1 "><p id="Kafka-client-parameter__p13714617415">request.timeout.ms</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.2 "><p id="Kafka-client-parameter__p157268417">30000</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.3 "><p id="Kafka-client-parameter__p107176114116">/</p>
</td>
<td class="cellrowborder" valign="top" width="57.99999999999999%" headers="mcps1.3.2.2.5.1.4 "><p id="Kafka-client-parameter__p51852172917">Maximum amount of time (in ms) the client will wait for the response of a request. If the response is not received before the timeout elapses, the client will throw a timeout exception.</p>
<p id="Kafka-client-parameter__p197264416">Setting this parameter to a large value, for example, <strong id="Kafka-client-parameter__b1134354121920">127000</strong> (127s), can prevent records from failing to be sent in high-concurrency scenarios.</p>
</td>
</tr>
<tr id="Kafka-client-parameter__row52417498310"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.1 "><p id="Kafka-client-parameter__p673624112">block.on.buffer.full</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.2 "><p id="Kafka-client-parameter__p573654116">TRUE</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.3 "><p id="Kafka-client-parameter__p1274613414">TRUE</p>
</td>
<td class="cellrowborder" valign="top" width="57.99999999999999%" headers="mcps1.3.2.2.5.1.4 "><p id="Kafka-client-parameter__p370312258306">Setting this parameter to <strong id="Kafka-client-parameter__b147075871911">TRUE</strong> indicates that when buffer memory is exhausted, the producer must stop receiving new message records or throw an exception.</p>
<p id="Kafka-client-parameter__p13726154115">By default, this parameter is set to <strong id="Kafka-client-parameter__b3734436202">TRUE</strong>. However, in some cases, non-blocking usage is desired and it is better to throw an exception immediately. Setting this parameter to <strong id="Kafka-client-parameter__b9614181512206">FALSE</strong> will cause the producer to instead throw "BufferExhaustedException" when buffer memory is exhausted.</p>
</td>
</tr>
<tr id="Kafka-client-parameter__row18241114912311"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.1 "><p id="Kafka-client-parameter__p17717614115">batch.size</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.2 "><p id="Kafka-client-parameter__p7766104113">16384</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.3 "><p id="Kafka-client-parameter__p197186134117">262144</p>
</td>
<td class="cellrowborder" valign="top" width="57.99999999999999%" headers="mcps1.3.2.2.5.1.4 "><p id="Kafka-client-parameter__p973654111">Default maximum number of bytes of messages that can be processed at a time. The producer will attempt to batch records together into fewer requests whenever multiple records are being sent to the same partition. This helps improve performance of both the client and the server. No attempt will be made to batch records larger than this size.</p>
<p id="Kafka-client-parameter__p1174684115">Requests sent to brokers will contain multiple batches, one for each partition with data available to be sent.</p>
<p id="Kafka-client-parameter__p671568418">A smaller batch size will make batching less common and may reduce throughput (a batch size of zero will disable batching entirely). A larger batch size may use more memory as a buffer of the specified batch size will always be allocated in anticipation of additional records.</p>
</td>
</tr>
<tr id="Kafka-client-parameter__row8241449034"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.1 "><p id="Kafka-client-parameter__p97176104117">buffer.memory</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.2 "><p id="Kafka-client-parameter__p11746194120">33554432</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.2.5.1.3 "><p id="Kafka-client-parameter__p167156134112">67108864</p>
</td>
<td class="cellrowborder" valign="top" width="57.99999999999999%" headers="mcps1.3.2.2.5.1.4 "><p id="Kafka-client-parameter__p5736134116">Total bytes of memory the producer can use to buffer records waiting to be sent to the server. If records are sent faster than they can be delivered to the broker, the producer will stop sending records or throw a "block.on.buffer.full" exception.</p>
<p id="Kafka-client-parameter__p37146194115">This setting should correspond roughly to the total memory the producer will use, but is not a rigid bound since not all memory the producer uses is used for buffering. Some additional memory will be used for compression (if compression is enabled) as well as for maintaining in-flight requests.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="Kafka-client-parameter__table1440709134014" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Consumer parameters</caption><thead align="left"><tr id="Kafka-client-parameter__row1840717954015"><th align="left" class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.3.3.2.5.1.1"><p id="Kafka-client-parameter__p9407209124010"><strong id="Kafka-client-parameter__b1452810251774">Parameter</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.3.3.2.5.1.2"><p id="Kafka-client-parameter__p440759114010"><strong id="Kafka-client-parameter__b10333846773">Default Value</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.3.3.2.5.1.3"><p id="Kafka-client-parameter__p7407119114014"><strong id="Kafka-client-parameter__b22211528716">Recommended Value</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="57.99999999999999%" id="mcps1.3.3.2.5.1.4"><p id="Kafka-client-parameter__p14071099406"><strong id="Kafka-client-parameter__b20992456971">Description</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="Kafka-client-parameter__row84071794405"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.2.5.1.1 "><p id="Kafka-client-parameter__p55029339546">auto.commit.enable</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.2.5.1.2 "><p id="Kafka-client-parameter__p155021633195419">TRUE</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.2.5.1.3 "><p id="Kafka-client-parameter__p5502333165415">FALSE</p>
</td>
<td class="cellrowborder" valign="top" width="57.99999999999999%" headers="mcps1.3.3.2.5.1.4 "><p id="Kafka-client-parameter__p12502633155418">If this parameter is set to <strong id="Kafka-client-parameter__b1560613413225">TRUE</strong>, the offset of messages already fetched by the consumer will be periodically committed to ZooKeeper. This committed offset will be used when the process fails as the position from which the new consumer will begin.</p>
<p id="Kafka-client-parameter__p850211335548">Constraints: If this parameter is set to <strong id="Kafka-client-parameter__b851122002215">FALSE</strong>, to avoid message loss, an offset must be committed to ZooKeeper after the messages are successfully consumed.</p>
</td>
</tr>
<tr id="Kafka-client-parameter__row1940711964018"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.2.5.1.1 "><p id="Kafka-client-parameter__p950363311540">auto.offset.reset</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.2.5.1.2 "><p id="Kafka-client-parameter__p105031233165413">latest</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.2.5.1.3 "><p id="Kafka-client-parameter__p45031833155412">earliest</p>
</td>
<td class="cellrowborder" valign="top" width="57.99999999999999%" headers="mcps1.3.3.2.5.1.4 "><p id="Kafka-client-parameter__p20503203319543">Indicates what to do when there is no initial offset in ZooKeeper or if the current offset has been deleted. Options:</p>
<ul id="Kafka-client-parameter__ul2690849172213"><li id="Kafka-client-parameter__li1369113491220"><strong id="Kafka-client-parameter__b207841441162216">earliest</strong>: Automatically reset to the smallest offset.</li><li id="Kafka-client-parameter__li7432205632212"><strong id="Kafka-client-parameter__b578315515220">latest</strong>: The offset is automatically reset to the largest offset.</li><li id="Kafka-client-parameter__li1880417590227"><strong id="Kafka-client-parameter__b1430911132315">none</strong>: The system throws an exception to the consumer if no offset is available.</li><li id="Kafka-client-parameter__li23006232320"><strong id="Kafka-client-parameter__b147091911235">anything else</strong>: The system throws an exception to the consumer.</li></ul>
<div class="note" id="Kafka-client-parameter__note16985225192416"><span class="notetitle"> NOTE: </span><div class="notebody"><p id="Kafka-client-parameter__p149858259243">If this parameter is set to <strong id="Kafka-client-parameter__b18471182592319">latest</strong>, the producer may start to send messages to new partitions (if any) before the consumer resets to the initial offset. As a result, some messages will be lost.</p>
</div></div>
</td>
</tr>
<tr id="Kafka-client-parameter__row440789154011"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.2.5.1.1 "><p id="Kafka-client-parameter__p1150383325416">connections.max.idle.ms</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.2.5.1.2 "><p id="Kafka-client-parameter__p2503173319543">600000</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.2.5.1.3 "><p id="Kafka-client-parameter__p13503433205410">30000</p>
</td>
<td class="cellrowborder" valign="top" width="57.99999999999999%" headers="mcps1.3.3.2.5.1.4 "><p id="Kafka-client-parameter__p1850373325411">Timeout interval (in ms) for an idle connection. The server closes the idle connection after this period of time ends. Setting this parameter to <strong id="Kafka-client-parameter__b75511837112316">30000</strong> can reduce the server response failures when the network condition is poor.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="kafka-ug-0062.html">Configuring the Kafka Client</a></div>
</div>
</div>