-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pool Wrapper with Queue #9320
Pool Wrapper with Queue #9320
Conversation
I've introduced two
I still believe tackling this problem at the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the basic approach shows promise and I don't think we should hold up a merge too much considering how pathological the current pool can be.
It would be nice to see how we could configure some alternative compound pools in XML.
private final ConcurrentPool<P> concurrentPool; | ||
private final Pool<P> secondBestPool; | ||
|
||
public CompoundPool(ConcurrentPool.StrategyType strategyType, int maxSize, boolean cache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather a constructor that just takes 2 other pools as that will allow the full configuration options to be available. Perhaps have some static builder methods that can make some common combinations, but we shouldn't bake only one combo into the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered such constructor, but how to make sure both underlying pools are compatible, especially w.r.t multiplexing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think this is the right thing to do, even if we cannot have isMultiplexing
.
IT would be better even if the constructor was private an only a static factory method with this signature was available
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/QueuedPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/QueuedPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ConcurrentPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/CompoundPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/CompoundPool.java
Outdated
Show resolved
Hide resolved
{ | ||
this.concurrentPool = new ConcurrentPool<>(strategyType, ConcurrentPool.MAX_RECOMMENDED_SIZE, cache); | ||
this.secondBestPool = new QueuedPool<>(maxSize - ConcurrentPool.MAX_RECOMMENDED_SIZE); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need someway of checking that both pools have compatible multiplexing capabilities. Do we need to be able to ask a Pool what it's max multiple is? Or perhaps just ask it if it has a non unary max multiple function in a isMultiplexing
method. If one pool is multiplexing, then the other one should be as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a can of worms. I considered adding a isMultiplexing
method to Pool
but then I realized that multiplexing is based on a constructor-provided ToIntFunction
which makes it impossible to be 100% certain both pools are going to use the same, or compatible multiplexing functions.
The best I can think of is to have such isMultiplexing
method in Pool
and make ConcurrentPool
return false
only when the constructor that doesn't take a ToIntFunction
has been used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that works for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But does not work, as I can pass a ToIntFunction that returns 1
.
I think this class is better as a private inner class of ArrayByteBufferPool
, as it's not really reusable that much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we introduce another pool that can handle queued multiplexed pools, then it will get more usage. It is a util class and I see no problem exposing it. All util classes can be used badly. If we provide some static factory methods that easily build combinations that work well together, then that will encourage good usage. I am OK with a protected constructor an only public static factory methods. Then if somebody really wanted to do something strange, they could extend.
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java
Outdated
Show resolved
Hide resolved
Would it be possible to have a multiplexing |
Perhaps a |
@gregw finding a sorted and concurrent structure with adequate perf to hold the multiplexed entries sounds challenging. I do not think we currently have a good use-case for it, as only H2 connections in the client currently are pooled and using the multiplexing support. But maybe we just found a good reason to not warn when a too large |
5931d91
to
62d3764
Compare
It should be fairly simple to find a |
@sbordet, as this was originally my PR, I can't review. I'm OK with it in it's current form (other than my niggle about a better constructor). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced that CompoundPool
and QueuedPool
should be public in jetty-util
, as they are ok for ABBP, but that's basically it.
Also, I am worried about ConnectionPool
performance too now, so I would like to see a more generic solution that supports multiplexing.
* free for other data. A quick test has also shown that ConcurrentPool's perf starts dipping | ||
* noticeably when more than 512 entries are used. | ||
*/ | ||
static final int MAX_RECOMMENDED_SIZE = 256; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a biggie, but I'd rename this to OPTIMAL_MAX_SIZE
, or RECOMMENDED_MAX_SIZE
as "max" refers to the size so they should be closer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIth such as low value, I am now worried about ConnectionPool
having a bad performance, in particular for load testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then let's add a priority queue implementation that will sort entries by multiplexed availability. It should not be too hard to write and may even be OK as the primary pool for the connections, as the concurrent pool has to use a poor strategy to work with multiplexing anyway.
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ConcurrentPool.java
Outdated
Show resolved
Hide resolved
{ | ||
this.concurrentPool = new ConcurrentPool<>(strategyType, ConcurrentPool.MAX_RECOMMENDED_SIZE, cache); | ||
this.secondBestPool = new QueuedPool<>(maxSize - ConcurrentPool.MAX_RECOMMENDED_SIZE); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But does not work, as I can pass a ToIntFunction that returns 1
.
I think this class is better as a private inner class of ArrayByteBufferPool
, as it's not really reusable that much.
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Pool.java
Outdated
Show resolved
Hide resolved
* | ||
* @param <P> the type of the pooled objects | ||
*/ | ||
public class QueuedPool<P> implements Pool<P> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this class being public in jetty-util, but have the big restriction of not being multiplexed.
For example I would not be able to use it for ConnectionPool
.
I think this implementation should be private to ArrayByteBufferPool
, but we do need an implementation that supports multiplexing for ConnectionPool
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to make it private. It is a perfectly good pool implementation that just happens not to take a multiplex int function, so it can't do multiplexing.
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/QueuedPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/QueuedPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/QueuedPool.java
Outdated
Show resolved
Hide resolved
I've renamed the
|
@lorban I'm sorry but ConcurrentOverflowingToQueuedPool is a silly name. The only thing about that class which that name applies to is the constructor. Everything else about that class is just CompoundPool. We should name the class for what it does, not for hours we use it. |
Okay, I've renamed the class back to I've tried to stick to the "best is the enemy of good" mindset when working on this because:
I'm not against working on a multiplexed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the approach of making this PR about fixing the known problems in the ABBP. We can investigate later if we need to generalise more and come up with solutions for multiplexed pools.
I still don't like the constructor of CompoundPool
, but since it is private, that is a niggle rather than a show stopper
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java
Outdated
Show resolved
Hide resolved
8639a0c
to
71506fc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This adds a QueuedPool that can wrap any other pool and provided a queue of Entries as a kind of cache.
d2517c5
to
1122b79
Compare
For #9311
This adds a QueuedPool that can wrap any other pool and provided a queue of Entries as a kind of cache.
This is an alternative to #9319