diff options
Diffstat (limited to 'testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark')
3 files changed, 368 insertions, 0 deletions
diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexBaseBenchMarkTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexBaseBenchMarkTest.java new file mode 100644 index 000000000..363811978 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexBaseBenchMarkTest.java @@ -0,0 +1,139 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.policy.apex.service.engine.benchmark; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.core.engine.EngineParameters; +import org.onap.policy.apex.core.engine.ExecutorParameters; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters; +import org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters; +import org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters; +import org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters; +import org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters; +import org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters; +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.runtime.ApexEventListener; +import org.onap.policy.apex.service.engine.runtime.ApexServiceModelUpdateTest; +import org.onap.policy.apex.service.engine.runtime.EngineService; +import org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface; +import org.onap.policy.apex.service.engine.runtime.impl.EngineServiceImpl; +import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +public class ApexBaseBenchMarkTest { + private static final long STOP_TIME_OUT = TimeUnit.SECONDS.toMillis(30); + private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexServiceModelUpdateTest.class); + private static final long MAX_START_WAIT = TimeUnit.SECONDS.toMillis(10); + private final AxArtifactKey engineServiceKey = new AxArtifactKey("Machine-1_process-1_engine-1", "0.0.0"); + private final String model; + private final int threads; + private final ApexEventListener listener; + private EngineService service; + private EngineServiceEventInterface engineServiceEventInterface; + + + public ApexBaseBenchMarkTest(final String model, final int threads, final ApexEventListener listener) { + this.model = model; + this.threads = threads; + this.listener = listener; + } + + public void setUp() throws Exception { + final EngineServiceParameters parameters = new EngineServiceParameters(); + parameters.setInstanceCount(threads); + parameters.setName(engineServiceKey.getName()); + parameters.setVersion(engineServiceKey.getVersion()); + parameters.setId(100); + + final EngineParameters engineParameters = parameters.getEngineParameters(); + final Map<String, ExecutorParameters> executorParameterMap = engineParameters.getExecutorParameterMap(); + executorParameterMap.put("MVEL", new MVELExecutorParameters()); + executorParameterMap.put("JAVASCRIPT", new JavascriptExecutorParameters()); + executorParameterMap.put("JYTHON", new JythonExecutorParameters()); + executorParameterMap.put("JAVA", new JavaExecutorParameters()); + executorParameterMap.put("JRUBY", new JrubyExecutorParameters()); + + final ContextParameters contextParameters = engineParameters.getContextParameters(); + final SchemaParameters schemaParameters = contextParameters.getSchemaParameters(); + schemaParameters.getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + schemaParameters.getSchemaHelperParameterMap().put("Java", new JavaSchemaHelperParameters()); + service = EngineServiceImpl.create(parameters); + + service = EngineServiceImpl.create(parameters); + service.registerActionListener("listener", listener); + service.updateModel(parameters.getEngineKey(), model, true); + + LOGGER.info("Starting EngineService ... "); + service.startAll(); + + final long starttime = System.currentTimeMillis(); + while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { + ThreadUtilities.sleep(50); + } + if (!service.isStarted()) { + LOGGER.error("Apex Service {} failed to start after {} ms", service.getKey(), MAX_START_WAIT); + new ApexException("Unable to start engine service "); + } + + engineServiceEventInterface = service.getEngineServiceEventInterface(); + } + + public void sendEvents(final List<ApexEvent> events) { + for (final ApexEvent event : events) { + engineServiceEventInterface.sendEvent(event); + } + } + + public void sendEvent(final ApexEvent event) { + engineServiceEventInterface.sendEvent(event); + } + + + public EngineService getService() { + return service; + } + + public void destroy() throws Exception { + if (service != null) { + LOGGER.info("Stopping EngineService ... "); + service.stop(); + final long currentTimeInMillSec = System.currentTimeMillis(); + while (!service.isStopped()) { + if (System.currentTimeMillis() - currentTimeInMillSec > STOP_TIME_OUT) { + LOGGER.warn("Timed Out EngineService status: ", service.isStopped()); + break; + } + ThreadUtilities.sleep(500); + } + service = null; + } + } + +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexEngineBenchmark.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexEngineBenchmark.java new file mode 100644 index 000000000..d7a4ef800 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexEngineBenchmark.java @@ -0,0 +1,137 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.service.engine.benchmark; + +import static org.junit.Assert.assertEquals; + +import java.util.concurrent.TimeUnit; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.utils.Utils; +import org.onap.policy.apex.test.common.model.EvalDomainModelFactory; +import org.python.icu.impl.Assert; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class ApexEngineBenchmark. + */ +public class ApexEngineBenchmark { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEngineBenchmark.class); + + private static final String TARGET = "apex"; + private static final String SOURCE = "test"; + private static final String NAME = "Event0000"; + private static final String VERSION = "0.0.1"; + private static final String PACKAGE = "org.onap.policy.apex.domains.sample.events"; + + private static final long TIME_OUT_IN_MILLISEC = TimeUnit.MINUTES.toMillis(1); + + private String apexECAModelString; + private String apexOODAModelString; + + @Before + public void setUp() throws Exception { + apexECAModelString = Utils.getModelString(new EvalDomainModelFactory().getECAPolicyModel()); + apexOODAModelString = Utils.getModelString(new EvalDomainModelFactory().getOODAPolicyModel()); + } + + @Test + public void testBenchmark_SingletonWorker() throws Exception { + executeTest(apexECAModelString, 100, 1, 20); + executeTest(apexOODAModelString, 100, 1, 20); + } + + @Test + public void testBenchmark_3ThreadWorker() throws Exception { + executeTest(apexECAModelString, 1000, 3, 10); + executeTest(apexOODAModelString, 100, 3, 10); + } + + @Test + public void testBenchmark_10ThreadWorker() throws Exception { + executeTest(apexECAModelString, 2000, 10, 10); + executeTest(apexOODAModelString, 2000, 10, 10); + } + + @Test + public void testBenchmark_50ThreadWorker() throws Exception { + executeTest(apexECAModelString, 3000, 50, 10); + executeTest(apexOODAModelString, 3000, 50, 10); + } + + @Test + public void TestE_AvailableProcessorsThreadWorker() throws Exception { + final int cores = Runtime.getRuntime().availableProcessors(); + executeTest(apexECAModelString, 3000, cores, 10); + executeTest(apexOODAModelString, 3000, cores, 10); + } + + private void executeTest(final String policyModel, final int eventsCount, final int threads, final int loop) + throws Exception { + + LOGGER.info("Running Test with Event count: {}, Instance count: {} and loop: {}", eventsCount, threads, loop); + final TestApexEventListener apexEventListener = new TestApexEventListener(); + + final ApexBaseBenchMarkTest apexBaseBenchMarkTest = + new ApexBaseBenchMarkTest(policyModel, threads, apexEventListener); + + try { + apexBaseBenchMarkTest.setUp(); + for (int i = 0; i < loop; i++) { + sendEvents(apexBaseBenchMarkTest, eventsCount); + final long currentTimeInMillSec = System.currentTimeMillis(); + while (apexEventListener.getEventReceived() < eventsCount) { + if (System.currentTimeMillis() - currentTimeInMillSec > TIME_OUT_IN_MILLISEC) { + LOGGER.warn("Wait timed out ... "); + break; + } + ThreadUtilities.sleep(500); + } + assertEquals(eventsCount, apexEventListener.getEventReceived()); + apexEventListener.printResult(); + apexEventListener.reset(); + } + } catch (final Exception exception) { + Assert.fail(exception); + } finally { + apexBaseBenchMarkTest.destroy(); + LOGGER.info("Finished Running Test with Event count: {}, Instance count: {} and loop: {}", eventsCount, + threads, loop); + } + } + + public void sendEvents(final ApexBaseBenchMarkTest apexBaseBenchMarkTest, final int eventsCount) throws Exception { + for (int eventNum = 0; eventNum < eventsCount; eventNum++) { + final long currentTimeMillis = System.currentTimeMillis(); + final ApexEvent event = new ApexEvent(NAME, VERSION, PACKAGE, SOURCE, TARGET); + event.put("TestTemperature", eventNum); + event.put("FirstEventTimestamp", currentTimeMillis); + event.put("SentTimestamp", currentTimeMillis); + event.put("EventNumber", eventNum); + apexBaseBenchMarkTest.sendEvent(event); + } + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/TestApexEventListener.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/TestApexEventListener.java new file mode 100644 index 000000000..b2de8f072 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/TestApexEventListener.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.policy.apex.service.engine.benchmark; + +import static org.junit.Assert.assertNull; + +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.atomic.AtomicLong; + +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.runtime.ApexEventListener; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +public class TestApexEventListener implements ApexEventListener { + + private static final String SENT_TIMESTAMP = "SentTimestamp"; + private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestApexEventListener.class); + private static final String RECVD_TIMESTAMP = "RecvdTimestamp"; + private Queue<ApexEvent> queue; + + private final AtomicLong eventReceived = new AtomicLong(); + + public TestApexEventListener() { + this.queue = new ConcurrentLinkedQueue<ApexEvent>(); + } + + @Override + public void onApexEvent(final ApexEvent apexEvent) { + apexEvent.put(RECVD_TIMESTAMP, System.currentTimeMillis()); + eventReceived.incrementAndGet(); + queue.add(apexEvent); + } + + public void printResult() { + if (!queue.isEmpty()) { + long maxTimeInMilliSeconds = 0; + long minTimeInMilliSeconds = Long.MAX_VALUE; + final long numEvents = queue.size(); + long totalTimeInMilliSeconds = 0; + for (final ApexEvent apexEvent : queue) { + assertNull(apexEvent.getExceptionMessage()); + final Long endTimeInMilliSeconds = (Long) apexEvent.get(RECVD_TIMESTAMP); + final Long startTimeInMilliSeconds = (Long) apexEvent.get(SENT_TIMESTAMP); + final long timeTaken = endTimeInMilliSeconds - startTimeInMilliSeconds; + totalTimeInMilliSeconds += timeTaken; + if (timeTaken > maxTimeInMilliSeconds) { + maxTimeInMilliSeconds = timeTaken; + } + if (timeTaken < minTimeInMilliSeconds) { + minTimeInMilliSeconds = timeTaken; + } + } + LOGGER.info("Average Time Taken to process {} events: {} ms", numEvents, + (totalTimeInMilliSeconds / numEvents)); + LOGGER.info("Max Time Taken: {} ms", maxTimeInMilliSeconds); + LOGGER.info("Min Time Taken: {} ms", minTimeInMilliSeconds); + } + } + + public void reset() { + this.queue = new ConcurrentLinkedQueue<ApexEvent>(); + eventReceived.set(0);; + } + + public Queue<ApexEvent> getQueue() { + return queue; + } + + public long getEventReceived() { + return eventReceived.get(); + } + +} |