<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/Memory+Management">Memory Management</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~shawkins">Steven Hawkins</a>
    </h4>
        <br/>
                         <h4>Changes (4)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{info} <br></td></tr>
            <tr><td class="diff-changed-lines" >With default settings and an 8GB VM size, then _max-reserve-kb_ will at a max <span class="diff-changed-words">use<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">,</span><span class="diff-added-chars"style="background-color: #dfd;">:</span></span> (((1024-300) * 0.5) + (7 * 1024 * 0.75)) = 5738 MB or 5875712 KB <br></td></tr>
            <tr><td class="diff-unchanged" >{info} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >*max-processing-kb* (default \-1) - setting determines the total size in kilobytes of batches that can be <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">used</span> <span class="diff-added-words"style="background-color: #dfd;">guaranteed for use</span> by _one_ active plan <span class="diff-added-words"style="background-color: #dfd;">and</span> may be in addition to the memory held based on _max-reserve-kb_. Typical minimum memory required by Teiid when all the active plans are active is _\#active-plans*max-processing-kb_. The default value of \-1 will auto-calculate a typical max based upon the max heap available to the VM and max active plans. The auto-calculated value assumes a 64bit architecture and will limit processing batch usage to 10% of memory beyond the first 300 megabytes (which are assumed for use by the AS and other Teiid purposes). <br></td></tr>
            <tr><td class="diff-unchanged" > <br>In systems where large intermediate results are normal (scrolling cursors or sorting over millions of rows) you can consider increasing the _max-processing-kb_ and decreasing the _max-reserve-kb_ so that each request has access to an effectively smaller buffer space. <br> <br>{info} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">With default setting and 20 active-plans, if you have 8GB VM size, then _max-processing-kb_ will, at a max, use (((1024-300) * 0.1) + (7 * 1024 * 0.1)) = 789.2 KB/20 = 39.46 KB. When all plans are not active then individual plans size can grow between 39 KB to 789 KB. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">With default settings including 20 active-plans and an 8GB VM size, then _max-processing-kb_ will be: (((1024-300) * 0.1) + (7 * 1024 * 0.1))/20 = 789.2 MB/20 = 39.46 MB or 40407 KB per plan. This implies a range between 0 and 789 MB that may be reserved with roughly 40 MB per plan. <br></td></tr>
            <tr><td class="diff-unchanged" >{info} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>The <em>BufferManager</em> is responsible for tracking both memory and disk usage by Teiid. Configuring the <em>BufferManager</em> properly is one of the most important parts of ensuring high performance. Execute following command on CLI to find all possible settings on <em>BufferManager</em></p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
/subsystem=teiid:read-resource-description
</pre>
</div></div>

<p>All the properties that start with "buffer-service" configure <em>BufferManager</em>. Some of them are described below. The Teiid engine uses batching to reduce the number of memory rows processed at a given time. The batch sizes may be adjusted to larger values as more clients will be accessing the Teiid server simultaneously.</p>

