Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-7338

REST API calls to Drill fail due to insufficient heap memory




      Drill queries that use REST API calls have started failing(given below) after recent changes.

      RESOURCE ERROR: There is not enough heap memory to run this query using the web interface.
      Please try a query with fewer columns or with a filter or limit condition to limit the data returned.
      You can also try an ODBC/JDBC client.

      They were running fine earlier as the ResultSet returned was just few rows. These queries now fail for even very small resultSets( < 10rows).

      Investigating the issue revealed that we introduced a check to limit the Heap usage.

      The Wrapper code from exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryWrapper.java  that throws this error, i see certain issues. It does seem we use a threshold of 85% of heap usage before throwing that warning and exiting the query.


      public class QueryWrapper {
        private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(QueryWrapper.class);
        // Heap usage threshold/trigger to provide resiliency on web server for queries submitted via HTTP
        private static final double HEAP_MEMORY_FAILURE_THRESHOLD = 0.85;
        private static MemoryMXBean memMXBean = ManagementFactory.getMemoryMXBean();
        // Wait until the query execution is complete or there is error submitting the query
          logger.debug("Wait until the query execution is complete or there is error submitting the query");
          do {
            try {
              isComplete = webUserConnection.await(TimeUnit.SECONDS.toMillis(1)); //periodically timeout 1 sec to check heap
            } catch (InterruptedException e) {}
            usagePercent = getHeapUsage();
            if (usagePercent >  HEAP_MEMORY_FAILURE_THRESHOLD) {
              nearlyOutOfHeapSpace = true;
          } while (!isComplete && !nearlyOutOfHeapSpace);

      By using above check, we unintentionally invited all those issues that happen with Java’s Heap usage. JVM does try to make maximum usage of HEAP until Minor or Major GC kicks in i.e GC kicks after there is no more space left in heap(eden or young gen).

      The workarounds i can think of in order to resolve this issue are:

      1. Remove this check altogether so we know why it is filling up Heap.
      1. Advise the users to stop using REST for querying data.(We did this already). But not all users may not be happy with this suggestion. There could be few dynamic applications(dashboard, monitoring etc).
      1. Make the threshold high enough so that GC kicks in much better.

      If not above options, we have to tune the Heap sizes of drillbit. A quick fix would be to increase the threshold from 85% to 100%(option-3 above).

      For documentation
      New Drill configuration property - drill.exec.http.memory.heap.failure.threshold


        Issue Links



              kkhatua Kunal Khatua
              adityaar Aditya Allamraju
              Arina Ielchiieva Arina Ielchiieva
              0 Vote for this issue
              4 Start watching this issue