Yang, Tong 6182f91ba8 MRS component operation guide_normal 2.0.38.SP20 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Yang, Tong <yangtong2@huawei.com>
Co-committed-by: Yang, Tong <yangtong2@huawei.com>
2022-12-09 14:55:21 +00:00

42 lines
9.6 KiB
HTML

<a name="mrs_01_1983"></a><a name="mrs_01_1983"></a>
<h1 class="topictitle1">Designing the Direction Acyclic Graph (DAG)</h1>
<div id="body1595920217991"><div class="section" id="mrs_01_1983__sff53dedf37294bfa92fbbd8da8641403"><h4 class="sectiontitle">Scenario</h4><p id="mrs_01_1983__a05f6e9aa52104c979f189ea1d59db9fc">Optimal program structure helps increase execution efficiency. During application programming, avoid shuffle operations and combine narrow-dependency operations.</p>
</div>
<div class="section" id="mrs_01_1983__s754cf93147764edc89c31c425237e941"><h4 class="sectiontitle">Procedure</h4><p id="mrs_01_1983__ac2be7790d8b64322931854bfbcf08b05">This topic describes how to design the DAG using the following example:</p>
<ul id="mrs_01_1983__u3e703b8a080349129aa493dde85ef44d"><li id="mrs_01_1983__l0648ee258e2c4ce5a9a533747478e6a3"><strong id="mrs_01_1983__b17250991417">Data format</strong>: Time when a vehicle passes a toll station, license plate number, toll station number, and more</li><li id="mrs_01_1983__l043c463485014c099ea83a8b9311596d"><strong id="mrs_01_1983__b19290743318">Logic</strong>: Two vehicles are determined to be traveling together if the following conditions are met:<ul id="mrs_01_1983__u01c635a275384706a371f221263c7144"><li id="mrs_01_1983__l78d84f8a24cd4bc4a8547919572db354">Both vehicles pass the same toll stations in the same sequence.</li><li id="mrs_01_1983__ld3a42db84a534cdd9b857cd0378605fa">The difference between the time that the vehicles pass the same toll station is smaller than a specified value.</li></ul>
</li></ul>
<p id="mrs_01_1983__aa9184424a4d04eb0ae81242344fa3883">There are two implementation ways for this example. <a href="#mrs_01_1983__f20e2f35bb3d74f7ba062fffcc54f51bc">Figure 1</a> shows the logic of implementation 1 and <a href="#mrs_01_1983__f1f6a59d3ec254ae7bd46d3ace67fa3a7">Figure 2</a> shows logic of implementation 2.</p>
<div class="fignone" id="mrs_01_1983__f20e2f35bb3d74f7ba062fffcc54f51bc"><a name="mrs_01_1983__f20e2f35bb3d74f7ba062fffcc54f51bc"></a><a name="f20e2f35bb3d74f7ba062fffcc54f51bc"></a><span class="figcap"><b>Figure 1 </b>Implementation logic 1</span><br><span><img id="mrs_01_1983__image426115612915" src="en-us_image_0000001296250248.png"></span></div>
<p id="mrs_01_1983__a988fd8ce21494be288cf94c45c344f60">Logic description:</p>
<ol id="mrs_01_1983__o48b9339dddd243f7aa99dfd0e293181a"><li id="mrs_01_1983__la072aa3d417f495b806c510f542fc3c5">Collect information about the toll stations passed by each vehicle based on the vehicle license plate number and sort the toll stations.<p id="mrs_01_1983__abc8fd8f55f4145c6a6a11e9302109d84"><a name="mrs_01_1983__la072aa3d417f495b806c510f542fc3c5"></a><a name="la072aa3d417f495b806c510f542fc3c5"></a>The following data is obtained: vehicle license plate number 1, [(time, toll station 3), (time, toll station 2), (time, toll station 4), (time, toll station 5)]</p>
</li><li id="mrs_01_1983__l8120eacfc71346f4b8c8036cba861292">Determine the sequence in which the vehicle passed through.<p id="mrs_01_1983__a78c23c91d02847c4b0ccf60b73658421"><a name="mrs_01_1983__l8120eacfc71346f4b8c8036cba861292"></a><a name="l8120eacfc71346f4b8c8036cba861292"></a>(toll station 3, (vehicle license plate number 1, time, 1st toll station))</p>
<p id="mrs_01_1983__a8eb16bff03c04b87a3ef8e20fcdc35e1">(toll station 2, (vehicle license plate number 1, time, 2nd toll station))</p>
<p id="mrs_01_1983__aa5d7a3342a95408baf07bb12bfbdcea9">(toll station 4, (vehicle license plate number 1, time, 3rd toll station))</p>
<p id="mrs_01_1983__aa94b3615eaff4472ad700a20e5ca20d5">(toll station 5, (vehicle license plate number 1, time, 4th toll station))</p>
</li><li id="mrs_01_1983__lb340749bcba648c589473d35a6dc25c6">Aggregate data by toll station.<p id="mrs_01_1983__a1554f7c717c74df8ab8ba75715e7fe8c"><a name="mrs_01_1983__lb340749bcba648c589473d35a6dc25c6"></a><a name="lb340749bcba648c589473d35a6dc25c6"></a>toll station 1, [(vehicle license plate number 1, time, 1st toll station), (vehicle license plate number 2, time, 5th toll station), (vehicle license plate number 3, time, 2nd toll station)]</p>
</li><li id="mrs_01_1983__l26de113866f84361873fc86044e3fb69">Determine whether the time difference that two vehicles passed through the same toll station is below the specified value. If yes, fetch information about the two vehicles.<p id="mrs_01_1983__a7a00ef60048c406ebfca1a38a58c482e"><a name="mrs_01_1983__l26de113866f84361873fc86044e3fb69"></a><a name="l26de113866f84361873fc86044e3fb69"></a>(vehicle license plate number 1, vehicle license plate number 2),(1st toll station, 5th toll station)</p>
<p id="mrs_01_1983__adefc656106cc4b1f8417958c800ceacb">(vehicle license plate number 1, vehicle license plate number 3),(1st toll station, 2nd toll station)</p>
</li><li id="mrs_01_1983__l72d4271402dc4978a7d6750f06967253">Aggregate data based on the vehicle license plate numbers that passed through the same toll stations.<p id="mrs_01_1983__a89ffef249a254265ad0846edb1ba5bdc"><a name="mrs_01_1983__l72d4271402dc4978a7d6750f06967253"></a><a name="l72d4271402dc4978a7d6750f06967253"></a>(vehicle license plate number 1, vehicle license plate number 2), [(1st toll station, 5th toll station), (2nd toll station, 6th toll station), (1st toll station, 7th toll station), (3rd toll station, 8th toll station)]</p>
</li><li id="mrs_01_1983__l67883a79db53491d8c5b8dfe50980d69">If the two vehicles pass through the same toll stations in sequence, for example, toll stations 3, 4, 5 are the first, second, and third toll station passed by vehicle 1 and the 6th, 7th, and 8th toll station passed by vehicle 2, and the number of toll stations meets the specified requirements, the two vehicles are determined to be traveling together.</li></ol>
<p id="mrs_01_1983__a1d96e1fb463b46778f32586baa054e4e">The logic of implementation 1 has the following disadvantages:</p>
<ul id="mrs_01_1983__ua79c5fb8d9374352b7cabd4a7720ae4d"><li id="mrs_01_1983__ldfa0f71f5d614c9ca84131f41c28de38">The logic is complex.</li><li id="mrs_01_1983__l8c2cbe5eb52c4ac8a335551eb2376f32">Too many shuffle operations affect performance.</li></ul>
<div class="fignone" id="mrs_01_1983__f1f6a59d3ec254ae7bd46d3ace67fa3a7"><a name="mrs_01_1983__f1f6a59d3ec254ae7bd46d3ace67fa3a7"></a><a name="f1f6a59d3ec254ae7bd46d3ace67fa3a7"></a><span class="figcap"><b>Figure 2 </b>Implementation logic 2</span><br><span><img id="mrs_01_1983__image1687937103713" src="en-us_image_0000001349090445.png"></span></div>
<p id="mrs_01_1983__a46f5d360415c42938e447ff89ab94f58"></p>
<p id="mrs_01_1983__ac7f01fa0b06d4749a7496c3285df8b01">Logic description:</p>
<ol id="mrs_01_1983__of5b3ee2f8b3b454a96651163ea371755"><li id="mrs_01_1983__l1787b308635c459e81477d6e5fc964e8">Collect information about the toll stations passed by each vehicle based on the vehicle license plate number and sort the toll stations.<p id="mrs_01_1983__ad198888a32f34fcfafc63658791ec9ef"><a name="mrs_01_1983__l1787b308635c459e81477d6e5fc964e8"></a><a name="l1787b308635c459e81477d6e5fc964e8"></a>The following data is obtained: vehicle license plate number 1, [(time, toll station 3), (time, toll station 2), (time, toll station 4), (time, toll station 5)]</p>
</li><li id="mrs_01_1983__l2fb8e5bbc0024cb0855b233becbc5267">Based on the number of toll stations (the number is 3 in this example) that must be passed by these vehicles, divide the toll station sequence as follows:<p id="mrs_01_1983__a1c415c98548c4d3f87bc01371e6ab374"><a name="mrs_01_1983__l2fb8e5bbc0024cb0855b233becbc5267"></a><a name="l2fb8e5bbc0024cb0855b233becbc5267"></a>toll station 3 &gt; toll station 2 &gt; toll station 4, (vehicle license plate number 1, [time passing through toll station 3, time passing through toll station 2, time passing through toll station 4])</p>
<p id="mrs_01_1983__ab6069f9d92a244a1ab75225d06c47ee3">toll station 2 &gt; toll station 4 &gt; toll station 5, (vehicle license plate number 1, [time passing through toll station 2, time passing through toll station 4, time passing through toll station 5])</p>
</li><li id="mrs_01_1983__l76989dbd8d0048bc9498439a2eee9495">Aggregate information about vehicles that pass the same toll stations in the same sequence.<p id="mrs_01_1983__ad1a23ddfb56c4b07a2a23c2b55e85e7e"><a name="mrs_01_1983__l76989dbd8d0048bc9498439a2eee9495"></a><a name="l76989dbd8d0048bc9498439a2eee9495"></a>toll station 3 &gt; toll station 2 &gt; toll station 4, [(vehicle license plate number 1, [time passing through toll station 3, time passing through toll station 2, time passing through toll station 4]), (vehicle license plate number 2, [time passing through toll station 3, time passing through toll station 2, time passing through toll station 4]), (vehicle license plate number 3, [time passing through toll station 3, time passing through toll station 2, time passing through toll station 4])]</p>
</li><li id="mrs_01_1983__lf12e642d5d5146a38ef0eb2f7c056459">Determine whether the time difference that these vehicles passed through the same toll station is below the specified value. If yes, the vehicles are determined to be traveling together.</li></ol>
<p id="mrs_01_1983__a12cf563dc15f4d92b5b5f9599b18cff5">The logic of implementation 2 has the following advantages:</p>
<ul id="mrs_01_1983__u3e2fc56564274d6f9b5a683de0eb60ef"><li id="mrs_01_1983__l9e6948ec752a418ba43d7237326a4348">The logic is simplified.</li><li id="mrs_01_1983__l8f7789d8d1cb44128009d5eb02e6a4f1">One <strong id="mrs_01_1983__b12045139286922">groupByKey</strong> is reduced, that is, one less shuffle operation is performed. It helps improve performance.</li></ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_1975.html">Spark Core Tuning</a></div>
</div>
</div>