Skip to content
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

Merged
merged 27 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b63c59d
Speculative idea to make a pluggable Pool strategy
gregw Sep 1, 2020
410fe53
Speculative idea to make a pluggable Pool strategy
gregw Sep 1, 2020
27d31de
Speculative idea to make a pluggable Pool strategy
gregw Sep 1, 2020
91df8da
Speculative idea to make a pluggable Pool strategy
gregw Sep 1, 2020
db086a5
Feedback from review
gregw Sep 2, 2020
6ab7bd7
Feedback from review
gregw Sep 2, 2020
e250a49
Feedback from review
gregw Sep 2, 2020
5053216
Improved Pool Strategies:
gregw Sep 7, 2020
d9abdeb
Testing all the different strategies
gregw Sep 8, 2020
0aa6bc9
More simplifications and made LRU work (ish)
gregw Sep 8, 2020
15ab226
javadoc
gregw Sep 8, 2020
c18a77e
More javadoc
gregw Sep 8, 2020
8906678
JMH Test
gregw Sep 9, 2020
feda65d
one strategy
gregw Sep 10, 2020
0b0030d
test
gregw Sep 10, 2020
bf520b4
Split implementations:
gregw Sep 10, 2020
e915784
More benchmarks
gregw Sep 10, 2020
db00126
Built in strategy
gregw Sep 10, 2020
69fe8f6
removed strategies version and simplified to single configurable solu…
gregw Sep 10, 2020
68bf2b5
updates from review
gregw Sep 10, 2020
225b096
better javadoc
gregw Sep 10, 2020
46d1819
Merge branch 'jetty-9.4.x' into jetty-9.4.x-PoolStrategy
gregw Sep 15, 2020
1ef761e
Updated ConnectionPool classes to use Pool strategies
gregw Sep 15, 2020
f9773d5
Small javadocs fixes.
sbordet Sep 16, 2020
4504fee
Merge branch 'jetty-9.4.x' into jetty-9.4.x-PoolStrategy
gregw Sep 16, 2020
6c90442
Updates from review
gregw Sep 16, 2020
21f93c6
javadoc
gregw Sep 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected AbstractConnectionPool(HttpDestination destination, int maxConnections
Pool<Connection> pool = destination.getBean(Pool.class);
if (pool == null)
{
pool = new Pool<>(maxConnections, cache ? 1 : 0);
pool = new Pool<>(Pool.Strategy.LINEAR, maxConnections, cache);
destination.addBean(pool);
}
this.pool = pool;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//

package org.eclipse.jetty.util;

import java.util.concurrent.atomic.LongAdder;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@State(Scope.Benchmark)
public class PoolStrategyBenchmark
{
private Pool<String> pool;

@Param({
"Pool.Linear",
"Pool.Random",
"Pool.RoundRobin",
"Pool.ThreadId",
})
public static String POOL_TYPE;

@Param({
"false",
"true",
})
public static boolean CACHE;

@Param({
"4",
"16"
})
public static int SIZE;

private static final LongAdder misses = new LongAdder();
private static final LongAdder hits = new LongAdder();
private static final LongAdder total = new LongAdder();

@Setup
public void setUp() throws Exception
{
misses.reset();

switch (POOL_TYPE)
{
case "Pool.Linear" :
pool = new Pool<>(Pool.Strategy.LINEAR, SIZE, CACHE);
break;
case "Pool.Random" :
pool = new Pool<>(Pool.Strategy.RANDOM, SIZE, CACHE);
break;
case "Pool.ThreadId" :
pool = new Pool<>(Pool.Strategy.THREAD_ID, SIZE, CACHE);
break;
case "Pool.RoundRobin" :
pool = new Pool<>(Pool.Strategy.ROUND_ROBIN, SIZE, CACHE);
break;

default:
throw new IllegalStateException();
}

for (int i = 0; i < SIZE; i++)
{
pool.reserve(1).enable(Integer.toString(i), false);
}
}

@TearDown
public void tearDown()
{
System.err.printf("%nMISSES = %d (%d%%)%n", misses.longValue(), 100 * misses.longValue() / (hits.longValue() + misses.longValue()));
System.err.printf("AVERAGE = %d%n", total.longValue() / hits.longValue());
pool.close();
pool = null;
}

@Benchmark
public void testAcquireReleasePoolWithStrategy()
{
// Now really benchmark the strategy we are interested in
Pool<String>.Entry entry = pool.acquire();
if (entry == null || entry.isIdle())
{
misses.increment();
Blackhole.consumeCPU(20);
return;
}
// do some work
hits.increment();
total.add(Long.parseLong(entry.getPooled()));
Blackhole.consumeCPU(entry.getPooled().hashCode() % 20);

// release the entry
entry.release();
}

public static void main(String[] args) throws RunnerException
{
Options opt = new OptionsBuilder()
.include(PoolStrategyBenchmark.class.getSimpleName())
.warmupIterations(3)
.measurementIterations(3)
.forks(1)
.threads(8)
.resultFormat(ResultFormatType.JSON)
.result("/tmp/poolStrategy-" + System.currentTimeMillis() + ".json")
// .addProfiler(GCProfiler.class)
.build();

new Runner(opt).run();
}
}