blob: a40d1667147a09aef87c595dad4463c802ec60f0 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SortMemoryManager (Drill : 1.20.3 API)</title>
<link rel="stylesheet" type="text/css" href="../../../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="SortMemoryManager (Drill : 1.20.3 API)";
}
}
catch(err) {
}
//-->
var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":9,"i19":10};
var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/SortMemoryManager.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortImpl.SortResults.html" title="interface in org.apache.drill.exec.physical.impl.xsort"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.BatchSizeEstimate.html" title="class in org.apache.drill.exec.physical.impl.xsort"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../../../index.html?org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html" target="_top">Frames</a></li>
<li><a href="SortMemoryManager.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li><a href="#nested.class.summary">Nested</a>&nbsp;|&nbsp;</li>
<li><a href="#field.summary">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#field.detail">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.drill.exec.physical.impl.xsort</div>
<h2 title="Class SortMemoryManager" class="title">Class SortMemoryManager</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</a></li>
<li>
<ul class="inheritance">
<li>org.apache.drill.exec.physical.impl.xsort.SortMemoryManager</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>public class <span class="typeNameLabel">SortMemoryManager</span>
extends <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></pre>
<div class="block">Computes the memory needs for input batches, spill batches and merge
batches. The key challenges that this code tries to overcome are:
<ul>
<li>Drill is not designed for the small memory allocations,
but the planner may provide such allocations because the memory per
query is divided among slices (minor fragments) and among buffering
operators, leaving very little per operator.</li>
<li>Drill does not provide the detailed memory information needed to
carefully manage memory in tight constraints.</li>
<li>But, Drill has a death penalty for going over the memory limit.</li>
</ul>
As a result, this class is a bit of a hack: it attempt to consider a
number of ill-defined factors in order to divide up memory use in a
way that prevents OOM errors.
<p>
First, it is necessary to differentiate two concepts:
<ul>
<li>The <i>data size</i> of a batch: the amount of memory needed to hold
the data itself. The data size is constant for any given batch.</li>
<li>The <i>buffer size</i> of the buffers that hold the data. The buffer
size varies wildly depending on how the batch was produced.</li>
</ul>
The three kinds of buffer layouts seen to date include:
<ul>
<li>One buffer per vector component (data, offsets, null flags, etc.)
&ndash; create by readers, project and other operators.</li>
<li>One buffer for the entire batch, with each vector component using
a slice of the overall buffer. &ndash; case for batches deserialized from
exchanges.</li>
<li>One buffer for each top-level vector, with component vectors
using slices of the overall vector buffer &ndash; the result of reading
spilled batches from disk.</li>
</ul>
In each case, buffer sizes are power-of-two rounded from the data size.
But since the data is grouped differently in each case, the resulting buffer
sizes vary considerably.
<p>
As a result, we can never be sure of the amount of memory needed for a
batch. So, we have to estimate based on a number of factors:
<ul>
<li>Uses the <a href="../../../../../../../org/apache/drill/exec/record/RecordBatchSizer.html" title="class in org.apache.drill.exec.record"><code>RecordBatchSizer</code></a> to estimate the data size and
buffer size of each incoming batch.</li>
<li>Estimates the internal fragmentation due to power-of-two rounding.</li>
<li>Configured preferences for spill and output batches.</li>
</ul>
The code handles "normal" and "low" memory conditions.
<ul>
<li>In normal memory, we simply work out the number of preferred-size
batches that fit in memory (based on the predicted buffer size.)</li>
<li>In low memory, we divide up the available memory to produce the
spill and merge batch sizes. The sizes will be less than the configured
preference.</li>
</ul>
<p>
The sort has two key configured parameters: the spill file size and the
size of the output (downstream) batch. The spill file size is chosen to
be large enough to ensure efficient I/O, but not so large as to overwhelm
any one spill directory. The output batch size is chosen to be large enough
to amortize the per-batch overhead over the maximum number of records, but
not so large as to overwhelm downstream operators. Setting these parameters
is a judgment call.
<p>
Under limited memory, the above sizes may be too big for the space available.
For example, the default spill file size is 256 MB. But, if the sort is
only given 50 MB, then spill files will be smaller. The default output batch
size is 16 MB, but if the sort is given only 20 MB, then the output batch must
be smaller. The low memory logic starts with the memory available and works
backwards to figure out spill batch size, output batch size and spill file
size. The sizes will be smaller than optimal, but as large as will fit in
the memory provided.</div>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== NESTED CLASS SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="nested.class.summary">
<!-- -->
</a>
<h3>Nested Class Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Nested Class Summary table, listing nested classes, and an explanation">
<caption><span>Nested Classes</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Class and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static class&nbsp;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.BatchSizeEstimate.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortMemoryManager.BatchSizeEstimate</a></span></code>&nbsp;</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static class&nbsp;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.MergeAction.html" title="enum in org.apache.drill.exec.physical.impl.xsort">SortMemoryManager.MergeAction</a></span></code>&nbsp;</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static class&nbsp;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.MergeTask.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortMemoryManager.MergeTask</a></span></code>&nbsp;</td>
</tr>
</table>
</li>
</ul>
<!-- =========== FIELD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="field.summary">
<!-- -->
</a>
<h3>Field Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Field Summary table, listing fields, and an explanation">
<caption><span>Fields</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Field and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static double</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#BUFFER_FROM_PAYLOAD">BUFFER_FROM_PAYLOAD</a></span></code>
<div class="block">Given a data size, this is the multiplier to create the buffer
size estimate.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static double</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#INTERNAL_FRAGMENTATION_ESTIMATE">INTERNAL_FRAGMENTATION_ESTIMATE</a></span></code>
<div class="block">Estimate for typical internal fragmentation in a buffer due to power-of-two
rounding on vectors.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static double</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#LOW_MEMORY_MERGE_BATCH_RATIO">LOW_MEMORY_MERGE_BATCH_RATIO</a></span></code>&nbsp;</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#MIN_ROWS_PER_SORT_BATCH">MIN_ROWS_PER_SORT_BATCH</a></span></code>
<div class="block">Desperate attempt to keep spill batches from being too small in low memory.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static double</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#PAYLOAD_FROM_BUFFER">PAYLOAD_FROM_BUFFER</a></span></code>
<div class="block">Given a buffer, this is the assumed amount of space
available for data.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static double</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#WORST_CASE_BUFFER_RATIO">WORST_CASE_BUFFER_RATIO</a></span></code>
<div class="block">On really bad days, we will add one more byte (or value) to a vector
than fits in a power-of-two sized buffer, forcing a doubling.</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#SortMemoryManager-org.apache.drill.exec.physical.impl.xsort.SortConfig-long-">SortMemoryManager</a></span>(<a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortConfig.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortConfig</a>&nbsp;config,
long&nbsp;opMemoryLimit)</code>&nbsp;</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t1" class="tableTab"><span><a href="javascript:show(1);">Static Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.MergeTask.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortMemoryManager.MergeTask</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#consolidateBatches-long-int-int-">consolidateBatches</a></span>(long&nbsp;allocMemory,
int&nbsp;inMemCount,
int&nbsp;spilledRunsCount)</code>
<div class="block">Choose a consolidation option during the merge phase depending on memory
available.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>long</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#freeMemory-long-">freeMemory</a></span>(long&nbsp;allocatedBytes)</code>&nbsp;</td>
</tr>
<tr id="i2" class="altColor">
<td class="colFirst"><code>long</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#getBufferMemoryLimit--">getBufferMemoryLimit</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i3" class="rowColor">
<td class="colFirst"><code><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.BatchSizeEstimate.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortMemoryManager.BatchSizeEstimate</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#getInputBatchSize--">getInputBatchSize</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i4" class="altColor">
<td class="colFirst"><code>long</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#getMemoryLimit--">getMemoryLimit</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i5" class="rowColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#getMergeBatchRowCount--">getMergeBatchRowCount</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i6" class="altColor">
<td class="colFirst"><code><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.BatchSizeEstimate.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortMemoryManager.BatchSizeEstimate</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#getMergeBatchSize--">getMergeBatchSize</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i7" class="rowColor">
<td class="colFirst"><code>long</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#getMergeMemoryLimit--">getMergeMemoryLimit</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i8" class="altColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#getPreferredMergeBatchSize--">getPreferredMergeBatchSize</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i9" class="rowColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#getPreferredSpillBatchSize--">getPreferredSpillBatchSize</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i10" class="altColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#getRowWidth--">getRowWidth</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i11" class="rowColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#getSpillBatchRowCount--">getSpillBatchRowCount</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i12" class="altColor">
<td class="colFirst"><code><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.BatchSizeEstimate.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortMemoryManager.BatchSizeEstimate</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#getSpillBatchSize--">getSpillBatchSize</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i13" class="rowColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#hasMemoryMergeCapacity-long-long-">hasMemoryMergeCapacity</a></span>(long&nbsp;allocatedBytes,
long&nbsp;neededForInMemorySort)</code>&nbsp;</td>
</tr>
<tr id="i14" class="altColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#hasPerformanceWarning--">hasPerformanceWarning</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i15" class="rowColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#isLowMemory--">isLowMemory</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i16" class="altColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#isSpillNeeded-long-long-">isSpillNeeded</a></span>(long&nbsp;allocatedBytes,
long&nbsp;incomingSize)</code>&nbsp;</td>
</tr>
<tr id="i17" class="rowColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#mayOverflow--">mayOverflow</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i18" class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#multiply-int-double-">multiply</a></span>(int&nbsp;byteSize,
double&nbsp;multiplier)</code>&nbsp;</td>
</tr>
<tr id="i19" class="rowColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html#updateEstimates-int-int-int-">updateEstimates</a></span>(int&nbsp;batchDataSize,
int&nbsp;batchRowWidth,
int&nbsp;batchRowCount)</code>
<div class="block">Update the data-driven memory use numbers including:
The average size of incoming records.
The estimated spill and output batch size.
The estimated number of average-size records per
spill and output batch.
The amount of memory set aside to hold the incoming
batches before spilling starts.
</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></h3>
<code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#clone--" title="class or interface in java.lang">clone</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#equals-java.lang.Object-" title="class or interface in java.lang">equals</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#finalize--" title="class or interface in java.lang">finalize</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#getClass--" title="class or interface in java.lang">getClass</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#hashCode--" title="class or interface in java.lang">hashCode</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notify--" title="class or interface in java.lang">notify</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notifyAll--" title="class or interface in java.lang">notifyAll</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#toString--" title="class or interface in java.lang">toString</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait--" title="class or interface in java.lang">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait-long-" title="class or interface in java.lang">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait-long-int-" title="class or interface in java.lang">wait</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ FIELD DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="field.detail">
<!-- -->
</a>
<h3>Field Detail</h3>
<a name="INTERNAL_FRAGMENTATION_ESTIMATE">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>INTERNAL_FRAGMENTATION_ESTIMATE</h4>
<pre>public static final&nbsp;double INTERNAL_FRAGMENTATION_ESTIMATE</pre>
<div class="block">Estimate for typical internal fragmentation in a buffer due to power-of-two
rounding on vectors.
<p>
<p>
<pre>[____|__$__]</pre>
In the above, the brackets represent the whole vector. The
first half is always full. The $ represents the end of data.
When the first half filled, the second
half was allocated. On average, the second half will be half full.
This means that, on average, 1/4 of the allocated space is
unused (the definition of internal fragmentation.)</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../../../constant-values.html#org.apache.drill.exec.physical.impl.xsort.SortMemoryManager.INTERNAL_FRAGMENTATION_ESTIMATE">Constant Field Values</a></dd>
</dl>
</li>
</ul>
<a name="PAYLOAD_FROM_BUFFER">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>PAYLOAD_FROM_BUFFER</h4>
<pre>public static final&nbsp;double PAYLOAD_FROM_BUFFER</pre>
<div class="block">Given a buffer, this is the assumed amount of space
available for data. (Adding more will double the buffer
size half the time.)</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../../../constant-values.html#org.apache.drill.exec.physical.impl.xsort.SortMemoryManager.PAYLOAD_FROM_BUFFER">Constant Field Values</a></dd>
</dl>
</li>
</ul>
<a name="BUFFER_FROM_PAYLOAD">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>BUFFER_FROM_PAYLOAD</h4>
<pre>public static final&nbsp;double BUFFER_FROM_PAYLOAD</pre>
<div class="block">Given a data size, this is the multiplier to create the buffer
size estimate. (Note: since we work with aggregate batches, we
cannot simply round up to the next power of two: rounding is done
on a vector-by-vector basis. Here we need to estimate the aggregate
effect of rounding.</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../../../constant-values.html#org.apache.drill.exec.physical.impl.xsort.SortMemoryManager.BUFFER_FROM_PAYLOAD">Constant Field Values</a></dd>
</dl>
</li>
</ul>
<a name="WORST_CASE_BUFFER_RATIO">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>WORST_CASE_BUFFER_RATIO</h4>
<pre>public static final&nbsp;double WORST_CASE_BUFFER_RATIO</pre>
<div class="block">On really bad days, we will add one more byte (or value) to a vector
than fits in a power-of-two sized buffer, forcing a doubling. In this
case, half the resulting buffer is empty.</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../../../constant-values.html#org.apache.drill.exec.physical.impl.xsort.SortMemoryManager.WORST_CASE_BUFFER_RATIO">Constant Field Values</a></dd>
</dl>
</li>
</ul>
<a name="MIN_ROWS_PER_SORT_BATCH">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>MIN_ROWS_PER_SORT_BATCH</h4>
<pre>public static final&nbsp;int MIN_ROWS_PER_SORT_BATCH</pre>
<div class="block">Desperate attempt to keep spill batches from being too small in low memory.
<p>
The number is also used for logging: the system will log a warning if
batches fall below this number which may represent too little memory
allocated for the job at hand. (Queries operate on big data: many records.
Batches with too few records are a probable performance hit. But, what is
too few? It is a judgment call.)</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../../../constant-values.html#org.apache.drill.exec.physical.impl.xsort.SortMemoryManager.MIN_ROWS_PER_SORT_BATCH">Constant Field Values</a></dd>
</dl>
</li>
</ul>
<a name="LOW_MEMORY_MERGE_BATCH_RATIO">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>LOW_MEMORY_MERGE_BATCH_RATIO</h4>
<pre>public static final&nbsp;double LOW_MEMORY_MERGE_BATCH_RATIO</pre>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../../../constant-values.html#org.apache.drill.exec.physical.impl.xsort.SortMemoryManager.LOW_MEMORY_MERGE_BATCH_RATIO">Constant Field Values</a></dd>
</dl>
</li>
</ul>
</li>
</ul>
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a name="SortMemoryManager-org.apache.drill.exec.physical.impl.xsort.SortConfig-long-">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>SortMemoryManager</h4>
<pre>public&nbsp;SortMemoryManager(<a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortConfig.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortConfig</a>&nbsp;config,
long&nbsp;opMemoryLimit)</pre>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="updateEstimates-int-int-int-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>updateEstimates</h4>
<pre>public&nbsp;boolean&nbsp;updateEstimates(int&nbsp;batchDataSize,
int&nbsp;batchRowWidth,
int&nbsp;batchRowCount)</pre>
<div class="block">Update the data-driven memory use numbers including:
<ul>
<li>The average size of incoming records.</li>
<li>The estimated spill and output batch size.</li>
<li>The estimated number of average-size records per
spill and output batch.</li>
<li>The amount of memory set aside to hold the incoming
batches before spilling starts.</li>
</ul>
<p>
Under normal circumstances, the amount of memory available is much
larger than the input, spill or merge batch sizes. The primary question
is to determine how many input batches we can buffer during the load
phase, and how many spill batches we can merge during the merge
phase.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>batchDataSize</code> - the overall size of the current batch received from
upstream</dd>
<dd><code>batchRowWidth</code> - the average width in bytes (including overhead) of
rows in the current input batch</dd>
<dd><code>batchRowCount</code> - the number of actual (not filtered) records in
that upstream batch</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>true if the estimates changed, false if the previous estimates
remain valid</dd>
</dl>
</li>
</ul>
<a name="consolidateBatches-long-int-int-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>consolidateBatches</h4>
<pre>public&nbsp;<a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.MergeTask.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortMemoryManager.MergeTask</a>&nbsp;consolidateBatches(long&nbsp;allocMemory,
int&nbsp;inMemCount,
int&nbsp;spilledRunsCount)</pre>
<div class="block">Choose a consolidation option during the merge phase depending on memory
available. Preference is given to moving directly onto merging (with no
additional spilling) when possible. But, if memory pressures don't allow
this, we must spill batches and/or merge on-disk spilled runs, to reduce
the final set of runs to something that can be merged in the available
memory.
<p>
Logic is here (returning an enum) rather than in the merge code to allow
unit testing without actually needing batches in memory.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>allocMemory</code> - amount of memory currently allocated (this class knows the total
memory available)</dd>
<dd><code>inMemCount</code> - number of incoming batches in memory (the number is important, not
the in-memory size; we get the memory size from
<tt>allocMemory</tt>)</dd>
<dd><code>spilledRunsCount</code> - the number of runs sitting on disk to be merged</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>whether to <tt>SPILL</tt> in-memory batches, whether to
<tt>MERGE<tt> on-disk batches to create a new, larger run, or whether
to do nothing (<tt>NONE</tt>) and instead advance to the final merge</dd>
</dl>
</li>
</ul>
<a name="multiply-int-double-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>multiply</h4>
<pre>public static&nbsp;int&nbsp;multiply(int&nbsp;byteSize,
double&nbsp;multiplier)</pre>
</li>
</ul>
<a name="isSpillNeeded-long-long-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>isSpillNeeded</h4>
<pre>public&nbsp;boolean&nbsp;isSpillNeeded(long&nbsp;allocatedBytes,
long&nbsp;incomingSize)</pre>
</li>
</ul>
<a name="hasMemoryMergeCapacity-long-long-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>hasMemoryMergeCapacity</h4>
<pre>public&nbsp;boolean&nbsp;hasMemoryMergeCapacity(long&nbsp;allocatedBytes,
long&nbsp;neededForInMemorySort)</pre>
</li>
</ul>
<a name="freeMemory-long-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>freeMemory</h4>
<pre>public&nbsp;long&nbsp;freeMemory(long&nbsp;allocatedBytes)</pre>
</li>
</ul>
<a name="getMergeMemoryLimit--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getMergeMemoryLimit</h4>
<pre>public&nbsp;long&nbsp;getMergeMemoryLimit()</pre>
</li>
</ul>
<a name="getSpillBatchRowCount--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getSpillBatchRowCount</h4>
<pre>public&nbsp;int&nbsp;getSpillBatchRowCount()</pre>
</li>
</ul>
<a name="getMergeBatchRowCount--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getMergeBatchRowCount</h4>
<pre>public&nbsp;int&nbsp;getMergeBatchRowCount()</pre>
</li>
</ul>
<a name="getMemoryLimit--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getMemoryLimit</h4>
<pre>public&nbsp;long&nbsp;getMemoryLimit()</pre>
</li>
</ul>
<a name="getRowWidth--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getRowWidth</h4>
<pre>public&nbsp;int&nbsp;getRowWidth()</pre>
</li>
</ul>
<a name="getInputBatchSize--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getInputBatchSize</h4>
<pre>public&nbsp;<a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.BatchSizeEstimate.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortMemoryManager.BatchSizeEstimate</a>&nbsp;getInputBatchSize()</pre>
</li>
</ul>
<a name="getPreferredSpillBatchSize--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getPreferredSpillBatchSize</h4>
<pre>public&nbsp;int&nbsp;getPreferredSpillBatchSize()</pre>
</li>
</ul>
<a name="getPreferredMergeBatchSize--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getPreferredMergeBatchSize</h4>
<pre>public&nbsp;int&nbsp;getPreferredMergeBatchSize()</pre>
</li>
</ul>
<a name="getSpillBatchSize--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getSpillBatchSize</h4>
<pre>public&nbsp;<a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.BatchSizeEstimate.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortMemoryManager.BatchSizeEstimate</a>&nbsp;getSpillBatchSize()</pre>
</li>
</ul>
<a name="getMergeBatchSize--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getMergeBatchSize</h4>
<pre>public&nbsp;<a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.BatchSizeEstimate.html" title="class in org.apache.drill.exec.physical.impl.xsort">SortMemoryManager.BatchSizeEstimate</a>&nbsp;getMergeBatchSize()</pre>
</li>
</ul>
<a name="getBufferMemoryLimit--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getBufferMemoryLimit</h4>
<pre>public&nbsp;long&nbsp;getBufferMemoryLimit()</pre>
</li>
</ul>
<a name="mayOverflow--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>mayOverflow</h4>
<pre>public&nbsp;boolean&nbsp;mayOverflow()</pre>
</li>
</ul>
<a name="isLowMemory--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>isLowMemory</h4>
<pre>public&nbsp;boolean&nbsp;isLowMemory()</pre>
</li>
</ul>
<a name="hasPerformanceWarning--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>hasPerformanceWarning</h4>
<pre>public&nbsp;boolean&nbsp;hasPerformanceWarning()</pre>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/SortMemoryManager.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortImpl.SortResults.html" title="interface in org.apache.drill.exec.physical.impl.xsort"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../../../org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.BatchSizeEstimate.html" title="class in org.apache.drill.exec.physical.impl.xsort"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../../../index.html?org/apache/drill/exec/physical/impl/xsort/SortMemoryManager.html" target="_top">Frames</a></li>
<li><a href="SortMemoryManager.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li><a href="#nested.class.summary">Nested</a>&nbsp;|&nbsp;</li>
<li><a href="#field.summary">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#field.detail">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>Copyright &#169; 1970 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p>
</body>
</html>