minor cleanups
This commit is contained in:
parent
c7aa64aa10
commit
cfabbd2341
|
@ -129,7 +129,6 @@ public class HTTP2Client extends ContainerLifeCycle
|
|||
private int initialSessionRecvWindow = FlowControlStrategy.DEFAULT_WINDOW_SIZE;
|
||||
private int initialStreamRecvWindow = FlowControlStrategy.DEFAULT_WINDOW_SIZE;
|
||||
private FlowControlStrategy.Factory flowControlStrategyFactory = () -> new BufferingFlowControlStrategy(0.5F);
|
||||
private ExecutionStrategy.Factory executionStrategyFactory = new ProduceConsume.Factory();
|
||||
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
|
|
|
@ -76,7 +76,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
_id = id;
|
||||
SelectorProducer producer = new SelectorProducer();
|
||||
Executor executor = selectorManager.getExecutor();
|
||||
_strategy = new EatWhatYouKill(producer, executor, Invocable.InvocationType.NON_BLOCKING, Invocable.InvocationType.BLOCKING);
|
||||
_strategy = new EatWhatYouKill(producer,executor);
|
||||
addBean(_strategy);
|
||||
setStopTimeout(5000);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.concurrent.RejectedExecutionException;
|
|||
import org.eclipse.jetty.util.Loader;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.thread.strategy.EatWhatYouKill;
|
||||
import org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume;
|
||||
|
||||
/**
|
||||
|
@ -73,55 +74,4 @@ public interface ExecutionStrategy
|
|||
Runnable produce();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>A factory for {@link ExecutionStrategy}.</p>
|
||||
*/
|
||||
public static interface Factory
|
||||
{
|
||||
/**
|
||||
* <p>Creates a new {@link ExecutionStrategy}.</p>
|
||||
*
|
||||
* @param producer the execution strategy producer
|
||||
* @param executor the execution strategy executor
|
||||
* @return a new {@link ExecutionStrategy}
|
||||
*/
|
||||
public ExecutionStrategy newExecutionStrategy(Producer producer, Executor executor);
|
||||
|
||||
/**
|
||||
* @return the default {@link ExecutionStrategy}
|
||||
*/
|
||||
public static Factory getDefault()
|
||||
{
|
||||
return DefaultExecutionStrategyFactory.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DefaultExecutionStrategyFactory implements Factory
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(Factory.class);
|
||||
private static final Factory INSTANCE = new DefaultExecutionStrategyFactory();
|
||||
|
||||
@Override
|
||||
public ExecutionStrategy newExecutionStrategy(Producer producer, Executor executor)
|
||||
{
|
||||
String strategy = System.getProperty(producer.getClass().getName() + ".ExecutionStrategy");
|
||||
if (strategy != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<? extends ExecutionStrategy> c = Loader.loadClass(strategy);
|
||||
Constructor<? extends ExecutionStrategy> m = c.getConstructor(Producer.class, Executor.class);
|
||||
LOG.info("Use {} for {}", c.getSimpleName(), producer.getClass().getName());
|
||||
return m.newInstance(producer, executor);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
return new ExecuteProduceConsume(producer, executor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,17 +32,30 @@ import org.eclipse.jetty.util.thread.Locker;
|
|||
import org.eclipse.jetty.util.thread.Locker.Lock;
|
||||
|
||||
/**
|
||||
* <p>A strategy where the thread that produces will always run the resulting task.</p>
|
||||
* <p>The strategy may then dispatch another thread to continue production.</p>
|
||||
* <p>The strategy is also known by the nickname 'eat what you kill', which comes from
|
||||
* the hunting ethic that says a person should not kill anything he or she does not
|
||||
* plan on eating. In this case, the phrase is used to mean that a thread should
|
||||
* not produce a task that it does not intend to run. By making producers run the
|
||||
* task that they have just produced avoids execution delays and avoids parallel slow
|
||||
* down by running the task in the same core, with good chances of having a hot CPU
|
||||
* cache. It also avoids the creation of a queue of produced tasks that the system
|
||||
* does not yet have capacity to consume, which can save memory and exert back
|
||||
* pressure on producers.</p>
|
||||
* <p>A strategy where the thread that produces will run the resulting task if it
|
||||
* is possible to do so without thread starvation.</p>
|
||||
*
|
||||
* <p>This strategy preemptively dispatches a thread as a pending producer, so that
|
||||
* when a thread produces a task it can immediately run the task and let the pending
|
||||
* producer thread take over producing. If necessary another thread will be dispatched
|
||||
* to replace the pending producing thread. When operating in this pattern, the
|
||||
* sub-strategy is called Execute Produce Consume (EPC)
|
||||
* </p>
|
||||
* <p>However, if the task produced uses the {@link Invocable} API to indicate that
|
||||
* it will not block, then the strategy will run it directly, regardless of the
|
||||
* presence of a pending producing thread and then resume producing after the
|
||||
* task has completed. This sub-strategy is also used if the strategy has been
|
||||
* configured with a maximum of 0 pending threads and the thread currently producing
|
||||
* does not use the {@link Invocable} API to indicate that it will not block.
|
||||
* When operating in this pattern, the sub-strategy is called
|
||||
* ProduceConsume (PC).
|
||||
* </p>
|
||||
* <p>If there is no pending producer thread available and if the task has not
|
||||
* indicated it is non-blocking, then this strategy will dispatch the execution of
|
||||
* the task and immediately continue producing. When operating in this pattern, the
|
||||
* sub-strategy is called ProduceExecuteConsume (PEC).
|
||||
* </p>
|
||||
*
|
||||
*/
|
||||
public class EatWhatYouKill extends AbstractLifeCycle implements ExecutionStrategy, Runnable
|
||||
{
|
||||
|
@ -73,7 +86,7 @@ public class EatWhatYouKill extends AbstractLifeCycle implements ExecutionStrate
|
|||
|
||||
public EatWhatYouKill(Producer producer, Executor executor, InvocationType preferredInvocationPEC, InvocationType preferredInvocationEPC)
|
||||
{
|
||||
this(producer,executor,preferredInvocationPEC,preferredInvocationEPC,1);
|
||||
this(producer,executor,preferredInvocationPEC,preferredInvocationEPC,Integer.getInteger("org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.maxProducersPending",1));
|
||||
}
|
||||
|
||||
public EatWhatYouKill(Producer producer, Executor executor, InvocationType preferredInvocationPEC, InvocationType preferredInvocationEPC, int maxProducersPending )
|
||||
|
@ -110,7 +123,7 @@ public class EatWhatYouKill extends AbstractLifeCycle implements ExecutionStrate
|
|||
LOG.debug("{} execute {}", this, produce);
|
||||
|
||||
if (produce)
|
||||
produceConsume();
|
||||
doProduce();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -183,10 +196,10 @@ public class EatWhatYouKill extends AbstractLifeCycle implements ExecutionStrate
|
|||
}
|
||||
|
||||
if (producing)
|
||||
produceConsume();
|
||||
doProduce();
|
||||
}
|
||||
|
||||
private void produceConsume()
|
||||
private void doProduce()
|
||||
{
|
||||
boolean may_block_caller = !Invocable.isNonBlockingInvocation();
|
||||
if (LOG.isDebugEnabled())
|
||||
|
@ -358,13 +371,4 @@ public class EatWhatYouKill extends AbstractLifeCycle implements ExecutionStrate
|
|||
produce();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Factory implements ExecutionStrategy.Factory
|
||||
{
|
||||
@Override
|
||||
public ExecutionStrategy newExecutionStrategy(Producer producer, Executor executor)
|
||||
{
|
||||
return new EatWhatYouKill(producer, executor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -249,13 +249,4 @@ public class ExecuteProduceConsume implements ExecutionStrategy, Runnable
|
|||
produce();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Factory implements ExecutionStrategy.Factory
|
||||
{
|
||||
@Override
|
||||
public ExecutionStrategy newExecutionStrategy(Producer producer, Executor executor)
|
||||
{
|
||||
return new ExecuteProduceConsume(producer, executor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,15 +106,6 @@ public class ProduceConsume implements ExecutionStrategy, Runnable
|
|||
produce();
|
||||
}
|
||||
|
||||
public static class Factory implements ExecutionStrategy.Factory
|
||||
{
|
||||
@Override
|
||||
public ExecutionStrategy newExecutionStrategy(Producer producer, Executor executor)
|
||||
{
|
||||
return new ProduceConsume(producer, executor);
|
||||
}
|
||||
}
|
||||
|
||||
private enum State
|
||||
{
|
||||
IDLE, PRODUCE, EXECUTE
|
||||
|
|
|
@ -107,15 +107,6 @@ public class ProduceExecuteConsume implements ExecutionStrategy
|
|||
produce();
|
||||
}
|
||||
|
||||
public static class Factory implements ExecutionStrategy.Factory
|
||||
{
|
||||
@Override
|
||||
public ExecutionStrategy newExecutionStrategy(Producer producer, Executor executor)
|
||||
{
|
||||
return new ProduceExecuteConsume(producer, executor);
|
||||
}
|
||||
}
|
||||
|
||||
private enum State
|
||||
{
|
||||
IDLE, PRODUCE, EXECUTE
|
||||
|
|
Loading…
Reference in New Issue