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

Improve performance of command writeConcern parsing

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.4.1, 3.5.1
    • Affects Version/s: None
    • Component/s: Querying, Replication
    • None
    • Fully Compatible
    • Query 2016-12-12
    • 0

      When a command is executed we attempt to extract a "writeConcern" field via extractWriteConcern() call which calls bsonExtractTypedField() to parse write concern from the command object (see here and here).

      In the case where the command does not contain a "writeConcern" field (which is valid), an error Status object is generated by bsonExtractField() and creates an error message using str::stream, which is an expensive operation.

      This came up as a bottleneck when profiling the Queries.IntNonIdFindOne mongo-perf test, with 8 threads and the --readCmd=true flag. This test performs an indexed findOne(). The extractWriteConcern() call consumed roughly 2% of the command run time.

      A few thoughts on fixing:

      1. We could modify the bsonExtractTypedField()/bsonExtractField() path to be more efficient in the "field not found" case. I suspect extracting an optional field may be a common use case for these methods.
      2. We could avoid calling bsonExtractTypedField()/bsonExtractField() to confirm existence of a "writeConcern" field. We should make the "No writeConcern field exist, return the default WriteConcern" path in extractWriteConcern() as fast as possible.
      3. Also consider skipping WriteConcern validation for commands that don't support WriteConcern (weighing the benefits of validation vs cost once we have addressed the above).

            Assignee:
            james.wahlin@mongodb.com James Wahlin
            Reporter:
            james.wahlin@mongodb.com James Wahlin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: