[SERVER-80296] Refactor command request processing path to reduce BSON parsing passes Created: 21/Aug/23  Updated: 01/Feb/24  Resolved: 01/Feb/24

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.3.0-rc2

Type: Task Priority: Major - P3
Reporter: Mark Benvenuto Assignee: Alex Li
Resolution: Fixed Votes: 0
Labels: perf, perf-8.0, perf-tiger, perf-tiger-handoff, perf-tiger-poc, perf-tiger-project-candidates, perf-tiger-q4, perf-tiger-triaged
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-80295 Refactor command reply processing pat... Open
related to SERVER-85791 Only parse command request once in co... In Progress
Assigned Teams:
Service Arch
Backwards Compatibility: Fully Compatible
Sprint: Service Arch 2023-10-02, Service Arch 2023-10-16, Service Arch 2023-10-30, Service Arch 2023-11-13, Service Arch 2023-11-27, Service Arch 2023-12-11, Service Arch 2023-12-25, Service Arch 2024-01-08, Service Arch 2024-01-22, Service Arch 2024-02-05
Participants:

 Description   

There are several calls to BSONObj::getField that are made by functions called by ExecCommandDatabase::_initiateCommand and ExecCommandDatabase::run.

They come from the following places:

  • Multiple calls to OpMsgRequest::getDbName
  • _extractReadConcern
  • commandSpecifiesWriteConcern
  • searches for "shardVersion" and "databaseVersion"
  • ReadPreferenceSetting::fromInnerBSON
  • VectorClock::PlainComponentFormat::in and VectorClock::SignedComponentFormat::in

Additionally, there are two manual loops over BSONOjb fields:

  • readRequestMetadata
  • ExecCommandDatabase::_initiateCommand

Finally, we invoke 2 IDL parser in addition to the one for the command

  • APIParametersFromClient
  • OperationSessionInfoFromClient

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

structs:
  CommonRequestArgs:
    description: TODO
    strict: false
    unsafe_dangerous_disable_extra_field_duplicate_checks: true
    chained_structs:
      APIParametersFromClient: APIParametersFromClient
      OperationSessionInfoFromClientBase: OperationSessionInfoFromClientBase
      ClusterTimesCommon: ClusterTimesCommon
    fields:
      readConcern:
        type: object
        optional: true
      databaseVersion:
          type: database_version
          optional: true
      shardVersion:
          type: shard_version
          optional: true
      writeConcern:
        type: IDLAnyType
        optional: true
      $readPreference:
        type: IDLAnyType
        cpp_name: readPreference
        optional: true
      $client:
        type: IDLAnyType
        cpp_name: clientMetadata
        optional: true
      tracking_info:
        type: IDLAnyType
        optional: true
      $audit:
        cpp_name: impersonation
        type: IDLAnyType
        optional: true
      clientOperationKey:
        type: uuid
        optional: true
      mayBypassWriteBlocking:
        type: IDLAnyType
        optional: true
      maxTimeMS:
        type: maxTimeMS
        optional: true
        validator: { gte: 0 }
      maxTimeMSOpOnly:
        type: maxTimeMS
        optional: true
        validator: { gte: 0 }
      help:
        type: safeBool
        optional: true
      comment:
        type: IDLAnyType
        optional: true
      $maxTimeMS:
        type: IDLAnyType
        cpp_name: queryOptionMaxTimeMS
        optional: true

Note: There may be opportunity to align with the request 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 request fields.

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



 Comments   
Comment by Githook User [ 01/Feb/24 ]

Author:

{'name': 'Alex Li', 'email': '98560274+lia394126@users.noreply.github.com', 'username': 'lia394126'}

Message: SERVER-80296 Refactor command request processing path to reduce BSON parsing passes (#17274)

GitOrigin-RevId: ee00ae5a48ea5261b342241d770f3d05c284fc88
Branch: master
https://github.com/mongodb/mongo/commit/f12a8e1acac9130e9721038b35210dcf0f2fab7c

Comment by Mark Benvenuto [ 11/Sep/23 ]

blake.oler@mongodb.com Benchmarking with POC is in PERF-4537

Comment by Blake Oler [ 29/Aug/23 ]

mark.benvenuto@mongodb.com have you done any benchmarking to show performance gains here, or is this just a theoretical gain at the moment?

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