Skip to content

Commit

Permalink
Add task queue size configuration on the Connector element
Browse files Browse the repository at this point in the history
BZ 69133
  • Loading branch information
rmaucher committed Jun 12, 2024
1 parent 7118991 commit 204f0fe
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
8 changes: 8 additions & 0 deletions java/org/apache/coyote/AbstractProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ public void setThreadPriority(int threadPriority) {
}


public int getMaxQueueSize() {
return endpoint.getMaxQueueSize();
}

public void setMaxQueueSize(int maxQueueSize) {
endpoint.setMaxQueueSize(maxQueueSize);
}

public int getAcceptCount() {
return endpoint.getAcceptCount();
}
Expand Down
18 changes: 17 additions & 1 deletion java/org/apache/tomcat/util/net/AbstractEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,22 @@ public int getMaxThreads() {
}


/**
* Task queue capacity for the thread pool.
*/
private int maxQueueSize = Integer.MAX_VALUE;
public void setMaxQueueSize(int maxQueueSize) {
this.maxQueueSize = maxQueueSize;
}
public int getMaxQueueSize() {
if (internalExecutor) {
return maxQueueSize;
} else {
return -1;
}
}


/**
* Amount of time in milliseconds before the internal thread pool stops any idle threads
* if the amount of thread is greater than the minimum amount of spare threads.
Expand Down Expand Up @@ -1225,7 +1241,7 @@ public void createExecutor() {
if (getUseVirtualThreads()) {
executor = new VirtualThreadExecutor(getName() + "-virt-");
} else {
TaskQueue taskqueue = new TaskQueue();
TaskQueue taskqueue = new TaskQueue(maxQueueSize);
TaskThreadFactory tf = new TaskThreadFactory(getName() + "-exec-", daemon, getThreadPriority());
executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), getThreadsMaxIdleTime(),
TimeUnit.MILLISECONDS, taskqueue, tf);
Expand Down
5 changes: 5 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@
<bug>69068</bug>: Ensure read timouts are triggered for asynchronous,
non-blocking reads when using HTTP/2. (markt)
</fix>
<update>
<bug>69133</bug>: Add task queue size configuration on the
<code>Connector</code> element, similar to the <code>Executor</code>
element, for consistency. (remm)
</update>
</changelog>
</subsection>
<subsection name="Jasper">
Expand Down
18 changes: 18 additions & 0 deletions webapps/docs/config/http.xml
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,24 @@
If not specified, this attribute is set to 100.</p>
</attribute>

<attribute name="maxQueueSize" required="false">
<p>(int) The maximum number of runnable tasks that can queue up awaiting
execution before they are rejected. The default value is
<code>Integer.MAX_VALUE</code></p>
</attribute>

<attribute name="maxThreads" required="false">
<p>The maximum number of request processing threads to be created
by this <strong>Connector</strong>, which therefore determines the
maximum number of simultaneous requests that can be handled. If
not specified, this attribute is set to 200. If an executor is associated
with this connector, this attribute is ignored as the connector will
execute tasks using the executor rather than an internal thread pool. Note
that if an executor is configured any value set for this attribute will be
recorded correctly but it will be reported (e.g. via JMX) as
<code>-1</code> to make clear that it is not used.</p>
</attribute>

<attribute name="maxSwallowSize" required="false">
<p>The maximum number of request body bytes (excluding transfer encoding
overhead) that will be swallowed by Tomcat for an aborted upload. An
Expand Down

0 comments on commit 204f0fe

Please sign in to comment.