Skip to content

Commit

Permalink
Issue #4809 - Set a max number of requests per connection.
Browse files Browse the repository at this point in the history
Improved Pool.reserve(int) logic to take into account the
fact that an entry can accommodate maxMultiplex acquires.

This reduces connection openings for HTTP/2 in case of
spikes of requests.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Aug 13, 2020
1 parent e7a0707 commit 26c2d34
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions jetty-util/src/main/java/org/eclipse/jetty/util/Pool.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ public final void setMaxUsageCount(int maxUsageCount)
* method called or be removed via {@link Pool.Entry#remove()} or
* {@link Pool#remove(Pool.Entry)}.
*
* @param maxReservations the max desired number of reserved entries,
* @param allotment the desired allotment, where each entry handles an allotment of maxMultiplex,
* or a negative number to always trigger the reservation of a new entry.
* @return a disabled entry that is contained in the pool,
* or null if the pool is closed or if the pool already contains
* {@link #getMaxEntries()} entries.
* {@link #getMaxEntries()} entries, or the allotment has already been reserved
*/
public Entry reserve(int maxReservations)
public Entry reserve(int allotment)
{
try (Locker.Lock l = locker.lock())
{
Expand All @@ -159,9 +159,8 @@ public Entry reserve(int maxReservations)

// The pending count is an AtomicInteger that is only ever incremented here with
// the lock held. Thus the pending count can be reduced immediately after the
// test below, but never incremented. Thus the maxReservations limit can be
// enforced.
if (maxReservations >= 0 && pending.get() >= maxReservations)
// test below, but never incremented. Thus the allotment limit can be enforced.
if (allotment >= 0 && (pending.get() * getMaxMultiplex()) >= allotment)
return null;
pending.incrementAndGet();

Expand Down

0 comments on commit 26c2d34

Please sign in to comment.