<p><b>max-reserve-kb</b> (default &#45;1) - setting determines the total size in kilobytes of batches that can be held by the <em>BufferManager</em> in memory. This number does not account for persistent batches held by soft (such as index pages) or weak references. The default value of &#45;1 will auto-calculate a typical max based upon the max heap available to the VM. The auto-calculated value assumes a 64bit architecture and will limit buffer usage to 50% of the first gigabyte of memory beyond the first 300 megabytes (which are assumed for use by the AS and other Teiid purposes) and 75% of the memory beyond that.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>With default settings and an 8GB VM size, then <em>max-reserve-kb</em> will at a max use: (((1024-300) * 0.5) + (7 * 1024 * 0.75)) = 5738 MB or 5875712 KB</td></tr></table></div>

<p>The <em>BufferManager</em> automatically triggers the use of a canonical value cache if enabled when more than 25% of the reserve is in use. This can dramatically cut the memory usage in situations where similar value sets are being read through Teiid, but does introduce a lookup cost. If you are processing small or highly similar datasets through Teiid, and wish to conserve memory, you should consider enabling <a href="#MemoryManagement-SystemProperties">value caching</a>.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Memory consumption can be significantly more or less than the nominal target depending upon actual column values and whether <a href="#MemoryManagement-SystemProperties">value caching</a> is enabled.  Large non built-in type objects can exceed their default size estimate. If an out of memory errors occur, then set a lower <em>max-reserve-kb</em> value.  Also note that source lob values are held by memory references that are not cleared when a batch is persisted. With heavy lob usage you should ensure that buffers of other memory associated with lob references are appropriately sized.</td></tr></table></div>


<p><b>max-processing-kb</b> (default &#45;1) - setting determines the total size in kilobytes of batches that can be guaranteed for use by <em>one</em> active plan and may be in addition to the memory held based on <em>max-reserve-kb</em>. Typical minimum memory required by Teiid when all the active plans are active is <em>&#35;active-plans*max-processing-kb</em>. The default value of &#45;1 will auto-calculate a typical max based upon the max heap available to the VM and max active plans. The auto-calculated value assumes a 64bit architecture and will limit processing batch usage to 10% of memory beyond the first 300 megabytes (which are assumed for use by the AS and other Teiid purposes).</p>

<p>In systems where large intermediate results are normal (scrolling cursors or sorting over millions of rows) you can consider increasing the <em>max-processing-kb</em> and decreasing the <em>max-reserve-kb</em> so that each request has access to an effectively smaller buffer space.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>With default settings including 20 active-plans and an 8GB VM size, then <em>max-processing-kb</em> will be: (((1024-300) * 0.1) + (7 * 1024 * 0.1))/20 = 789.2 MB/20 = 39.46 MB or 40407 KB per plan. This implies a range between 0 and 789 MB that may be reserved with roughly 40 MB per plan.</td></tr></table></div>


<p><b>max-file-size</b> (default 2GB) - Each intermediate result buffer, temporary LOB, and temporary table is stored in its own set of buffer files, where an individual file is limited to <em>max-file-size</em> megabytes. Consider increasing the storage space available to all such files by increasing&nbsp;<em>max-buffer-space,</em> if your installation makes use of internal materialization, makes heavy use of SQL/XML, or processes large row counts.</p>


<h1><a name="MemoryManagement-BigData%2FMemory"></a>Big Data/Memory</h1>

<p><b>processor-batch-size</b> (default 512) - Specifies the max row count of a batch sent internally within the query processor. &nbsp;Should be &lt;= the <b>connector-batch-size</b> (default 1024) - Additional considerations are needed if extremely large VM sizes and or datasets are being used. Teiid has a non-negligible amount of overhead per batch/table page on the order of 100-200 bytes.  Depending on the data types involved each full batch/table page will represent a variable number of rows (a power of two multiple above or below the processor batch size).  If you are dealing with datasets with billions of rows and you run into OutOfMemory issues, consider increasing the <em>processor-batch-size</em> to force the allocation of larger batches and table pages. &nbsp;</p>

<p><b>max-storage-object-size</b> (default 8288608 or 8MB) - The maximum size of a buffered managed object in bytes and represents the individual batch page size. If the <em>processor-batch-size</em> is increased and/or you are dealing with extremely wide result sets (several hundred columns), then the default setting of 8MB for the <em>max-storage-object-size</em> may be too low.  The inline-lobs also account in this size if batch contains them. The sizing for <em>max-storage-object-size</em> is in terms of serialized size, which will be much closer to the raw data size than the Java memory footprint estimation used for <em>max-reserved-kb</em>. <em>max-storage-object-size</em> should not be set too large relative to <em>memory-buffer-space</em> since it will reduce the performance of the memory buffer.  The memory buffer supports only 1 concurrent writer for each <em>max-storage-object-size</em> of the <em>memory-buffer-space</em>.</p>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Teiid temporary tables (also used for internal materialization) can only support 2^31-1 rows per table.</td></tr></table></div>

<p><b>memory-buffer-space</b> (default &#45;1) - This controls the amount of on or off heap memory allocated as byte buffers for use by the Teiid buffer manager.  This setting defaults to &#45;1, which automatically determines a setting based upon whether it is on or off heap and the value for <em>max-reserve-kb</em>.</p>

<p><b>memory-buffer-off-heap</b> (default false) - Take advantage of the <em>BufferManager</em> memory buffer to access system memory without allocating it to the heap.  Setting <em>memory-buffer-off-heap</em> to "true" will allocate the Teiid memory buffer off heap.  Depending on whether your installation is dedicated to Teiid and the amount of system memory available, this may be preferable to on-heap allocation.  The primary benefit is additional memory usage for Teiid without additional garbage collection tuning.  This becomes especially important in situations where more than 32GB of memory is desired for the VM. Note that when using off-heap allocation, the memory must still be available to the java process and that setting the value of <em>memory-buffer-space</em> too high may cause the VM to swap rather than reside in memory. With large off-heap buffer sizes (greater than several gigabytes) you may also need to adjust VM settings.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Sun VM</b><br />For Sun VMs the relevant VM settings are MaxDirectMemorySize and UseLargePages.  For example adding:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
-XX:MaxDirectMemorySize=12g -XX:+UseLargePages
</pre>
</div></div>

<p>to the VM process arguments would allow for an effective allocation of approximately an 11GB Teiid memory buffer (the <b>memory-buffer-space</b> setting) accounting for any additional direct memory that may be needed by the AS or applications running in the AS.</p></td></tr></table></div>




<h1><a name="MemoryManagement-DiskUsage"></a>Disk Usage</h1>

<p><b>max-buffer-space</b> (default &#45;1) - For table page and result batches the buffer manager will have a limited number of files that are dedicated to a particular storage size. However, as mentioned in the installation, creation of Teiid lob values (for example through SQL/XML) will typically create one file per lob once the lob exceeds the allowable in memory size of 8KB.  In heavy usage scenarios, consider pointing the buffer directory on a partition that is routinely defragmented. By default Teiid will use up to 50GB of disk space.  This is tracked in terms of the number of bytes written by Teiid.  For large data sets, you may need to increase the <em>max-buffer-space</em> setting.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://docs.jboss.org/author/display/TEIID/Memory+Management">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=18646070&revisedVersion=10&originalVersion=9">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Memory+Management?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>