Skip to content

Commit

Permalink
Issue #6974 - ByteBufferPools should default to use maxMemory heuristic
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Oct 20, 2021
1 parent 952f3bc commit 8e8c670
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ protected AbstractByteBufferPool(int factor, int maxQueueLength, long maxHeapMem
{
_factor = factor <= 0 ? 1024 : factor;
_maxQueueLength = maxQueueLength;
_maxHeapMemory = (maxHeapMemory != 0) ? maxHeapMemory : Runtime.getRuntime().totalMemory() / 4;
_maxDirectMemory = (maxDirectMemory != 0) ? maxDirectMemory : Runtime.getRuntime().totalMemory() / 4;
_maxHeapMemory = (maxHeapMemory != 0) ? maxHeapMemory : Runtime.getRuntime().maxMemory() / 4;
_maxDirectMemory = (maxDirectMemory != 0) ? maxDirectMemory : Runtime.getRuntime().maxMemory() / 4;
}

protected int getCapacityFactor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ArrayByteBufferPool()
*/
public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity)
{
this(minCapacity, factor, maxCapacity, -1, -1, -1);
this(minCapacity, factor, maxCapacity, -1, 0, 0);
}

/**
Expand All @@ -81,7 +81,7 @@ public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity)
*/
public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxQueueLength)
{
this(minCapacity, factor, maxCapacity, maxQueueLength, -1, -1);
this(minCapacity, factor, maxCapacity, maxQueueLength, 0, 0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public MappedByteBufferPool(int factor, int maxQueueLength)
*/
public MappedByteBufferPool(int factor, int maxQueueLength, Function<Integer, Bucket> newBucket)
{
this(factor, maxQueueLength, newBucket, -1, -1);
this(factor, maxQueueLength, newBucket, 0, 0);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions jetty-server/src/main/config/etc/jetty-bytebufferpool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Arg type="int"><Property name="jetty.byteBufferPool.factor" default="1024"/></Arg>
<Arg type="int"><Property name="jetty.byteBufferPool.maxCapacity" default="65536"/></Arg>
<Arg type="int"><Property name="jetty.byteBufferPool.maxQueueLength" default="-1"/></Arg>
<Arg type="long"><Property name="jetty.byteBufferPool.maxHeapMemory" default="-1"/></Arg>
<Arg type="long"><Property name="jetty.byteBufferPool.maxDirectMemory" default="-1"/></Arg>
<Arg type="long"><Property name="jetty.byteBufferPool.maxHeapMemory" default="0"/></Arg>
<Arg type="long"><Property name="jetty.byteBufferPool.maxDirectMemory" default="0"/></Arg>
</New>
</Configure>
8 changes: 4 additions & 4 deletions jetty-server/src/main/config/modules/bytebufferpool.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ etc/jetty-bytebufferpool.xml
## Maximum queue length for each bucket (-1 for unbounded)
#jetty.byteBufferPool.maxQueueLength=-1

## Maximum heap memory retainable by the pool (-1 for unlimited)
#jetty.byteBufferPool.maxHeapMemory=-1
## Maximum heap memory retainable by the pool (0 for heuristic, -1 for unlimited)
#jetty.byteBufferPool.maxHeapMemory=0

## Maximum direct memory retainable by the pool (-1 for unlimited)
#jetty.byteBufferPool.maxDirectMemory=-1
## Maximum direct memory retainable by the pool (0 for heuristic, -1 for unlimited)
#jetty.byteBufferPool.maxDirectMemory=0
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
//
// ========================================================================
// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//

package org.eclipse.jetty.test;

import java.net.URI;
Expand Down Expand Up @@ -25,15 +43,15 @@

public class WSClientForMemTest
{
private static final char[] ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789{} \":;<>,.()[]".toCharArray();
private static final char[] ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789{}\":;<>,.()[]".toCharArray();

@Test
public void test() throws Exception
{
HttpClient httpClient = new HttpClient();
httpClient.setByteBufferPool(new NullByteBufferPool());
WebSocketClient _client = new WebSocketClient(httpClient);
_client.start();
WebSocketClient client = new WebSocketClient(httpClient);
client.start();

int numThreads = 100;
int maxMessageSize = 1024 * 1024;
Expand Down Expand Up @@ -65,7 +83,7 @@ public void succeeded()
URI uri = URI.create("ws://localhost:8080/websocket");
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
upgradeRequest.addExtensions("permessage-deflate");
Session session = _client.connect(clientSocket, uri, upgradeRequest).get(5, TimeUnit.SECONDS);
Session session = client.connect(clientSocket, uri, upgradeRequest).get(5, TimeUnit.SECONDS);
assertTrue(session.getUpgradeResponse().getExtensions().stream().anyMatch(config -> config.getName().equals("permessage-deflate")));

session.getRemote().sendString(randomString(messageSize));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
//
// ========================================================================
// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//

package org.eclipse.jetty.test;

import java.io.IOException;
Expand Down Expand Up @@ -57,16 +75,16 @@ public void before() throws Exception
{
_server = new Server();
// _server.addBean(new LogArrayByteBufferPool(512, -1, -1, maxMemory, maxMemory));
int maxMemory = 1024 * 1024 * 64;
int maxMemory = 0; //1024 * 1024 * 64;
// ByteBufferPool bufferPool = new ArrayByteBufferPool(-1, -1, -1, -1, maxMemory, maxMemory);
LogArrayByteBufferPool bufferPool = new LogArrayByteBufferPool(-1, 1024 * 1024, -1, maxMemory, maxMemory);
// MappedByteBufferPool bufferPool = new MappedByteBufferPool(-1, -1, null, maxMemory, maxMemory);
bufferPool.setDetailedDump(true);
// ByteBufferPool bufferPool = new NullByteBufferPool();
_server.addBean(bufferPool);
ServerConnector _connector = new ServerConnector(_server);
_connector.setPort(8080);
_server.addConnector(_connector);
ServerConnector connector = new ServerConnector(_server);
connector.setPort(8080);
_server.addConnector(connector);

ServletContextHandler contextHandler = new ServletContextHandler();
WebSocketUpgradeFilter.configure(contextHandler);
Expand Down

0 comments on commit 8e8c670

Please sign in to comment.