-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OF-2505: BOSH: add back-pressure to network IO when processing can't …
…keep up For BOSH and websocket connections, this commit introduces a new feature (disabled by default) that allows Openfire to be configured to apply 'back pressure' that could be useful in a scenario where the network IO thread pool is outpacing the processing thread pool. By enabling the feature using `xmpp.httpbind.worker.backpressure-enabled` (and setting the queue to a limited value with `xmpp.httpbind.worker.queue-capacity`, the queuing of new tasks by the network IO thread pool blocks when the queue is at capacity.
- Loading branch information
Showing
3 changed files
with
112 additions
and
10 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
29 changes: 29 additions & 0 deletions
29
...erver/src/main/java/org/jivesoftware/openfire/util/ThreadPoolExecutorRejectionPolicy.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,29 @@ | ||
package org.jivesoftware.openfire.http; | ||
|
||
/** | ||
* Enumerates frequently used RejectedExecutionHandler implementations. | ||
* | ||
* @author Guus der Kinderen, [email protected] | ||
*/ | ||
public enum ThreadPoolExecutorRejectionPolicy | ||
{ | ||
/** | ||
* Indicates desired usage of {@link java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy}. | ||
*/ | ||
DiscardOldestPolicy, | ||
|
||
/** | ||
* Indicates desired usage of {@link java.util.concurrent.ThreadPoolExecutor.AbortPolicy}. | ||
*/ | ||
AbortPolicy, | ||
|
||
/** | ||
* Indicates desired usage of {@link java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy}. | ||
*/ | ||
CallerRunsPolicy, | ||
|
||
/** | ||
* Indicates desired usage of {@link java.util.concurrent.ThreadPoolExecutor.DiscardPolicy}. | ||
*/ | ||
DiscardPolicy | ||
} |
50 changes: 50 additions & 0 deletions
50
xmppserver/src/main/java/org/jivesoftware/util/BlocksOnOfferQueue.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,50 @@ | ||
/* | ||
* Copyright (C) 2022 Ignite Realtime Foundation. All rights reserved. | ||
* | ||
* Licensed 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.jivesoftware.util; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* A LinkedBlockingQueue of which the {@link #offer(Object)} method blocks, instead of immediately returning. | ||
* | ||
* This class is designed to be used as a queue for ThreadPoolExecutors that wish to slow down the producing threads | ||
* when the queue is reaching capacity, and where {@link java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy} | ||
* cannot be used (for example, because it would cause rejected tasks to be executed _before_ already queued tasks). | ||
* | ||
* Note that the lock used to guard access in {@link LinkedBlockingQueue#offer(Object, long, TimeUnit)}, which is used | ||
* by this implementation of {@link #offer(Object)}, uses an unfair lock. No strict ordering of execution of produced | ||
* tasks can be guaranteed. | ||
* | ||
* @param <E> | ||
* @author Guus der Kinderen, [email protected] | ||
*/ | ||
public class BlocksOnOfferQueue<E> extends LinkedBlockingQueue<E> | ||
{ | ||
public BlocksOnOfferQueue(int capacity) { | ||
super(capacity); | ||
} | ||
|
||
@Override | ||
public boolean offer(@Nonnull E e) { | ||
try { | ||
return super.offer(e, 999, TimeUnit.DAYS); // 'indefinitely'. | ||
} catch (InterruptedException ex) { | ||
return false; | ||
} | ||
} | ||
} |