[SERVER-80295] Refactor command reply processing path to reduce BSON parsing passes Created: 21/Aug/23  Updated: 29/Jan/24

Status: Open
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Mark Benvenuto Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 0
Labels: perf, perf-tiger, perf-tiger-handoff, perf-tiger-poc, perf-tiger-project-candidates, perf-tiger-triaged
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Issue split
split to SERVER-82091 Add a benchmark for ServiceEntryPoint Closed
Related
is related to SERVER-80296 Refactor command request processing p... Closed
Assigned Teams:
Service Arch
Sprint: Service Arch 2023-09-18, Service Arch 2023-10-02, Service Arch 2023-10-16
Participants:

 Description   

There are several calls to BSONObj::getField that are made by functions called by RunCommandImpl::_epilogue. These are chiefly CommandHelpers::extractOrAppendOK and mongo::getStatusFromCommandResult. These command parsers can be consolidated with the help of an IDL generated parser to reduce the amount of parsing of the BSON reply.

Also, CommandHelpers::checkForInternalError can be made debug only to avoid yet another pass over the reply.

Example of the reply fields that can be consolidated in an IDL definition:

  CommonReplyArgs:
      description: TODO
      strict: false
      unsafe_dangerous_disable_extra_field_duplicate_checks: true
      fields:
        ok:
          type: safeBool
          optional: true
        code:
          type: safeInt
          optional: true
        errmsg:
          type: string
          optional: true
        $err:
          cpp_name: dollarErr
          type: string
          optional: true
        writeConcernError:
          type: object
          optional: true

Note: There may be opportunity to align with the reply fields defined in src/mongo/idl/generic_argument.idl. On the other hand, a more narrow parser for this error handling will be better then a wider parser handling all generic reply fields.

POC: https://github.com/markbenvenuto/mongo/tree/tiger_perf_bson



 Comments   
Comment by Patrick Freed [ 29/Jan/24 ]

Reopening this since we will be revisiting as part of PM-3598.

Comment by Jason Chan [ 02/Nov/23 ]

Closing since the investigations didn't show clear benefits. We may want to reopen or create another ticket to discuss another approach on reducing the number of bson parsing passes.

Comment by Mark Benvenuto [ 18/Oct/23 ]

One other set of `getField` calls were missed in my analysis: ReplicationCoordinatorImpl::prepareReplMetadata has two calls to `getField`. This code is only used in a replica set, not standalone.

Generated at Thu Feb 08 06:43:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.