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
Alternative Pool Strategies #5218
Conversation
Signed-off-by: Greg Wilkins <gregw@webtide.com>
+ javadoc Signed-off-by: Greg Wilkins <gregw@webtide.com>
I'm not going to comment on the implementation that is a bit drafty, but making the thread-local caching pluggable is surprisingly not very intrusive, so I don't mind it. But I'm still not conviced by the usefulness of this change as I'm worried it seems like it will create a tendency to push down some logic that should be kept higher-up, like the randomness / round robinness that IMHO is better suited at a higher level. Oh, and some unwise strategy has the potential of totally killing perf, like the LRU implementation. |
+ Added a ThreadLocalStrategy for a single cached item + Tell strategies about newly reserved entries + Fixed multiplexing test that was dependent on the impl of the cache Signed-off-by: Greg Wilkins <gregw@webtide.com>
@lorban yep the LRU impl really sux :) Perhaps we shouldn't offer that one as the name is attractive, but hard to implement without garbage and/or contention. Have a look again now, as I've created ThreadLocalStrategy for the common case of a cache of size 1. So that will give us a performance improvement. |
+ added tests Signed-off-by: Greg Wilkins <gregw@webtide.com>
What I'm uncomfortable with in this change is the fact that the strategy can either augment the entry lookup, like the caching strategy does by adding a fastpath / slowpath behavior, or it can completely bypass the entry lookup... while still having the ability to fallback to the default lookup. This sounds like a too coarse/permissive API that could easily be abused. I'm worried this could encourage turning the Pool class into a silver bullet in the long run, especially since I can't think of a use-case that can't be solved by wrapping it instead. |
@lorban But I think it is better to have Pool be a Shiny bullet (if not silver), rather than have the HttpClient connection pool code worrying about the details of how to do random/round-robin/etc. Wrapping is a poor solution as it requires exposing public API of aquireAt(int) and you end up with the situation of unused cache mechanisms in the code that you hope the JIT will remove and that they wont confuse connection cache developers. Finally, if your arguments hold, then that is a reason to remove the caching mechanism from Pool as that too could be done with a wrapper! Strategy should be 0,1 or infinity. The fact that we have thread local cache and round robin shows that we have at least 2 strategies... hence we should implement infinity. |
+ Don't have a fallback iteration, instead make a SearchStrategy and DualStrategy
@lorban I think I've fixed your reservation of having the fallback iterative search. cacheSize ==0 results in a round robin pool is just Naming could be worked on.... |
+ split strategies into Cache and Strategies
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 leaning on the path of being convinced by this Strategy
approach, mostly because we could get rid of the acquireAt()
method.
But the Strategy
API needs some cleanup IMHO.
+ Added reserve and release
@sbordet @lorban I've followed Simone's feedback and it is working... but I think it is really rather delicate and there are all sorts of ways that it can be used incorrectly. I'm not sure that making the strategies get involved with the actual mechanics of release/remove/reserve is a good thing. Sure it makes the interface look symmetric (having Fundamentally I think it kind of goes against the atomic spirit of the pool, where the Entry is the primary atomic mechanism and when you act on it, you might find that somebody else has already acquired or closed it on you. Thus I think a So I am 99% sure that this is the right place to implement round robin / random style strategies. I'm just 1% sure this is currently the right way to do it. |
+ reverted to post notifications for removed, reserved and released. + Added a few more strategies that need to be benchmarked, that use the list iterator. Signed-off-by: Greg Wilkins <gregw@webtide.com>
@lorban @sbordet I know I shouldn't be playing with this... but.... I've updated to a simpler strategy that is notified after removed, reserved, released - as that makes combining strategies sensible. Anyway, this is still a draft, but have a look if you are interested.... but only once jetty-10 is ready to release. cheers |
Signed-off-by: Greg Wilkins <gregw@webtide.com>
Signed-off-by: Greg Wilkins <gregw@webtide.com>
Signed-off-by: Greg Wilkins <gregw@webtide.com>
+ pluggable strategies + hard coded Signed-off-by: Greg Wilkins <gregw@webtide.com>
Some strange benchmark results!
Ignore the garbage generated by round robin, that's a lambda I can get rid of. All the inherited behaviour ones: Pool.Linear, Pool.Thread etc. are the slowest! Virtual calls I guess. So I can see 2 ways forward:
I'm guessing @sbordet likes 1. and @lorban likes 2. ??? I'm kind of on the fence and need to be nudged either way. |
So the results show us the way:
The hard coded strategies match the pluggable strategies, except for threadlocal, in which case it is a lot better. So given the simplicity of |
…tion. Signed-off-by: Greg Wilkins <gregw@webtide.com>
@sbordet I think this is ready to use in the connection pools, but it needs changes to their constructors, so I might let you do it? |
Final benchmark results:
|
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.
Besides a few small cleanups, I like that the all-contained-and-compact design was kept. But the PR's name is now wrong.
LGTM.
Signed-off-by: Greg Wilkins <gregw@webtide.com>
Signed-off-by: Greg Wilkins <gregw@webtide.com>
jetty-documentation/src/main/asciidoc/administration/logging/jetty-server-dump.adoc
Outdated
Show resolved
Hide resolved
jetty-documentation/src/main/asciidoc/configuring/jsp/configuring-jsp.adoc
Outdated
Show resolved
Hide resolved
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
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 like a minimal javadocs for Pool.StrategyType
. Other than that, LGTM.
Speculative proposal to make Pool have a pluggable strategy for #5217