Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-2494

DBClientBase::insert requires multiple alloc/copy/free operations, should be zero copy for passed in BSONObj

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 1.6.3, 1.6.4, 1.6.5, 1.7.0, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5
    • Fix Version/s: None
    • Labels:
    • Backwards Compatibility:
      Fully Compatible

      Description

      In the current C++ driver, calling 'insert' with a BSONObj ends up copying the (already contiguous) data in the BSONObj to newly allocated temporary buffers, then discards the temp buffers. This happens at least two times that I can see:

      • Once when calling BSONObj::appendSelfToBufBuilder( b ) in DBClientBase::insert
      • Once again when calling Message::setData(int operation, const char *msgdata, size_t len), also in DBClientBase::insert

      The Message::setData operation always requires a dynamic allocation, and a subsequent free after the temporary Message object is goes out of scope. The appendSelfToBufBuilder will also require some number of dynamic allocations to resize the BufBuilder as data is copied in.

      For large BSONObj objects, this is not optimal. It would be better if the IO strategy here either used multiple independent writes to the TCP stream to write the message header, then the BSONObj, and then any trailing data. Another possibility would be to use vector IO, and to write the header and BSONObj in one go as separate chunks: it looks like there is already some support in Message.cpp for this. For small BSONObjs this probably isn't a big deal, but for larger ones, the overhead of all of this allocating, copying, and freeing is noticeable during profiling.

        Attachments

          Activity

            People

            Assignee:
            backlog-server-platform DO NOT USE - Backlog - Platform Team
            Reporter:
            acm Andrew Morrow
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: