Skip to content

Commit 1e81245

Browse files
committed
For write commands, use buffer pool for encoding and the DBPort's decoder for decoding. By using pooled buffers instead of short-lived ones,
memory pressure is reduced. JAVA-1880
1 parent 2f7c6c3 commit 1e81245

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/main/com/mongodb/DBCollectionImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ private MongoNamespace getNamespace() {
515515

516516
private BaseWriteCommandMessage sendWriteCommandMessage(final BaseWriteCommandMessage message, final int batchNum,
517517
final DBPort port) throws IOException {
518-
final PoolOutputBuffer buffer = new PoolOutputBuffer();
518+
PoolOutputBuffer buffer = _db.getMongo()._bufferPool.get();
519519
try {
520520
BaseWriteCommandMessage nextMessage = message.encode(buffer);
521521
if (nextMessage != null || batchNum > 1) {
@@ -525,11 +525,12 @@ private BaseWriteCommandMessage sendWriteCommandMessage(final BaseWriteCommandMe
525525
return nextMessage;
526526
} finally {
527527
buffer.reset();
528+
_db.getMongo()._bufferPool.done(buffer);
528529
}
529530
}
530531

531532
private CommandResult receiveWriteCommandMessage(final DBPort port) throws IOException {
532-
Response response = new Response(port.getAddress(), null, port.getInputStream(), DefaultDBDecoder.FACTORY.create());
533+
Response response = new Response(port.getAddress(), null, port.getInputStream(), port.getDecoder());
533534
CommandResult writeCommandResult = new CommandResult(port.getAddress());
534535
writeCommandResult.putAll(response.get(0));
535536
writeCommandResult.throwOnError();

src/main/com/mongodb/DBPort.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ public ServerAddress serverAddress() {
356356
return _sa;
357357
}
358358

359+
DBDecoder getDecoder() {
360+
return _decoder;
361+
}
362+
359363
@Override
360364
public String toString(){
361365
return "{DBPort " + host() + "}";

0 commit comments

Comments
 (0)