title: Memory Bloating while Caching in Spark
body: <p>I have a 5 node cluster each having 132 GB physical memory and managed by Cloudera. However, both the properties <code>yarn.nodemanager.resource.memory-mb</code> and <code>yarn.scheduler.maximum-allocation-mb</code> have been set to 100 GB. I am submitting the job with 5 executors, 5 cores per executor and 40 GB of memory per executor. This code is just taking the file which is 16 GB in size and making it into RDD and caching it as follows</p>
  
  <pre><code>try {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          System.out.println("Enter the file name");
          String file = br.readLine();
  
          // getting the context and spark configuration
          SparkConf sparkConf = new SparkConf();
          JavaSparkContext ctx = new JavaSparkContext(sparkConf);
  
          // getting the input file into JavaRDD of strings
          JavaRDD&lt;String&gt; lines = ctx.textFile("hdfs:/root/utkarsh/stark/" + file).cache();
          lines.count();
          ctx.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>While running I am observing the physical memory consumption of the 3 nodes running 2+2+1 executors respectively. The peak memory for the nodes are 54, 26, 48 GB respectively.</p>
  
  <p>Why does the memory bloat whereas my input is only 16 GB.</p>
  
  <p>Thanks in Advance!!</p>