title: Seemingly random tika performance issues
body: <p>I use RxJava to pipe documents from a source to tika and from tika to ElasticSearch. </p>
  
  <p>At some point in time tika takes about <em>5</em> minutes to index a document and continues normally afterwards.</p>
  
  <p>I am unable to properly point out the cause: If I restart the application, everything is still the same, let's say it took 5mins at the 301st document last time, it will take 5mins at the 301st document again. But if I change up the order of the documents, it happens neither at the same index (301), nor with the same document (the previous 301st).</p>
  
  <p>Here are the relevant parts of the application:</p>
  
  <pre class="lang-java prettyprint-override"><code>public Indexable analyze(Indexable indexable) {
          Timestamp from = new Timestamp(System.currentTimeMillis());
          if (indexable instanceof NCFile) {
          // there is some code here that has no effect
  
              Metadata md = this.generateMetadata(((NCFile) indexable).getPath());
              ((NCFile) indexable).setType(md.get("Content-Type"));
  
              if (((NCFile) indexable).getType().startsWith("text/")) {
                  ((NCFile) indexable).setContent(this.parseContent(((NCFile) indexable).getPath())); //todo . hier könnte man noch viel mehr machen
              } else {
                  ((NCFile) indexable).setContent("");
              }
              ((NCFile) indexable).setType(this.detectMediaType(((NCFile) indexable).getPath()));
  
      }
          Timestamp to = new Timestamp(System.currentTimeMillis());
          System.out.println("the file " + ((NCFile) indexable).getPath() + " took " + (to.getTime()-from.getTime()) + " ms to parse");
          return indexable;
      }
  </code></pre>
  
  <p>and the pipeline that is feeding the code above:</p>
  
  <pre class="lang-java prettyprint-override"><code>nc.filter(action -&gt; action.getOperation() == Operation.INSERT)
                  .map(IndexingAction::getIndexable)
                  .subscribeOn(Schedulers.computation())
                  .map(indexableAction -&gt; metadataAnalyzer.analyze(indexableAction))
                  .map(indexable -&gt; {
                      indexer.insert(indexable);
                      return indexable;
                  })
                  .subscribeOn(Schedulers.io())
                  .map(indexable -&gt; "The indexable " + indexable.getIdentifier() + " of class " + indexable.getClass().getName() + " has been inserted.")
                  .subscribe(message -&gt; this.logger.log(Level.INFO, message));
  </code></pre>
  
  <p>My guess would be that the problem is memory- or thread-related; but as far as I can see, the code should work perfectly fine.</p>
  
  <pre><code>the file Workspace/xx/xx-server/.test-documents/testRFC822_base64 took 5 ms to index
  the file Workspace/xx/xx-server/.test-documents/testPagesHeadersFootersAlphaLower.pages took 306889 ms to index
  the file Workspace/xx/xx-server/.test-documents/testFontAfterBufferedText.rtf took 2 ms to index
  the file Workspace/xx/xx-server/.test-documents/testOPUS.opus took 7 ms to index
  </code></pre>
  
  <p>Funny thing is, these are the tika testfiles provided in their repo.</p>
  
  <p>EDIT:
  After a request I looked into it using FR, but I am not sure what exactly I have to look at:</p>
  
  <p>Right after the plateau it stops working, even though neither the RAM nor the CPU limit is met</p>
  
  <p><a href="https://i.stack.imgur.com/K6n1G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K6n1G.png" alt="enter image description here"></a></p>
  
  <p>EDIT 2:
  Is it the PipedReader that is blocking alle of these threads? Do I understand that correctly?</p>
  
  <p><a href="https://i.stack.imgur.com/Pn4VR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pn4VR.png" alt="enter image description here"></a></p>
  
  <p>EDIT 3:</p>
  
  <p>Here is a 1min flight recording:</p>
  
  <p>Note: The flight recording seems wrong. In my system monitor application I do not see such a big memory consumption (apparent 16GB?!)...</p>
  
  <p><a href="https://i.stack.imgur.com/D9yJA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D9yJA.png" alt="enter image description here"></a></p>
  
  <p>What am I doing wrong?</p>