You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2020/04/29 12:20:50 UTC
[tomcat] branch master updated: Merge BufferPool15Impl into
BufferPool
This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 8ed94f7 Merge BufferPool15Impl into BufferPool
8ed94f7 is described below
commit 8ed94f7a33f62315b1fd490ce2845a05660ffd35
Author: remm <re...@apache.org>
AuthorDate: Wed Apr 29 14:20:31 2020 +0200
Merge BufferPool15Impl into BufferPool
Also add (!!) a system property to configure the static buffer pool
size, since it was fixed to 100MB.
This static pool may not be beneficial anymore and could be reviewed.
---
java/org/apache/catalina/tribes/io/BufferPool.java | 81 ++++++++++++----------
.../catalina/tribes/io/BufferPool15Impl.java | 67 ------------------
webapps/docs/changelog.xml | 9 +++
webapps/docs/config/systemprops.xml | 6 ++
4 files changed, 59 insertions(+), 104 deletions(-)
diff --git a/java/org/apache/catalina/tribes/io/BufferPool.java b/java/org/apache/catalina/tribes/io/BufferPool.java
index a44a1da..4c77c20 100644
--- a/java/org/apache/catalina/tribes/io/BufferPool.java
+++ b/java/org/apache/catalina/tribes/io/BufferPool.java
@@ -17,68 +17,75 @@
package org.apache.catalina.tribes.io;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
import org.apache.catalina.tribes.util.StringManager;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
-/**
- *
- *
- * @version 1.0
- */
public class BufferPool {
private static final Log log = LogFactory.getLog(BufferPool.class);
- public static final int DEFAULT_POOL_SIZE = 100*1024*1024; //100MB
+ public static final int DEFAULT_POOL_SIZE =
+ Integer.getInteger("org.apache.catalina.tribes.io.BufferPool.DEFAULT_POOL_SIZE", 100*1024*1024); //100MB
protected static final StringManager sm = StringManager.getManager(BufferPool.class);
-
-
protected static volatile BufferPool instance = null;
- protected final BufferPoolAPI pool;
-
- private BufferPool(BufferPoolAPI pool) {
- this.pool = pool;
- }
-
- public XByteBuffer getBuffer(int minSize, boolean discard) {
- if ( pool != null ) return pool.getBuffer(minSize, discard);
- else return new XByteBuffer(minSize,discard);
- }
-
- public void returnBuffer(XByteBuffer buffer) {
- if ( pool != null ) pool.returnBuffer(buffer);
- }
-
- public void clear() {
- if ( pool != null ) pool.clear();
- }
-
public static BufferPool getBufferPool() {
if (instance == null) {
synchronized (BufferPool.class) {
if (instance == null) {
- BufferPoolAPI pool = new BufferPool15Impl();
- pool.setMaxSize(DEFAULT_POOL_SIZE);
- log.info(sm.getString("bufferPool.created",
- Integer.toString(DEFAULT_POOL_SIZE), pool.getClass().getName()));
- instance = new BufferPool(pool);
+ BufferPool pool = new BufferPool();
+ pool.setMaxSize(DEFAULT_POOL_SIZE);
+ log.info(sm.getString("bufferPool.created",
+ Integer.toString(DEFAULT_POOL_SIZE),
+ pool.getClass().getName()));
+ instance = pool;
}
}
}
return instance;
}
+ private BufferPool() {
+ }
- public static interface BufferPoolAPI {
- public void setMaxSize(int bytes);
+ public XByteBuffer getBuffer(int minSize, boolean discard) {
+ XByteBuffer buffer = queue.poll();
+ if ( buffer != null ) size.addAndGet(-buffer.getCapacity());
+ if ( buffer == null ) buffer = new XByteBuffer(minSize,discard);
+ else if ( buffer.getCapacity() <= minSize ) buffer.expand(minSize);
+ buffer.setDiscard(discard);
+ buffer.reset();
+ return buffer;
+ }
- public XByteBuffer getBuffer(int minSize, boolean discard);
+ public void returnBuffer(XByteBuffer buffer) {
+ if ( (size.get() + buffer.getCapacity()) <= maxSize ) {
+ size.addAndGet(buffer.getCapacity());
+ queue.offer(buffer);
+ }
+ }
+
+ public void clear() {
+ queue.clear();
+ size.set(0);
+ }
- public void returnBuffer(XByteBuffer buffer);
+ protected int maxSize;
+ protected final AtomicInteger size = new AtomicInteger(0);
+ protected final ConcurrentLinkedQueue<XByteBuffer> queue =
+ new ConcurrentLinkedQueue<>();
- public void clear();
+ public void setMaxSize(int bytes) {
+ this.maxSize = bytes;
}
+
+ public int getMaxSize() {
+ return maxSize;
+ }
+
}
diff --git a/java/org/apache/catalina/tribes/io/BufferPool15Impl.java b/java/org/apache/catalina/tribes/io/BufferPool15Impl.java
deleted file mode 100644
index 57bc227..0000000
--- a/java/org/apache/catalina/tribes/io/BufferPool15Impl.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.catalina.tribes.io;
-
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- *
- * @version 1.0
- */
-class BufferPool15Impl implements BufferPool.BufferPoolAPI {
- protected int maxSize;
- protected final AtomicInteger size = new AtomicInteger(0);
- protected final ConcurrentLinkedQueue<XByteBuffer> queue =
- new ConcurrentLinkedQueue<>();
-
- @Override
- public void setMaxSize(int bytes) {
- this.maxSize = bytes;
- }
-
-
- @Override
- public XByteBuffer getBuffer(int minSize, boolean discard) {
- XByteBuffer buffer = queue.poll();
- if ( buffer != null ) size.addAndGet(-buffer.getCapacity());
- if ( buffer == null ) buffer = new XByteBuffer(minSize,discard);
- else if ( buffer.getCapacity() <= minSize ) buffer.expand(minSize);
- buffer.setDiscard(discard);
- buffer.reset();
- return buffer;
- }
-
- @Override
- public void returnBuffer(XByteBuffer buffer) {
- if ( (size.get() + buffer.getCapacity()) <= maxSize ) {
- size.addAndGet(buffer.getCapacity());
- queue.offer(buffer);
- }
- }
-
- @Override
- public void clear() {
- queue.clear();
- size.set(0);
- }
-
- public int getMaxSize() {
- return maxSize;
- }
-
-}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 18f1325..5991a50 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -147,6 +147,15 @@
</fix>
</changelog>
</subsection>
+ <subsection name="Cluster">
+ <changelog>
+ <update>
+ Refactor Tribes BufferPool and add the
+ <code>org.apache.catalina.tribes.io.BufferPool.DEFAULT_POOL_SIZE</code>
+ system property to configure its size. (remm)
+ </update>
+ </changelog>
+ </subsection>
<subsection name="Web applications">
<changelog>
<fix>
diff --git a/webapps/docs/config/systemprops.xml b/webapps/docs/config/systemprops.xml
index 2a15d9d..0b00c60 100644
--- a/webapps/docs/config/systemprops.xml
+++ b/webapps/docs/config/systemprops.xml
@@ -407,6 +407,12 @@
<p>If not specified, the default value of <code>3</code> will be used.</p>
</property>
+ <property name="org.apache.catalina.tribes.io. BufferPool.DEFAULT_POOL_SIZE">
+ <p>The size of the buffer pool which is used by Tribes in bytes.</p>
+ <p>If not specified, the default value of <code>100*1024*1024</code>
+ (100MB) will be used.</p>
+ </property>
+
</properties>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org