-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Netty default allocator whenever it is pooled otherwise fallback …
…to adaptive allocator. Motivation: Vert.x should use Netty's default allocator whenever possible in order to minimize the resources for pooled allocation (thread-local direct buffers, arenas). Changes: VertxByteBufAllocator.POOLED_ALLOCATOR reuses ByteBufAllocator.DEFAULT when it is pooled otherwise uses AdaptiveByteBufAllocator.DEFAULT. TCP server/client should use VertxByteBufAllocator.POOLED_ALLOCATOR instead of PooledByteBufAllocator.DEFAULT.
- Loading branch information
Showing
8 changed files
with
165 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
vertx-core/src/test/java/io/vertx/it/buffer/TcpAllocationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2011-2024 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package io.vertx.it.buffer; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.ByteBufAllocator; | ||
import io.netty.buffer.UnpooledByteBufAllocator; | ||
import io.netty.util.ReferenceCountUtil; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.buffer.impl.BufferImpl; | ||
import io.vertx.core.impl.buffer.VertxByteBufAllocator; | ||
import io.vertx.core.internal.net.NetSocketInternal; | ||
import io.vertx.core.net.NetClient; | ||
import io.vertx.core.net.NetServer; | ||
import io.vertx.core.net.NetSocket; | ||
import io.vertx.test.core.VertxTestBase; | ||
import org.junit.Test; | ||
|
||
public class TcpAllocationTest extends VertxTestBase { | ||
|
||
@Test | ||
public void testByteBufOriginateFromDefaultByteBufAllocator() { | ||
NetServer server = vertx.createNetServer(); | ||
server.connectHandler(so -> { | ||
NetSocketInternal soi = (NetSocketInternal) so; | ||
soi.messageHandler(msg -> { | ||
try { | ||
ByteBuf bbuf = (ByteBuf) msg; | ||
assertSame(VertxByteBufAllocator.POOLED_ALLOCATOR, bbuf.alloc()); | ||
} finally { | ||
ReferenceCountUtil.release(msg); | ||
} | ||
testComplete(); | ||
}); | ||
}); | ||
server.listen(1234, "localhost").await(); | ||
NetClient client = vertx.createNetClient(); | ||
NetSocket so = client.connect(1234, "localhost").await(); | ||
so.write(Buffer.buffer("ping")); | ||
await(); | ||
} | ||
|
||
@Test | ||
public void testByteBufCopyAndRelease() { | ||
NetServer server = vertx.createNetServer(); | ||
server.connectHandler(so -> { | ||
so.handler(buff -> { | ||
ByteBuf byteBuf = ((BufferImpl)buff).byteBuf(); | ||
assertFalse(byteBuf.isDirect()); | ||
assertFalse(byteBuf.alloc().isDirectBufferPooled()); | ||
testComplete(); | ||
}); | ||
}); | ||
server.listen(1234, "localhost").await(); | ||
NetClient client = vertx.createNetClient(); | ||
NetSocket so = client.connect(1234, "localhost").await(); | ||
so.write(Buffer.buffer("ping")); | ||
await(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters