doc-exports/docs/fg/umn/functiongraph_01_0303.html
Chen, Junjie dac566cf2f FG UMN 20230725 version
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com>
Co-authored-by: Chen, Junjie <chenjunjie@huawei.com>
Co-committed-by: Chen, Junjie <chenjunjie@huawei.com>
2024-04-03 10:30:56 +00:00

92 lines
14 KiB
HTML
Raw 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="functiongraph_01_0303"></a><a name="functiongraph_01_0303"></a>
<h1 class="topictitle1">Configuring Single-Instance Multi-Concurrency</h1>
<div id="body32001227"><div class="section" id="functiongraph_01_0303__en-us_topic_0000001252067196_section1192433133819"><h4 class="sectiontitle">Overview</h4><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p1335081110396">By default, each function instance processes only one request at a specific time. For example, to process three concurrent requests, FunctionGraph triggers three function instances. To address this issue, FunctionGraph has launched the single-instance multi-concurrency feature, allowing multiple requests to be processed concurrently on one instance.</p>
</div>
<div class="section" id="functiongraph_01_0303__en-us_topic_0000001252067196_section489544017389"><h4 class="sectiontitle">Scenario</h4><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p10161142515391">This feature is suitable for functions which spend a long time to initialize or wait for a response from downstream services. The feature has the following advantages:</p>
<ul id="functiongraph_01_0303__en-us_topic_0000001252067196_ul397313379393"><li id="functiongraph_01_0303__en-us_topic_0000001252067196_li1197313720396">Fewer cold starts and lower latency: Usually, FunctionGraph starts three instances to process three requests, involving three cold starts. If you configure the concurrency of three requests per instance, only one instance is required, involving only one cold start.</li><li id="functiongraph_01_0303__en-us_topic_0000001252067196_li312216414395">Shorter processing duration and lower cost: Normally, the total duration of multiple requests is the sum of each request's processing time. </li></ul>
</div>
<div class="section" id="functiongraph_01_0303__en-us_topic_0000001252067196_section17466173944218"><h4 class="sectiontitle">Comparison</h4><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p13201944155">If a function takes 5s to execute each time and you set the number of requests that can be concurrently processed by an instance to 1, three requests need to be processed in three instances, respectively. Therefore, the total execution duration is 15s.</p>
<p id="functiongraph_01_0303__en-us_topic_0000001252067196_p192011048155">When you set <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b789264517518">Max. Requests per Instance</strong> to <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b1024312503510">5</strong>, if three requests are sent, they will be concurrently processed by one instance. The total execution time is 5s.</p>
<div class="note" id="functiongraph_01_0303__en-us_topic_0000001252067196_note146308551415"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p1181422774013">If the maximum number of requests per instance is greater than 1, new instances will be automatically added when this number is reached. The maximum number of instances will not exceed <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b1537712199541">Max. Instances per Function</strong> you set.</p>
</div></div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="functiongraph_01_0303__en-us_topic_0000001252067196_table1480615164612" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Comparison</caption><thead align="left"><tr id="functiongraph_01_0303__en-us_topic_0000001252067196_row148064511465"><th align="left" class="cellrowborder" valign="top" width="9.460946094609461%" id="mcps1.3.3.5.2.4.1.1"><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p148061555460">Comparison Item</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="37.67376737673767%" id="mcps1.3.3.5.2.4.1.2"><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p19806050462">Single-Instance Single-Concurrency</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="52.86528652865285%" id="mcps1.3.3.5.2.4.1.3"><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p580618516469">Single-Instance Multi-Concurrency</p>
</th>
</tr>
</thead>
<tbody><tr id="functiongraph_01_0303__en-us_topic_0000001252067196_row5807145104619"><td class="cellrowborder" valign="top" width="9.460946094609461%" headers="mcps1.3.3.5.2.4.1.1 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p280715124611">Log printing</p>
</td>
<td class="cellrowborder" valign="top" width="37.67376737673767%" headers="mcps1.3.3.5.2.4.1.2 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p22902925214">-</p>
</td>
<td class="cellrowborder" valign="top" width="52.86528652865285%" headers="mcps1.3.3.5.2.4.1.3 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p757010516169">To print logs, Node.js Runtime uses the <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b1437223164312">console.info()</strong> function, Python Runtime uses the <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b074604017431">print()</strong> function, and Java Runtime uses the <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b17843174619430">System.out.println()</strong> function. In this mode, current request IDs are included in the log content. However, when multiple requests are concurrently processed by an instance, the request IDs are incorrect if you continue to use the preceding functions to print logs. In this case, use <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b9957141320106">context.getLogger()</strong> to obtain a log output object, for example, Python Runtime.</p>
<p id="functiongraph_01_0303__en-us_topic_0000001252067196_p162922542389">log = context.getLogger()</p>
<p id="functiongraph_01_0303__en-us_topic_0000001252067196_p18292115413384">log.info("test")</p>
</td>
</tr>
<tr id="functiongraph_01_0303__en-us_topic_0000001252067196_row070417412533"><td class="cellrowborder" valign="top" width="9.460946094609461%" headers="mcps1.3.3.5.2.4.1.1 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p147051541155316">Shared variables</p>
</td>
<td class="cellrowborder" valign="top" width="37.67376737673767%" headers="mcps1.3.3.5.2.4.1.2 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p147055415537">Not involved.</p>
</td>
<td class="cellrowborder" valign="top" width="52.86528652865285%" headers="mcps1.3.3.5.2.4.1.3 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p3705341135314">Modifying shared variables will cause errors. Mutual exclusion protection is required when you modify non-thread-safe variables during function writing.</p>
</td>
</tr>
<tr id="functiongraph_01_0303__en-us_topic_0000001252067196_row18648124414533"><td class="cellrowborder" valign="top" width="9.460946094609461%" headers="mcps1.3.3.5.2.4.1.1 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p116481449530">Monitoring metrics</p>
</td>
<td class="cellrowborder" valign="top" width="37.67376737673767%" headers="mcps1.3.3.5.2.4.1.2 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p5648154425310">Perform monitoring based on the actual situation.</p>
</td>
<td class="cellrowborder" valign="top" width="52.86528652865285%" headers="mcps1.3.3.5.2.4.1.3 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p136481044105311">Under the same load, the number of function instances decreases significantly.</p>
</td>
</tr>
<tr id="functiongraph_01_0303__en-us_topic_0000001252067196_row1729811651619"><td class="cellrowborder" valign="top" width="9.460946094609461%" headers="mcps1.3.3.5.2.4.1.1 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p52989620161">Flow control error</p>
</td>
<td class="cellrowborder" valign="top" width="37.67376737673767%" headers="mcps1.3.3.5.2.4.1.2 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p2029817641619">Not involved.</p>
</td>
<td class="cellrowborder" valign="top" width="52.86528652865285%" headers="mcps1.3.3.5.2.4.1.3 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p829820611169">When there are too many requests, the error code in the body is <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b117381754181514">FSS.0429</strong>, the status in the response header is <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b12536364418">429</strong>, and the error message is <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b164332541342">Your request has been controlled by overload sdk, please retry later</strong>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="functiongraph_01_0303__en-us_topic_0000001252067196_section19593125212815"><h4 class="sectiontitle">Configuring Single-Instance Multi-Concurrency</h4><ol id="functiongraph_01_0303__en-us_topic_0000001252067196_ol9726133131813"><li id="functiongraph_01_0303__en-us_topic_0000001252067196_li19220424104513">Log in to the FunctionGraph console. In the navigation pane, choose <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_en-us_topic_0000001251907924_b033610517502">Functions</strong> &gt; <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_en-us_topic_0000001251907924_b183361950502">Function List</strong>.</li><li id="functiongraph_01_0303__en-us_topic_0000001252067196_li85541845124517">Click the function to be configured to go to the function details page.</li><li id="functiongraph_01_0303__en-us_topic_0000001252067196_li13283183812464">Choose <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b73282711348">Configuration</strong> &gt; <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b17781931163418">Concurrency</strong>.<div class="p" id="functiongraph_01_0303__en-us_topic_0000001252067196_p91519240321">Set parameters by referring to <a href="#functiongraph_01_0303__en-us_topic_0000001252067196_table1167224813179">Table 2</a> and click <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b1352918653614">Save</strong>.<div class="fignone" id="functiongraph_01_0303__en-us_topic_0000001252067196_fig7671124815176"><span class="figcap"><b>Figure 1 </b>Concurrency configuration</span><br><span><img id="functiongraph_01_0303__en-us_topic_0000001252067196_image667114811715" src="en-us_image_0000001387407430.png"></span></div>
<div class="tablenoborder"><a name="functiongraph_01_0303__en-us_topic_0000001252067196_table1167224813179"></a><a name="en-us_topic_0000001252067196_table1167224813179"></a><table cellpadding="4" cellspacing="0" summary="" id="functiongraph_01_0303__en-us_topic_0000001252067196_table1167224813179" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Description</caption><thead align="left"><tr id="functiongraph_01_0303__en-us_topic_0000001252067196_row667174815175"><th align="left" class="cellrowborder" valign="top" width="16.86%" id="mcps1.3.4.2.3.3.4.2.3.1.1"><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p1667174871713">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="83.14%" id="mcps1.3.4.2.3.3.4.2.3.1.2"><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p126711048151713">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="functiongraph_01_0303__en-us_topic_0000001252067196_row467194891716"><td class="cellrowborder" valign="top" width="16.86%" headers="mcps1.3.4.2.3.3.4.2.3.1.1 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p267154814177">Max. Requests per Instance</p>
</td>
<td class="cellrowborder" valign="top" width="83.14%" headers="mcps1.3.4.2.3.3.4.2.3.1.2 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p7671648101713">Number of concurrent requests supported by a single instance. Value range: 11000.</p>
</td>
</tr>
<tr id="functiongraph_01_0303__en-us_topic_0000001252067196_row1967274801719"><td class="cellrowborder" valign="top" width="16.86%" headers="mcps1.3.4.2.3.3.4.2.3.1.1 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p3671174831718">Max. Instances per Function</p>
</td>
<td class="cellrowborder" valign="top" width="83.14%" headers="mcps1.3.4.2.3.3.4.2.3.1.2 "><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p10672104801711">Maximum number of instances in which a function can run. Default: <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b355264110139">400</strong>. Maximum: <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b6453184320132">1000</strong>. <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b7200142931313">1</strong>: The function can run in any number of instances. <strong id="functiongraph_01_0303__en-us_topic_0000001252067196_b162066297132">0</strong>: The function is disabled.</p>
<div class="note" id="functiongraph_01_0303__en-us_topic_0000001252067196_note2672148201711"><span class="notetitle"> NOTE: </span><div class="notebody"><p id="functiongraph_01_0303__en-us_topic_0000001252067196_p1167214851719">Requests that exceed the processing capability of instances will be discarded.</p>
<p id="functiongraph_01_0303__en-us_topic_0000001252067196_p18672948131719">Errors caused by excessive requests will not be displayed in function logs. You can obtain error details by referring to <a href="functiongraph_01_0390_03.html#functiongraph_01_0390_03">Configuring Asynchronous Execution Notification</a>.</p>
</div></div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</li></ol>
</div>
<div class="section" id="functiongraph_01_0303__en-us_topic_0000001252067196_section145531130114519"><h4 class="sectiontitle">Configuration Constraints</h4><ul id="functiongraph_01_0303__en-us_topic_0000001252067196_ul97531533182611"><li id="functiongraph_01_0303__en-us_topic_0000001252067196_li78722385262">For Python functions, threads on an instance are bound to one core due to the Python Global Interpreter Lock (GIL) lock. As a result, concurrent requests can only be processed using the single core, not multiple cores. The function processing performance cannot be improved even if larger resource specifications are configured.</li><li id="functiongraph_01_0303__en-us_topic_0000001252067196_li1014311486261">For Node.js functions, the single-process single-thread processing of the V8 engine results in processing of concurrent requests only using a single core, not multiple cores. The function processing performance cannot be improved even if larger resource specifications are configured.</li></ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="functiongraph_01_0300.html">Configuring Functions</a></div>
</div>
</div>