Search in sources :

Example 1 with DecomposedQueueMainProcessingUnit

use of org.openksavi.sponge.core.engine.processing.decomposed.DecomposedQueueMainProcessingUnit in project sponge by softelnet.

the class DefaultStatisticsManager method getSummary.

/**
 * Returns statistics summary.
 *
 * @return statistics summary.
 */
@Override
public String getSummary() {
    StringBuffer sb = new StringBuffer(512);
    sb.append(getQueueSummary(getEngine().getEventQueueManager().getInputEventQueue()));
    sb.append(". " + getQueueSummary(getEngine().getEventQueueManager().getMainEventQueue()));
    sb.append(". Plugins (" + getPluginCount() + ")");
    sb.append(". Actions (" + getEngine().getActions().size() + ")");
    sb.append(". Filters (" + getEngine().getFilters().size() + ")");
    sb.append(". Triggers (" + getEngine().getTriggers().size() + ")");
    sb.append(". " + getEventSetProcessorsSummary("Rules", getEngine().getRuleGroups()));
    sb.append(". " + getEventSetProcessorsSummary("Correlators", getEngine().getCorrelatorGroups()));
    sb.append(". Event scheduler (" + getScheduledEventCount() + ")");
    sb.append(". Thread pools: ");
    MainProcessingUnit mainProcessingUnit = getEngine().getProcessingUnitManager().getMainProcessingUnit();
    sb.append(getThreadPoolSummary(mainProcessingUnit.getWorkerThreadPool()));
    sb.append(", " + getThreadPoolSummary(mainProcessingUnit.getAsyncEventSetProcessorThreadPool()));
    if (mainProcessingUnit instanceof DecomposedQueueMainProcessingUnit) {
        sb.append(". " + getDecomposedQueueSummary((DecomposedQueueMainProcessingUnit) mainProcessingUnit));
    }
    sb.append(". " + getMemorySummary());
    Double eventPerformance = getEventPerformance();
    if (eventPerformance != null) {
        sb.append(String.format(". Events performance (%.2f events/s)", eventPerformance));
    }
    sb.append(".");
    return sb.toString();
}
Also used : DecomposedQueueMainProcessingUnit(org.openksavi.sponge.core.engine.processing.decomposed.DecomposedQueueMainProcessingUnit) DecomposedQueueMainProcessingUnit(org.openksavi.sponge.core.engine.processing.decomposed.DecomposedQueueMainProcessingUnit) MainProcessingUnit(org.openksavi.sponge.engine.processing.MainProcessingUnit)

Example 2 with DecomposedQueueMainProcessingUnit

use of org.openksavi.sponge.core.engine.processing.decomposed.DecomposedQueueMainProcessingUnit in project sponge by softelnet.

the class ShutdownTest method testShutdown.

private void testShutdown(int sizes) {
    EngineBuilder<DefaultSpongeEngine> builder = DefaultSpongeEngine.builder().knowledgeBase("kb", "examples/core/shutdown.py");
    // Caution: this test depends on the exact configuration values as they are specified below.
    builder.getEngineDefaultParameters().setEventQueueCapacity(1000);
    builder.getEngineDefaultParameters().setExecutorShutdownTimeout(60000);
    int eventsToBeProcessed = 0;
    // One event waits in the FilerProcessingUnit for putting into the Main Event Queue.
    eventsToBeProcessed++;
    // Some events wait in the Main Event Queue.
    builder.getEngineDefaultParameters().setMainEventQueueCapacity(sizes);
    eventsToBeProcessed += builder.getEngineDefaultParameters().getMainEventQueueCapacity();
    // One event waits in the Main Processing Unit for putting into the Decomposed Queue.
    eventsToBeProcessed++;
    // Some events wait in the Decomposed Queue.
    builder.getEngineDefaultParameters().setDecomposedQueueCapacity(sizes);
    eventsToBeProcessed += builder.getEngineDefaultParameters().getDecomposedQueueCapacity();
    // One event waits in the DecomposedQueueReaderWorker for putting into the WorkerThreadPool executor queue.
    eventsToBeProcessed++;
    // Some events wait in the the WorkerThreadPool executor queue.
    builder.getEngineDefaultParameters().setMainProcessingUnitWorkerExecutorQueueSize(sizes);
    eventsToBeProcessed += builder.getEngineDefaultParameters().getMainProcessingUnitWorkerExecutorQueueSize();
    // Some events are being processed in the WorkerThreadPool. Note that for this test assertions there should be only one thread here.
    builder.getEngineDefaultParameters().setMainProcessingUnitThreadCount(1);
    eventsToBeProcessed += builder.getEngineDefaultParameters().getMainProcessingUnitThreadCount();
    SpongeEngine engine = builder.build();
    engine.startup();
    try {
        TimeUnit.SECONDS.sleep(2);
        engine.shutdown();
        final int finalEventsToBeProcessed = eventsToBeProcessed;
        await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "finishedEvents").intValue() >= finalEventsToBeProcessed);
        assertEquals(eventsToBeProcessed, engine.getOperations().getVariable(Number.class, "finishedEvents").intValue());
        assertEquals(engine.getOperations().getVariable(Number.class, "sentEvents").intValue() - finalEventsToBeProcessed, engine.getEventQueueManager().getInputEventQueue().getSize());
        assertEquals(0, engine.getEventQueueManager().getMainEventQueue().getSize());
        DecomposedQueueMainProcessingUnit mainProcessingUnit = (DecomposedQueueMainProcessingUnit) engine.getProcessingUnitManager().getMainProcessingUnit();
        assertEquals(0, mainProcessingUnit.getDecomposedQueue().getSize());
        assertFalse(engine.isError());
    } catch (InterruptedException e) {
        fail(e.toString());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) DecomposedQueueMainProcessingUnit(org.openksavi.sponge.core.engine.processing.decomposed.DecomposedQueueMainProcessingUnit) DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Aggregations

DecomposedQueueMainProcessingUnit (org.openksavi.sponge.core.engine.processing.decomposed.DecomposedQueueMainProcessingUnit)2 DefaultSpongeEngine (org.openksavi.sponge.core.engine.DefaultSpongeEngine)1 SpongeEngine (org.openksavi.sponge.engine.SpongeEngine)1 MainProcessingUnit (org.openksavi.sponge.engine.processing.MainProcessingUnit)1