<li><ahref="#Use_the_LAZY_PERSIST_Storage_Policy">Use the LAZY_PERSIST Storage Policy</a>
<ul>
<li><ahref="#Invoke_hdfs_storagepolicies_command_for_directories">Invoke hdfs storagepolicies command for directories</a></li>
<li><ahref="#Call_setStoragePolicy_method_for_directories">Call setStoragePolicy method for directories</a></li>
<li><ahref="#Pass_LAZY_PERSIST_CreateFlag_for_new_files">Pass LAZY_PERSIST CreateFlag for new files</a></li></ul></li></ul>
<section>
<h2><aname="Introduction"></a>Introduction</h2>
<p>HDFS supports writing to off-heap memory managed by the Data Nodes. The Data Nodes will flush in-memory data to disk asynchronously thus removing expensive disk IO and checksum computations from the performance-sensitive IO path, hence we call such writes <i>Lazy Persist</i> writes. HDFS provides best-effort persistence guarantees for Lazy Persist Writes. Rare data loss is possible in the event of a node restart before replicas are persisted to disk. Applications can choose to use Lazy Persist Writes to trade off some durability guarantees in favor of reduced latency.</p>
<p>This feature is available starting with Apache Hadoop 2.6.0 and was developed under Jira <aclass="externalLink"href="https://issues.apache.org/jira/browse/HDFS-6581">HDFS-6581</a>.</p>
<p>The target use cases are applications that would benefit from writing relatively low amounts of data (from a few GB up to tens of GBs depending on available memory) with low latency. Memory storage is for applications that run within the cluster and collocated with HDFS Data Nodes. We have observed that the latency overhead from network replication negates the benefits of writing to memory.</p>
<p>Applications that use Lazy Persist Writes will continue to work by falling back to DISK storage if memory is insufficient or unconfigured.</p></section><section>
<p>This section enumerates the administrative steps required before applications can start using the feature in a cluster.</p></section><section>
<h2><aname="Limit_RAM_used_for_replicas_in_Memory"></a>Limit RAM used for replicas in Memory</h2>
<p>First decide the amount of memory to be dedicated for replicas stored in memory. Set <code>dfs.datanode.max.locked.memory</code> accordingly in <code>hdfs-site.xml</code>. This is the same setting used by the <ahref="./CentralizedCacheManagement.html">Centralized Cache Management</a> feature. The Data Node will ensure that the combined memory used by Lazy Persist Writes and Centralized Cache Management does not exceed the amount configured in <code>dfs.datanode.max.locked.memory</code>.</p>
<p>E.g. To reserve 32 GB for in-memory replicas</p>
<p>This memory is not allocated by the Data Node on startup.</p>
<p>On Unix-like systems, the “locked-in-memory size” ulimit (<code>ulimit -l</code>) of the Data Node user also needs to be increased to match this parameter (see the related section on <ahref="./CentralizedCacheManagement.html#OS_Limits">OS Limits</a>). When setting this value, please remember that you will need space in memory for other things as well, such as the Data Node and application JVM heaps and the operating system page cache. You will also need memory for YARN containers if there is a YARN Node Manager process running on the same node as the Data Node.</p></section><section>
<h2><aname="Setup_RAM_Disks_on_Data_Nodes"></a>Setup RAM Disks on Data Nodes</h2>
<p>Initialize a RAM disk on each Data Node. The choice of RAM Disk allows better data persistence across Data Node process restarts. The following setup will work on most Linux distributions. Using RAM disks on other platforms is not currently supported.</p><section>
<p>Linux supports using two kinds of RAM disks - <code>tmpfs</code> and <code>ramfs</code>. The size of <code>tmpfs</code> is limited by the Linux kernel while <code>ramfs</code> grows to fill all available system memory. There is a downside to <code>tmpfs</code> since its contents can be swapped to disk under memory pressure. However many performance-sensitive deployments run with swapping disabled so we do not expect this to be an issue in practice.</p>
<p>HDFS currently supports using <code>tmpfs</code> partitions. Support for adding <code>ramfs</code> is in progress (See <aclass="externalLink"href="https://issues.apache.org/jira/browse/HDFS-8584">HDFS-8584</a>).</p></section><section>
<p>Mount the RAM Disk partition with the Unix <code>mount</code> command. E.g. to mount a 32 GB <code>tmpfs</code> partition under <code>/mnt/dn-tmpfs/</code></p>
<divclass="source">
<divclass="source">
<pre> sudo mount -t tmpfs -o size=32g tmpfs /mnt/dn-tmpfs/
</pre></div></div>
<p>It is recommended you create an entry in the <code>/etc/fstab</code> so the RAM Disk is recreated automatically on node restarts. Another option is to use a sub-directory under <code>/dev/shm</code> which is a <code>tmpfs</code> mount available by default on most Linux distributions. Ensure that the size of the mount is greater than or equal to your <code>dfs.datanode.max.locked.memory</code> setting else override it in <code>/etc/fstab</code>. Using more than one <code>tmpfs</code> partition per Data Node for Lazy Persist Writes is not recommended.</p></section><section>
<h3><aname="Tag_tmpfs_volume_with_the_RAM_DISK_Storage_Type"></a>Tag <code>tmpfs</code> volume with the RAM_DISK Storage Type</h3>
<p>Tag the <code>tmpfs</code> directory with the RAM_DISK storage type via the <code>dfs.datanode.data.dir</code> configuration setting in <code>hdfs-site.xml</code>. E.g. On a Data Node with three hard disk volumes <code>/grid/0</code>, <code>/grid/1</code> and <code>/grid/2</code> and a <code>tmpfs</code> mount <code>/mnt/dn-tmpfs</code>, <code>dfs.datanode.data.dir</code> must be set as follows:</p>
<p>This step is crucial. Without the RAM_DISK tag, HDFS will treat the <code>tmpfs</code> volume as non-volatile storage and data will not be saved to persistent storage. You will lose data on node restart.</p></section><section>
<h3><aname="Ensure_Storage_Policies_are_enabled"></a>Ensure Storage Policies are enabled</h3>
<p>Ensure that the global setting to turn on Storage Policies is enabled <ahref="ArchivalStorage.html#Configuration">as documented here</a>. This setting is on by default.</p></section></section><section>
<h2><aname="Use_the_LAZY_PERSIST_Storage_Policy"></a>Use the LAZY_PERSIST Storage Policy</h2>
<p>Applications indicate that HDFS can use Lazy Persist Writes for a file with the <code>LAZY_PERSIST</code> storage policy. Administrative privileges are <i>not</i> required to set the policy and it can be set in one of three ways.</p><section>
<h3><aname="Invoke_hdfs_storagepolicies_command_for_directories"></a>Invoke <code>hdfs storagepolicies</code> command for directories</h3>
<p>Setting the policy on a directory causes it to take effect for all new files in the directory. The <code>hdfs storagepolicies</code> command can be used to set the policy as described in the <ahref="ArchivalStorage.html#Storage_Policy_Commands">Storage Policies documentation</a>.</p>
<h3><aname="Call_setStoragePolicy_method_for_directories"></a>Call <code>setStoragePolicy</code> method for directories</h3>
<p>Starting with Apache Hadoop 2.8.0, an application can programmatically set the Storage Policy with <code>FileSystem.setStoragePolicy</code>. E.g.</p>