Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-5080 Create a memory-managed version of the External Sort operator
  3. DRILL-5022

ExternalSortBatch sets two different limits for "copier" memory

    XMLWordPrintableJSON

    Details

    • Type: Sub-task
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8.0
    • Fix Version/s: 1.11.0
    • Component/s: None
    • Labels:
      None

      Description

      The ExternalSortBatch (ESB) operator sorts rows and supports spilling to disk to operate within a set memory budget.

      A key step in disk-based sorting is to merge "runs" of previously-sorted records. ESB does this with a class created from the PriorityQueueCopierTemplate, called the "copier" in the code.

      The sort runs are represented by record batches, each with an indirection vector (AKA SelectionVector) that point to the records in sort order.

      The copier restructures the incoming runs: copying from the original batches (from positions given by the indirection vector) into new output vectors in sorted order. To do this work, the copier must allocate new vectors to hold the merged data. These vectors consume memory, and must fit into the overall memory budget assigned to the ESB.

      As it turns out, the ESB code has two conflicting ways of setting the limit. One is hard-coded:

        private static final int COPIER_BATCH_MEM_LIMIT = 256 * 1024;
      

      The other comes from config parameters:

        public static final long INITIAL_ALLOCATION = 10_000_000;
        public static final long MAX_ALLOCATION = 20_000_000;
      
          copierAllocator = oAllocator.newChildAllocator(oAllocator.getName() + ":copier",
              PriorityQueueCopier.INITIAL_ALLOCATION, PriorityQueueCopier.MAX_ALLOCATION);
      

      Strangely, the config parameters are used to set aside memory for the copier to use. But, the COPIER_BATCH_MEM_LIMIT is used to determine how large of a merged batch to actually create.

      The result is that we set aside 10 MB of memory, but use only 256K of it, wasting 9 MB.

      This ticket asks to:

      • Determine the proper merged batch size.
      • Use that limit to set the memory allocation for the copier.

      Elsewhere in Drill batch sizes tend to be on the order of 32K records. In the ESB, the low COPIER_BATCH_MEM_LIMIT tends to favor smaller batches: A test case has a row width of 114 bytes, and produces batches of just 2299 records. So, likely the proper choice is the larger 10 MB memory allocator limit.

        Attachments

          Activity

            People

            • Assignee:
              paul-rogers Paul Rogers
              Reporter:
              paul-rogers Paul Rogers
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: