[JAVA-2636] Improve the performance of ByteBufPayloadBsonDocument Created: 12/Oct/17  Updated: 29/Oct/23  Resolved: 13/Nov/17

Status: Closed
Project: Java Driver
Component/s: Monitoring
Affects Version/s: None
Fix Version/s: 3.6.0

Type: Improvement Priority: Major - P3
Reporter: Ross Lawley Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Java MongoDB 3.6 Support

 Comments   
Comment by Githook User [ 13/Nov/17 ]

Author:

{'name': 'Jeff Yemin', 'username': 'jyemin', 'email': 'jeff.yemin@10gen.com'}

Message: JAVA-2636: Move logic from InternalStreamConnection to CommandMessage for getting the BsonDocument to use for command monitoring.

Take advantage of the observation that a command with a payload is likely to be small (minus the payload)
so it's a reasonable approach to simple convert the BSON back into a BsonDocument and then add the payload as a BsonArray
initialized with a List<ByteBufBsonDocument> from the OP_MSG payload.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/0d3c5aa6e39cab844db79c971dd5e3f27f1c60cc

Comment by Githook User [ 13/Nov/17 ]

Author:

{'name': 'Jeff Yemin', 'username': 'jyemin', 'email': 'jeff.yemin@10gen.com'}

Message: JAVA-2636: Add getFirstKey method to BsonDocument
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/dd71640664fd58166cc766c43acaf822f28086b4

Comment by Jeffrey Yemin [ 12/Oct/17 ]

Since we know that the commands that have payloads are the three write commands, and that those commands are quite small (minus the payload itself), we can afford to hydrate the command document into an actual BsonDocument, then add the payload as a BsonArray. This is similar to what's done in InsertProtocol#getAsWriteCommand.

As a method of CommandMessage it would look something like this:

    BsonDocument getCommandDocument(final ByteBufferBsonOutput bsonOutput) {
        ByteBufBsonDocument byteBufBsonDocument = ByteBufBsonDocument.createOne(bsonOutput,
                getEncodingMetadata().getFirstDocumentPosition());
        BsonDocument commandBsonDocument = byteBufBsonDocument;
 
        if (useOpMsg() && containsPayload()) {
            commandBsonDocument = byteBufBsonDocument.toBsonDocument();
            int startPosition = 0;
            // TODO: skip over the payload type, size, and name
            commandBsonDocument.append(getPayload().getPayloadName(),
                    new BsonArray(ByteBufBsonDocument.create(bsonOutput, startPosition)));
        }
 
        if (commandBsonDocument.containsKey("$query")) {
            commandBsonDocument = commandBsonDocument.getDocument("$query");
        }
        return commandBsonDocument;
    }

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