Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-11805

SolrRequest elapsedTime is not computed correctly (premature millisecond conversion)

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.3
    • Component/s: None
    • Labels:
      None

      Description

      (this is not QTime, this is what the SolrJ client request duration is captured as)
      This is what SolrRequest.process looks like:

          long startTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
          T res = createResponse(client);
          res.setResponse(client.request(this, collection));
          long endTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
          res.setElapsedTime(endTime - startTime);
          return res;
      

      The millisecond conversion should be delayed to the very end, otherwise it could yield a time duration of a millisecond greater than it deserves. Also, it's better to put the unit into the variable name. Also, note the convenience methods on TimeUnit like "toMillis". Here's what this should look like:

          long startNanos = System.nanoTime();
          T res = createResponse(client);
          res.setResponse(client.request(this, collection));
          long endNanos = System.nanoTime();
          res.setElapsedTime(TimeUnit.NANOSECONDS.toMillis(endNanos - startNanos));
          return res;
      

        Attachments

          Activity

            People

            • Assignee:
              dsmiley David Smiley
              Reporter:
              dsmiley David Smiley
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: