<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by swetha murali on Medium]]></title>
        <description><![CDATA[Stories by swetha murali on Medium]]></description>
        <link>https://medium.com/@swethamurali03?source=rss-d534d6a5dcd4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ExmuRNhT338g9186</url>
            <title>Stories by swetha murali on Medium</title>
            <link>https://medium.com/@swethamurali03?source=rss-d534d6a5dcd4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:40:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@swethamurali03/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Apache Spark — How much resource my spark job require ~approximately.]]></title>
            <link>https://medium.com/@swethamurali03/apache-spark-how-much-resource-my-spark-job-require-approximately-945b82605645?source=rss-d534d6a5dcd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/945b82605645</guid>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[swetha murali]]></dc:creator>
            <pubDate>Wed, 10 Apr 2024 15:14:40 GMT</pubDate>
            <atom:updated>2024-04-10T15:49:43.124Z</atom:updated>
            <content:encoded><![CDATA[<h3>Apache Spark — How much resource my spark job require.</h3><p>We need to consider the below factors</p><ol><li>Amount of data we are going to deal.</li><li>how quickly we want the job to complete.</li></ol><p>we need to allocate resources such a way we do not hit OOM (out of memory) errors and performance bottlenecks.</p><p>Lets Assume, we have 10GB data to be processed and want the job to be completed quickly (which means to use parallelism to the fullest possible)</p><h3><strong>Worker Node configuration</strong></h3><p>Lets take a worker with 16 CPU cores and 64 GB of RAM.</p><p>1 core goes for background processes and 1GB RAM is given to OS.</p><p>We have 15 core CPU and 63 GB RAM each node. Doing a optimal cut, we can have 3 executors — 5 CORES and 21GB RAM each.</p><p>On this 21 GB RAM, Deducting 7% for off-heap memory , ~1.5GB going to off heap( 7% of executor memory ( 7 % of 21 GB = 1.5 GB) for each executor, we end up, with <strong>3 executors — 5 CORES and 19GB RAM each </strong>on each node<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*B9KzxbzESDp5aPhD83ErMA.jpeg" /></figure><p>on this 19 GB RAM, 300MB goes to reserved memory, 40 % goes to user memory and 60% we get as unified region — which is for storage and execution. which means, ~5 GB for storage and ~5GB for execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*170UNJhv1uLfbx9dd1CrDA.png" /></figure><blockquote><strong>At core level, each core will get around ~1GB for execution and ~1GB for storage. Why we speak, for each core, is because, each core handles one partition.</strong></blockquote><p>Assuming default block size is 128MB. we are going to have 80 partitions.</p><p>Execution memory for 128 mb data will be 4x. Why ? 128MB at disk will be more when it is brought to memory (after deserialisation). And operations like join and group by will take extra memory for its internal data structures. so, for 128 mb of data, peak execution memory is going to be <strong>somewhere 750 mb</strong>.</p><p>with the worker node we are considering, each core will get around 1GB of execution memory which is more than 750 mb and safe enough to handle 128 mb partition.</p><p><strong>how many such nodes do we need.</strong></p><p>In order to process all the 80 partitions in parallel we need to have 80 cores working. Our worker has 3 executors each with 5 core. So, to process 80 partitions we will need 80/5 = 16 executors, and 16/3 ~ <strong>6 worker nodes</strong>.</p><p>When we perform, wide transformations like group by, join etc will need data shuffling and number of partition by default becomes 200 on the shuffle stage. when this 10GB data gets to be divided in 200 partition, each partition with need handle 50mb of data. The executor set up we have assumed will be able to handle it easily. With only 80 cores available to run in parallel, the 200 partitions gets to be executed in 3 batches. we can change the shuffle partition by setting the <strong>spark.sql.shuffle.partitions. </strong>When we change it to 80, then each partition will be of size ~125 mb which is under safe limit. With this we can run all the partition in single batch.</p><p>Changing shuffle partition number according to total number of cores available will help us<strong> </strong>minimize idle time of CPU cores and we can change provided, partition size is within “safe” limits. We can increase when we have more CPU cores available, so we use them completely. We can reduce, when we want to reduce the execution time, ensuring we are with in safe limit of execution memory.</p><p>In order process 10GB of data with spark job having at least 2 stages ( involving a wide transformation) and having initial partition 80 and setting shuffle.partitions as well to 80, and assuming default block size to be 128MB, we will be able to run the job with 6 worker node having with 16 CPU cores and 64 GB of RAM each.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=945b82605645" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache Spark — Executors]]></title>
            <link>https://medium.com/@swethamurali03/apache-spark-executors-cba87f3de78d?source=rss-d534d6a5dcd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/cba87f3de78d</guid>
            <category><![CDATA[executor]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[swetha murali]]></dc:creator>
            <pubDate>Thu, 21 Dec 2023 16:40:52 GMT</pubDate>
            <atom:updated>2024-03-11T15:10:56.107Z</atom:updated>
            <content:encoded><![CDATA[<h3>Apache Spark — Executors — How many tasks can my cluster run in parallel</h3><p>Executors are responsible for actually executing the work that the driver assigns them. All the computation requires a certain amount of memory and CPU.</p><p>An executor is a single JVM process that is launched for a spark application on a node. A node can have multiple executors.</p><p>Lets consider a 10-Node cluster with 16 Core, 64 GB RAM on each node. Let’s do math based in above numbers throughout .</p><h3>How many executors do we need for optimal performance?</h3><p><strong>Thin ( Slicing cores &amp; RAM very thin )</strong></p><ol><li>allotting bare minimum resource possible for each executor. In our case, we will be allotting 1 core for each executor and 4GB RAM.</li><li>Problem — No multithreading, and multiple tasks cannot run within the same executor.</li></ol><p><strong>Fat — ( Slicing cores &amp; RAM too Big )</strong></p><ol><li>Giving maximum possible resource for the executor . In our case, allotting all 16 core and 64GB RAM to one executor. which also mean only one executor for entire node.</li><li>Problem —If executors hold huge amount of memory, Garbage collection ( removing unused objects from memory) will take lot of time.</li><li>HDFS throughtput suffers — they get slow.</li></ol><h3><strong>Balanced approach — Anything in extreme is not good</strong></h3><blockquote><strong>We want multi threading on each executor , at the same time throughput should also not get affected. It is observed, HDFS achieves full write throughput with ~5 tasks per executor, which means we can allot ~5 cores for each executor to get optimal performance</strong> .</blockquote><h3>Calculating total number of executors in the cluster</h3><p>We have 10 Node cluster with, 16 CPU cores anf 64 GB RAM on each node .</p><p>1 core goes for background processes and 1GB RAM is given to OS. We have 15 core CPU and 63 GB RAM.</p><p>Doing a optimal cut, we can have 3 executors — 5 CORES and 21 GB RAM each.</p><h4>Off-Heap Memory</h4><p>This is memory outside the JVM heap space, used for off-heap storage (like caching), reducing GC overhead.</p><blockquote>off heap memory <em>= MAX</em>(384 MB, 7% of executor memory)</blockquote><p>In our case, 7% of executor memory ( 7 % of 21 GB = 1.5 GB) goes to off heap memory. 19 GB remaining to be allotted for executors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*B9KzxbzESDp5aPhD83ErMA.jpeg" /></figure><h4>Total Executors</h4><ul><li>Each executor has 5 cores and 19 GB RAM, with 3 executors per node, making it 30 executors across the cluster.</li><li>One goes for YARN application manager, resulting in <strong>29 executors on the cluster.</strong></li></ul><h4>How many tasks can run in parallel</h4><ul><li>Each executor can run 5 tasks in parallel ( 5 Cores each) and and with 3 executors in each node, 15 tasks can run in parallel on a node.</li><li>Across the cluster, we have one executor alloted to yarn manager. so, 29 *5 , 145 tasks can run in parallel.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*yhd4rKHi4hcaa7wU5VV3PA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cba87f3de78d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache Spark — caching a RDD]]></title>
            <link>https://medium.com/@swethamurali03/apache-spark-caching-a-rdd-f22159517efe?source=rss-d534d6a5dcd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f22159517efe</guid>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[rdd]]></category>
            <dc:creator><![CDATA[swetha murali]]></dc:creator>
            <pubDate>Fri, 15 Dec 2023 15:53:31 GMT</pubDate>
            <atom:updated>2023-12-15T23:53:39.234Z</atom:updated>
            <content:encoded><![CDATA[<h3>Apache Spark — caching a RDD</h3><p>Generally we cache data, so they can be accessed faster. Same Concept goes here as well.</p><p>Suppose we do 10 transformations which are costly and the resultant RDD needs to be used again and again, we can cache it.</p><p>We do cache once we have done considerable amount of processing and resultant RDD is small / medium, sized and need to be reused.</p><p>Caching is lazy, which means, caching happens after the 1st exectution. Things get faster from 2nd execution.</p><p><strong>Note :</strong> At the time of caching, if enough memory is not available, caching gets skipped. We do not see error message. Caching is meant for optimisation and not a show stopper and hence they get skipped.</p><p>we see green circle in the DAG visualisation when a RDD gets cached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*Pi16fdrpkoZDh-yuHlKjSg.png" /></figure><p>Lets consider below code. Basically we are trying to take a particular column , mapping it with 1 and reducing it based on key by adding the values, which ideally gets count for each of the key.</p><p>we are collecting the resultant rdd3 twice. lets see DAG visualisation.</p><pre>load_rdd1 = spark.sparkContext.textFile(&quot;&lt;PATH&gt;&quot;)<br>split_and_take_status_column_rdd2 = load_rdd1.map(lambda line: (line.split(&quot;,&quot;)[3],1))<br>count_on_each_category_rdd3 = split_and_take_status_rdd2.reduceByKey(lambda x,y : x+y)<br>count_on_each_category_rdd3.cache()<br>count_on_each_category_rdd3.collect()<br>count_on_each_category_rdd3.collect()<br>spark.stop()</pre><p>We see two Collect operation and 2nd collect has skipped task and clearly see some time difference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OiJFSi-ToSAsTBYFcneFhw.png" /></figure><p>We can also notice stage one is being greyed out on DAG visualisation of the 2nd collect operation and reduceBy is being skipped as we had cached the rdd.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ov2pszoy5KtBytHExdhqw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f22159517efe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache Spark — RDDs]]></title>
            <link>https://medium.com/@swethamurali03/apache-spark-rdds-cd6736b3714d?source=rss-d534d6a5dcd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd6736b3714d</guid>
            <category><![CDATA[rdd-transformation]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[swetha murali]]></dc:creator>
            <pubDate>Fri, 15 Dec 2023 14:42:23 GMT</pubDate>
            <atom:updated>2024-01-22T04:06:26.641Z</atom:updated>
            <content:encoded><![CDATA[<h3>Apache Spark — Resilience and fault tolerance — RDDs and DAGs make it!</h3><p>Spark jobs are typically executed against RDDs (Resilient Distributed Dataset). They are the basic units which hold records of data that is distributed across the cluster.</p><p>Say we have a file sample-file.csv, that has 4 partitions (file is split into 4 parts)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*1RYXUmDWmvik70ZJYfCRXg.png" /></figure><p>and, we a have 4 worker node cluster, the distributed collection P1,P2,P3 and P4 form a RDD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*p5WQ-pBcATW-Zs0-3t0qtA.png" /></figure><h3>Role of DAG</h3><h4><strong>Making spark resilient and fault tolerant</strong></h4><p>RDDs are immutable, which means they cannot be changed. For any transformation, we get a new RDD.</p><p>Say we have the sample-file.csv,</p><ol><li>we load it. A RDD gets created. Lets call it RDD_1</li><li>we do a map transformation — a new RDD gets generated. — RDD_2</li><li>We do one more transformation, say a filter — a new RDD gets generated. — RDD_3</li><li>we collect the result.</li></ol><p>Now a plan, also called <strong>DAG </strong>(Directed Acyclic Graph) gets created for the above steps.</p><p>Load -&gt; map -&gt; Filter -&gt; Collect.</p><p>This DAG helps is maintaining the linear flow and any RDD can get regenerated from its parent RDD, even when we lose on a RDD, hence giving resilience.</p><p>This immutability and DAG together makes spark resilient and fault tolerant.</p><h4>Optimised Execution</h4><p><strong>Transformations are made lazy,</strong> which means, they get executed upon a action. In our case, they get executed when we do collect operation. This lazyness helps spark to optimise its way of execution. Since we have DAG at hand, spark can decide which one to exectute first for a faster processing.</p><p>For example, we have a million record, do map and then do a filter which ends up giving, 5 records back, we can filter first, and take up map transformation instead of loading all the million record into memory and processing them on map.</p><p>Spark is intelligent enough to handle this kind of optimisations and this is achievable by making <strong>transformations lazy and maintaining them in a DAG</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd6736b3714d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Thailand.]]></title>
            <link>https://medium.com/@swethamurali03/exploring-thailand-10cdd663e256?source=rss-d534d6a5dcd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/10cdd663e256</guid>
            <category><![CDATA[khao-sok]]></category>
            <category><![CDATA[thailand]]></category>
            <category><![CDATA[travel]]></category>
            <dc:creator><![CDATA[swetha murali]]></dc:creator>
            <pubDate>Wed, 17 Jul 2019 05:42:40 GMT</pubDate>
            <atom:updated>2021-08-09T10:53:17.316Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exploring Thailand - Khao Sok.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*KK2ne9uVIiJsfXoHBo6nSA.png" /></figure><p>Khao Sok is an ancient rainforest which is a 3hr drive from Krabi. It is one of the beautiful places in Thailand with stunning views. It is Thailand&#39;s best-kept secret and a paradise for nature lovers.</p><p>There are lots of activities like jungle trekking, canoeing, tubing, camping, elephant bathing, bird watching, and more. A One-day lake tour can give you a complete forest experience.</p><p>Our tour started with an hour boat ride on Cheow Larn Lake which gave us out-of-the-world views. The ride took us to row houses/floating houses where we started preparing for the 3hr trek.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*f8RPhwOMjEHBSoHkzPvrFQ.png" /><figcaption>some pics from our trek :)</figcaption></figure><p>We recommend getting shoes for trekking for rent (50 batt) from the tour guide themselves as they will get really muddy on the trek and the pathway will be too slippery. End of the trek We entered a cave called ‘Namtalu<strong>’</strong>. Entry to the cave depends on the weather.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bZlFp6TfpH-okV1lqlcqiA.jpeg" /><figcaption>row house on the lake Cheow Larn</figcaption></figure><p>Back from the trek, we will have an hour&#39;s stop at the row house. we can either swim or kayak in the lake. The water is so warm, so pure, never miss the swimming.</p><p>They serve awesome food for lunch which was divine after the long, tiring, and strenuous trek. They serve golden roasted fish from the lake. Though we are vegetarians, we noticed people enjoying it a lot.</p><p><strong>More information on the trip</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8X7G1xCSL6BuJrtfnAEP_g.jpeg" /><figcaption>Agenda of one-day lake trip</figcaption></figure><p><strong>Some recommendations </strong>:</p><p><strong>Be on time</strong>. Make sure to be on time. People are really keen on timings.</p><p><strong>Insect repellents</strong>. Suggest getting repellents. There is a stop in the market before entering the forest. we can get in 711.</p><p><strong>Rent trekking shoes</strong>. Best to get the trekking shoes that they rent out. The pathway is very very muddy and slippery. The rent is 50Batt.</p><p><strong>Get Muddy.</strong> Put your leg into muddy swamps. When we do not do that, we will end up walking on corners and which are slippery and we end up losing balance and fall off.</p><p><strong>Don&#39;t expect proper toilet</strong>s. Let&#39;s understand we are going to a forest and adjust and adapt to the situation. Carry tissues if you are a tissue person.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10cdd663e256" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>