You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2015/10/08 13:11:44 UTC
svn commit: r1707492 - in
/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance:
./ AbstractPerformanceTest.java BigApplicationTest.java
ManyFeaturesWithSharedBundlesTest.java
Author: jwross
Date: Thu Oct 8 11:11:44 2015
New Revision: 1707492
URL: http://svn.apache.org/viewvc?rev=1707492&view=rev
Log:
Performance Tests
I'm not quite sure what to do with these performance tests but do not wish to risk losing them as they are important. So I'm committing them in a disabled state. Perhaps in the
future they can be scaled down a bit so the run time is not as long and configured with some sort of threshold to serve as a regression warning.
Added:
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/AbstractPerformanceTest.java (with props)
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/BigApplicationTest.java (with props)
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/ManyFeaturesWithSharedBundlesTest.java (with props)
Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/AbstractPerformanceTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/AbstractPerformanceTest.java?rev=1707492&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/AbstractPerformanceTest.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/AbstractPerformanceTest.java Thu Oct 8 11:11:44 2015
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.aries.subsystem.itests.performance;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.aries.subsystem.itests.SubsystemTest;
+import org.easymock.internal.matchers.Null;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.service.subsystem.Subsystem;
+
+public abstract class AbstractPerformanceTest extends SubsystemTest {
+ protected static final int ARRAY_SIZE_BYTES = 2048;
+ protected static final int BUNDLE_COUNT = 25;
+ protected static final int PACKAGE_COUNT = 10;
+ protected static final int THREAD_COUNT = 1;
+ protected static final int TRIAL_COUNT = 1;
+
+ protected final ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
+
+ protected void addBundles(ZipOutputStream zos, String symbolicNamePrefix, String packageNamePrefix, String importOrExport) throws IOException {
+ for (int i = 0; i < BUNDLE_COUNT; i++) {
+ String symbolicName = symbolicNamePrefix + i;
+ zos.putNextEntry(new ZipEntry(symbolicName + ".jar"));
+ InputStream is = createBundle(symbolicName, packageNamePrefix, importOrExport);
+ copy(is, zos);
+ is.close();
+ zos.closeEntry();
+ }
+ }
+
+ protected static double average(long[] values) {
+ double sum = 0;
+ for (long value : values) {
+ sum += value;
+ }
+ return sum / values.length;
+ }
+
+ protected static void copy(InputStream is, OutputStream os) throws IOException {
+ byte[] bytes = new byte[ARRAY_SIZE_BYTES];
+ int read;
+ while ((read = is.read(bytes)) != -1) {
+ os.write(bytes, 0, read);
+ }
+ }
+
+ protected InputStream createBundle(String symbolicName, String packageNamePrefix, String importOrExport) {
+ TinyBundle tinyBundle = TinyBundles.bundle();
+ tinyBundle.set(Constants.BUNDLE_SYMBOLICNAME, symbolicName);
+ StringBuilder builder = new StringBuilder(packageNamePrefix + 0);
+ for (int i = 1; i < PACKAGE_COUNT; i++) {
+ builder.append(',');
+ builder.append(packageNamePrefix + i);
+ }
+ tinyBundle.set(importOrExport, builder.toString());
+ InputStream is = tinyBundle.build();
+ return is;
+ }
+
+ protected static Collection<Callable<Null>> createUninstallSubsystemCallables(Collection<Future<Subsystem>> futures) {
+ Collection<Callable<Null>> callables = new ArrayList<Callable<Null>>(futures.size());
+ for (Future<Subsystem> future : futures) {
+ try {
+ final Subsystem subsystem = future.get();
+ callables.add(new Callable<Null>() {
+ @Override
+ public Null call() throws Exception {
+ subsystem.uninstall();
+ return null;
+ }
+ });
+ }
+ catch (Exception e) {}
+ }
+ return callables;
+ }
+
+ protected void runTrials(Collection<Callable<Subsystem>> callables) throws InterruptedException {
+ long[] times = new long[TRIAL_COUNT];
+ for (int i = 0; i < TRIAL_COUNT; i++) {
+ long start = System.currentTimeMillis();
+ Collection<Future<Subsystem>> futures = executor.invokeAll(callables);
+ long end = System.currentTimeMillis();
+ times[i] = end - start;
+ System.out.println("Trial " + i + " took " + times[i] + " ms");
+ uninstallSubsystems(futures);
+ }
+ System.out.println("Average time across " + TRIAL_COUNT + " trials: " + average(times) + " ms");
+ executor.shutdownNow();
+ }
+
+ protected void uninstallSubsystems(Collection<Future<Subsystem>> futures) throws InterruptedException {
+ Collection<Callable<Null>> callables = createUninstallSubsystemCallables(futures);
+ executor.invokeAll(callables);
+ }
+}
Propchange: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/AbstractPerformanceTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/BigApplicationTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/BigApplicationTest.java?rev=1707492&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/BigApplicationTest.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/BigApplicationTest.java Thu Oct 8 11:11:44 2015
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.aries.subsystem.itests.performance;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.aries.subsystem.core.archive.PreferredProviderHeader;
+import org.apache.aries.subsystem.core.archive.SubsystemManifest;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemConstants;
+
+public class BigApplicationTest extends AbstractPerformanceTest {
+ public static void main(String[] args) throws IOException {
+ BigApplicationTest test = new BigApplicationTest();
+ InputStream is = test.createApplication("application");
+ FileOutputStream fos = new FileOutputStream("application.esa");
+ copy(is, fos);
+ is.close();
+ fos.close();
+ }
+
+ @Test
+ @org.junit.Ignore
+ public void testBigApplication() throws Exception {
+ runTrials(createCallables());
+ }
+
+ private InputStream createApplication(String symbolicName) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ZipOutputStream zos = new ZipOutputStream(baos);
+ addBundles(zos, "preferredbundle", "package", Constants.EXPORT_PACKAGE);
+ addBundles(zos, "exportbundle", "package", Constants.EXPORT_PACKAGE);
+ addBundles(zos, "importbundle", "package", Constants.IMPORT_PACKAGE);
+ zos.putNextEntry(new ZipEntry("OSGI-INF/SUBSYSTEM.MF"));
+ StringBuilder preferredProviders = new StringBuilder("preferredbundle0;type=osgi.bundle");
+ for (int i = 1; i < BUNDLE_COUNT; i++) {
+ preferredProviders.append(",preferredbundle").append(i).append(";type=osgi.bundle");
+ }
+ new SubsystemManifest.Builder()
+ .symbolicName(symbolicName)
+ .type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION)
+ .header(new PreferredProviderHeader(preferredProviders.toString()))
+ .build()
+ .write(zos);
+ zos.closeEntry();
+ zos.close();
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+
+ private Collection<Callable<Subsystem>> createCallables() {
+ Callable<Subsystem> callable = new Callable<Subsystem>() {
+ @Override
+ public Subsystem call() throws Exception {
+ Subsystem subsystem = getRootSubsystem().install("application", createApplication("application"));
+ return subsystem;
+ }
+ };
+ return Collections.singletonList(callable);
+ }
+}
Propchange: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/BigApplicationTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/ManyFeaturesWithSharedBundlesTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/ManyFeaturesWithSharedBundlesTest.java?rev=1707492&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/ManyFeaturesWithSharedBundlesTest.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/ManyFeaturesWithSharedBundlesTest.java Thu Oct 8 11:11:44 2015
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.aries.subsystem.itests.performance;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.aries.subsystem.core.archive.PreferredProviderHeader;
+import org.apache.aries.subsystem.core.archive.SubsystemManifest;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemConstants;
+
+public class ManyFeaturesWithSharedBundlesTest extends AbstractPerformanceTest {
+ private static final int FEATURE_COUNT = 50;
+
+ public static void main(String[] args) throws IOException {
+ ManyFeaturesWithSharedBundlesTest test = new ManyFeaturesWithSharedBundlesTest();
+ InputStream is = test.createFeature("feature");
+ FileOutputStream fos = new FileOutputStream("feature.esa");
+ copy(is, fos);
+ is.close();
+ fos.close();
+ }
+
+ @Test
+ @org.junit.Ignore
+ public void testInstallAllFeatures() throws Exception {
+ Collection<Callable<Subsystem>> callables = createInstallFeatureCallables();
+ runTrials(callables);
+ }
+
+ @Test
+ @org.junit.Ignore
+ public void testInstallOneFeatureAfterAll() throws Exception {
+ Collection<Callable<Subsystem>> callables = createInstallFeatureCallables();
+ Collection<Future<Subsystem>> futures = executor.invokeAll(callables);
+ Callable<Subsystem> callable = new Callable<Subsystem>() {
+ @Override
+ public Subsystem call() throws Exception {
+ Subsystem feature = getRootSubsystem().install("onefeature", createFeature("onefeature"));
+ return feature;
+ }
+ };
+ runTrials(Collections.singletonList(callable));
+ uninstallSubsystems(futures);
+ }
+
+ private InputStream createApplication(String symbolicName) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ZipOutputStream zos = new ZipOutputStream(baos);
+ addBundles(zos, "applicationbundle", "package", Constants.IMPORT_PACKAGE);
+ zos.putNextEntry(new ZipEntry("OSGI-INF/SUBSYSTEM.MF"));
+ StringBuilder preferredProviders = new StringBuilder("featurebundle0;type=osgi.bundle");
+ for (int i = 1; i < BUNDLE_COUNT; i++) {
+ preferredProviders.append(",featurebundle").append(i).append(";type=osgi.bundle");
+ }
+ new SubsystemManifest.Builder()
+ .symbolicName(symbolicName)
+ .type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION)
+ .header(new PreferredProviderHeader(preferredProviders.toString()))
+ .build()
+ .write(zos);
+ zos.closeEntry();
+ zos.close();
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+
+ private InputStream createFeature(String symbolicName) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ZipOutputStream zos = new ZipOutputStream(baos);
+ addBundles(zos, "featurebundle", "package", Constants.EXPORT_PACKAGE);
+ zos.putNextEntry(new ZipEntry("application.esa"));
+ copy(createApplication("application"), zos);
+ zos.closeEntry();
+ zos.putNextEntry(new ZipEntry("OSGI-INF/SUBSYSTEM.MF"));
+ new SubsystemManifest.Builder()
+ .symbolicName(symbolicName)
+ .type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE)
+ .build()
+ .write(zos);
+ zos.closeEntry();
+ zos.close();
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+
+ private Collection<Callable<Subsystem>> createInstallFeatureCallables() {
+ Collection<Callable<Subsystem>> callables = new ArrayList<Callable<Subsystem>>(FEATURE_COUNT);
+ for (int i = 0; i < FEATURE_COUNT; i++) {
+ final int count = i;
+ callables.add(new Callable<Subsystem>() {
+ @Override
+ public Subsystem call() throws Exception {
+ Subsystem feature = getRootSubsystem().install("feature" + count, createFeature("feature" + count));
+ System.out.println("Installed feature " + count);
+ return feature;
+ }
+ });
+ }
+ return callables;
+ }
+}
Propchange: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/performance/ManyFeaturesWithSharedBundlesTest.java
------------------------------------------------------------------------------
svn:executable = *