Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-4794

Improve Garbage Collection required by Provenance Repository


    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.6.0
    • Component/s: Core Framework
    • Labels:


      The EventIdFirstSchemaRecordWriter that is used by the provenance repository has a writeRecord(ProvenanceEventRecord) method. Within this method, it serializes the given record into a byte array by serializing to a ByteArrayOutputStream (after wrapping the BAOS in a DataOutputStream). Once this is done, it calls toByteArray() on that BAOS so that it can write the byte[] directly to another OutputStream.

      This can create a rather large amount of garbage to be collected. We can improve this significantly:

      1. Instead of creating a new ByteArrayOutputStream each time, create a pool of them. This avoids constantly having to garbage collect them.
      2. If said BAOS grows beyond a certain size, we should not return it to the pool because we don't want to keep a huge impact on the heap.
      3. Instead of wrapping the BAOS in a new DataOutputStream, the DataOutputStream should be pooled/recycled as well. Since it must create an internal byte[] for the writeUTF method, this can save a significant amount of garbage.
      4. Avoid calling ByteArrayOutputStream.toByteArray(). We can instead just use ByteArrayOutputStream.writeTo(OutputStream). This avoids both allocating that new array/copying the data, and the GC overhead.



          Issue Links



              • Assignee:
                markap14 Mark Payne
                markap14 Mark Payne
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: