Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5485

Improve GridFS throughput by reducing byte array cloning

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 5.1.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • Java Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Description: During a review of the GridFS in sync Java driver, specifically within the GridFSDownloadStream and GridFSUploadStream classes, it was found that byte arrays are cloned twice internally via the Binary class. This behavior impacts performance by reducing throughput.

      Initial tests indicate that by minimizing the unnecessary cloning of byte arrays, we can achieve a 33-37% increase in throughput. Throughput is calculated as megabytes per second (MBps), determined by dividing the total megabytes transferred per run by the median time (50th percentile) taken per iterations, measured in seconds.

      However, due to existing compatibility commitments documented in the getData() method of the Binary class, directly modifying this behavior could lead to breaking changes.

      Proposed Solution: Instead of modifying the Binary class, it is proposed to adjust GridFSDownloadStream and GridFSUploadStream to utilize BsonDocument instead of Document. The BsonDocument implementation does not involve copying in BsonBinary class, which would sidestep the compatibility issues while achieving the performance improvements.

            Assignee:
            slav.babanin@mongodb.com Slav Babanin
            Reporter:
            slav.babanin@mongodb.com Slav Babanin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: