moved new dm4 from sandbox to trunk.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1663056 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/.classpath b/dependencymanager/org.apache.felix.dependencymanager.benchmark/.classpath
new file mode 100644
index 0000000..57c70f3
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="bin" path="src"/>
+	<classpathentry kind="src" output="bin_test" path="test"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+	<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/.gitignore b/dependencymanager/org.apache.felix.dependencymanager.benchmark/.gitignore
new file mode 100644
index 0000000..90dde36
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/.gitignore
@@ -0,0 +1,3 @@
+/bin/
+/bin_test/
+/generated/
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/.project b/dependencymanager/org.apache.felix.dependencymanager.benchmark/.project
new file mode 100644
index 0000000..e601a91
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.apache.felix.dependencymanager.benchmark</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>bndtools.core.bndbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>bndtools.core.bndnature</nature>
+	</natures>
+</projectDescription>
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/.settings/org.eclipse.jdt.core.prefs b/dependencymanager/org.apache.felix.dependencymanager.benchmark/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..a698e59
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/README b/dependencymanager/org.apache.felix.dependencymanager.benchmark/README
new file mode 100644
index 0000000..ff032fe
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/README
@@ -0,0 +1,182 @@
+/*
+ * 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.
+ */
+
+Installation:
+============
+
+- see toplevel README on how to import dependencymanager into bndtools
+
+How to launch the stress test under bndtools:
+============================================
+
+The stress test performs two kind of tests on DM and parallel DM.
+
+1) first kind of tests: starts/stops several times each tested bundle (DM/Parallel DM). When
+started, the test bundle is expected to register/unregister several services. And no processing is
+done at all in each component start methods).
+
+2) second kind of tests: same as before, but some processing is done in each component start methods.
+
+To launch the stress test under BndTools, click on the noindex.bndrun file of the
+"org.apache.felix.dm.benchmark" project, then click on "Run", then in "Run OSGi". 
+
+You should see something like that in the eclipse console:
+
+>> --------------------------------------------------------------------------------------------------------------
+g! Starting benchmarks (each tested bundle will add/remove 630 components during bundle activation).
+
+	[Starting benchmarks with no processing done in components start methods]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager ....................
+-> results in nanos: [189,130,687 | 205,730,144 | 312,092,102 | 357,470,857 | 871,419,487]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager.parallel ....................
+-> results in nanos: [85,158,366 | 103,439,337 | 122,633,515 | 157,082,407 | 284,332,202]
+
+	[Starting benchmarks with processing done in components start methods]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager .....
+-> results in nanos: [2,748,431,149 | 2,750,475,610 | 2,756,254,193 | 2,772,447,115 | 2,774,345,245]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager.parallel .....
+-> results in nanos: [687,259,058 | 696,725,568 | 700,220,615 | 704,310,739 | 740,325,481]
+-----------------------------------------------------------------------------------------------------------------
+
+You can also possibly run the same test using optimized DM filter indices.
+To do so, run "index.bndrun"
+but using DM filter indices has a CPU cost and are useful if you have many service dependencies.
+To test filter indices, first increase the number of components created/removed during bundle
+startup. To do so, edit the Artist.java and change the "Artists" when is by default set to 30, and set it to 300.
+
+You should then observe some significant performance improvements:
+
+for example, with Artist.ARTISTS=300, you should observe the following:
+
+noindex.bndrun (no filter indices used):
+
+>> --------------------------------------------------------------------------------------------------------------
+ g! Starting benchmarks (each tested bundle will add/remove 6300 components during bundle activation).
+
+        [Starting benchmarks with no processing done in components start methods]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager .....
+-> results in nanos: [17,436,869,644 | 17,525,534,346 | 18,080,624,001 | 18,246,597,908 | 20,715,696,669]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager.parallel .....
+-> results in nanos: [9,660,520,501 | 9,810,057,488 | 9,870,295,166 | 10,014,334,906 | 10,628,193,815]
+
+        [Starting benchmarks with processing done in components start methods]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager .....
+-> results in nanos: [42,700,651,438 | 43,207,156,615 | 43,653,372,523 | 43,869,438,994 | 44,715,701,457]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager.parallel .....
+-> results in nanos: [15,021,876,153 | 15,091,340,552 | 15,202,305,936 | 15,248,728,826 | 15,398,221,492]
+-----------------------------------------------------------------------------------------------------------------
+ 
+and with index.bndrun (using DM filter indices):
+
+>> --------------------------------------------------------------------------------------------------------------
+g! Starting benchmarks (each tested bundle will add/remove 6300 components during bundle activation).
+
+        [Starting benchmarks with no processing done in components start methods]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager .....
+-> results in nanos: [3,142,869,517 | 3,564,970,695 | 4,023,603,870 | 6,206,640,362 | 6,918,113,818]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager.parallel .....
+-> results in nanos: [2,868,554,914 | 2,873,491,201 | 2,897,439,973 | 2,913,317,331 | 3,890,123,728]
+
+        [Starting benchmarks with processing done in components start methods]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager .....
+-> results in nanos: [28,515,623,505 | 28,558,774,886 | 28,661,315,061 | 28,808,682,302 | 28,915,519,208]
+
+Benchmarking bundle: org.apache.felix.dependencymanager.benchmark.dependencymanager.parallel .....
+-> results in nanos: [7,702,400,991 | 7,749,145,806 | 7,760,650,323 | 7,832,386,237 | 7,854,739,136]
+-----------------------------------------------------------------------------------------------------------------
+ 
+
+How to interpret results:
+========================
+
+for each tested bundle, the time spent is displayed in nanos.
+for example: 
+
+	-> results in nanos: [85,158,366 | 103,439,337 | 122,633,515 | 157,082,407 | 284,332,202]
+
+Here is how to interpret the results: when testing a bundle, the benchmark controller starts/stops
+it many times, then the elapsed time used to start the bundle, activate/deactivate all services, and
+stop the bundle is recorded in a list. Then this list is sorted: the first entry is the fastest
+execution time, the last entry is the slowest. the middle one is the average. We display the first
+entry (fastest), the entry at 1/4 of the list, the middle of the list, the entry at 3/4 of the list,
+and the last entry (slowest time).
+
+We don't do an average, because usually, when running benchmark, some measurements don't reflect
+reality, especially, when there is a full GC or when the JVM is warming up. (we actually do the same
+as in Java Chronicle: https://github.com/peter-lawrey/Java-Chronicle). 
+
+Stress test scenario description
+--------------------------------
+
+For sake of simplicity, a simple scenario domain is used (actually, this example domain has been
+inspired from the "Java8 Lambdas" book, O'reilly): We have the following services: 
+
+"Artist" service: An Artist is an individual or group of musicians, who creates some "Albums". One
+Artist service depends on several Album services. 
+
+"Album" service: is a single release of musics, comprising several music Tracks. One Album depends
+on several Track services. 
+
+"Track" service: A piece of music.
+
+The scenario is implemented in the following bundles
+
+- org.apache.felix.dm.benchmark.scenario: defines the interfaces.
+- org.apache.felix.dm.benchmark.scenario.impl: defines the basic implementations for the services.
+
+The Scenario Controller (see
+org.apache.felix.dm.benchmark.scenario/org.apache.felix.dm.benchmark.scenario.impl) is in charge of
+starting/stopping many times some specific bundles (DM, Parallel DM).
+
+By default, when a tested bundle is started, it will create several Artists (see Artists.ARTISTS
+constant). each Artist depends on several Albums (see Artists.ALBUMS constant), and each Album
+depends on several music Tracks (see Artists.TRACKS constants).
+
+Test bundles (DM, parallel DM)
+==============================
+
+- org.apache.felix.dm.benchmark.dependencymanager: 
+It contains a simple activator, which creates the various services using dependency manager API.
+
+- org.apache.felix.dm.benchmark.dependencymanager.parallel: 
+same as above, but using parallel dependency manager where components dependency management and
+components activation processing is performed concurrently, using a fixed thread pool.
+
+The org.apache.felix.dm.benchmark.controller bundle, when started, first stops all tested bundles.
+Then for each one, it performs the following test (multiple times):
+
+- start the tested bundle
+- wait for all expected services to be registered (Artists/Albums/Tracks)
+- stop the tested bundle.
+- wait for all expected services to be unregistered
+
+All the elapsed time (nanoseconds) used to execute each iteration is then recorded in a list.
+When enough iterations are done, the list is sorted (that is : the first entry in the list
+corresponds to the fastest execution time, and the last entry corresponds to the slowest execution
+time). Then, we display some meaningful entries in the list (like the first entry, the entry in the
+middle of the list (average), and the last entry (slowest).
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/bnd.bnd b/dependencymanager/org.apache.felix.dependencymanager.benchmark/bnd.bnd
new file mode 100644
index 0000000..58f280a
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/bnd.bnd
@@ -0,0 +1,28 @@
+#
+# 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.
+#
+javac.source:          1.8
+javac.target:          1.8
+Bundle-Version: 1.0.0
+-buildpath:  \
+	org.apache.felix.dependencymanager;version=latest,\
+	osgi.core;version=4.2,\
+	osgi.cmpn;version=4.2
+
+-sub:  \
+	*.bnd
+Export-Package:  \
+	org.apache.felix.dm.benchmark.scenario.impl
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/controller.bnd b/dependencymanager/org.apache.felix.dependencymanager.benchmark/controller.bnd
new file mode 100644
index 0000000..d4fcced
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/controller.bnd
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+Private-Package:  \
+	org.apache.felix.dm.benchmark.controller.impl
+Bundle-Activator: org.apache.felix.dm.benchmark.controller.impl.Activator
+Export-Package:  \
+	org.apache.felix.dm.benchmark.controller
\ No newline at end of file
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/dependencymanager.bnd b/dependencymanager/org.apache.felix.dependencymanager.benchmark/dependencymanager.bnd
new file mode 100644
index 0000000..8e12db1
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/dependencymanager.bnd
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+Private-Package:  \
+	org.apache.felix.dm.benchmark.dependencymanager
+Bundle-Activator: org.apache.felix.dm.benchmark.dependencymanager.Activator
\ No newline at end of file
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/dependencymanager.parallel.bnd b/dependencymanager/org.apache.felix.dependencymanager.benchmark/dependencymanager.parallel.bnd
new file mode 100644
index 0000000..b6ce3b2
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/dependencymanager.parallel.bnd
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+Bundle-Activator: org.apache.felix.dm.benchmark.dependencymanager.ParallelActivator
+Private-Package:  \
+	org.apache.felix.dm.benchmark.dependencymanager
\ No newline at end of file
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/index.bndrun b/dependencymanager/org.apache.felix.dependencymanager.benchmark/index.bndrun
new file mode 100644
index 0000000..a05e08e
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/index.bndrun
@@ -0,0 +1,40 @@
+#
+# 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.
+#
+-runbundles:  \
+	org.apache.felix.dependencymanager;version=latest,\
+	org.apache.felix.dependencymanager.shell;version=latest,\
+	org.apache.felix.metatype;version=1.0.10,\
+	org.apache.felix.log;version=1.0.1,\
+	org.apache.felix.gogo.command;version=0.12.0,\
+	org.apache.felix.gogo.shell;version=0.10.0,\
+	org.apache.felix.gogo.runtime;version=0.10.0,\
+	org.apache.felix.configadmin;version=1.8.0,\
+	org.apache.felix.dependencymanager.benchmark.scenario,\
+	org.apache.felix.dependencymanager.benchmark.dependencymanager,\
+    org.apache.felix.dependencymanager.benchmark.dependencymanager.parallel,\
+    org.apache.felix.dependencymanager.benchmark.controller
+	
+-runfw: org.apache.felix.framework;version='[4.4.0,4.4.0]'
+
+-runproperties:  \
+	ds.loglevel=warn,\
+	org.osgi.framework.bootdelegation='sun.*,com.sun.*,org.netbeans.*',\
+	org.apache.felix.dependencymanager.filterindex=objectClass,id
+-runvm: -server -Xmx1024m -Xms1024m
+-runee: JavaSE-1.8
+javac.source:          1.8
+javac.target:          1.8
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/noindex.bndrun b/dependencymanager/org.apache.felix.dependencymanager.benchmark/noindex.bndrun
new file mode 100644
index 0000000..480a954
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/noindex.bndrun
@@ -0,0 +1,39 @@
+#
+# 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.
+#
+-runbundles:  \
+	org.apache.felix.dependencymanager;version=latest,\
+	org.apache.felix.dependencymanager.shell;version=latest,\
+	org.apache.felix.metatype;version=1.0.10,\
+	org.apache.felix.log;version=1.0.1,\
+	org.apache.felix.gogo.command;version=0.12.0,\
+	org.apache.felix.gogo.shell;version=0.10.0,\
+	org.apache.felix.gogo.runtime;version=0.10.0,\
+	org.apache.felix.configadmin;version=1.8.0,\
+	org.apache.felix.dependencymanager.benchmark.scenario,\
+	org.apache.felix.dependencymanager.benchmark.dependencymanager,\
+    org.apache.felix.dependencymanager.benchmark.dependencymanager.parallel,\
+    org.apache.felix.dependencymanager.benchmark.controller
+	
+-runfw: org.apache.felix.framework;version='[4.4.0,4.4.0]'
+
+-runproperties:  \
+	ds.loglevel=warn,\
+	org.osgi.framework.bootdelegation='sun.*,com.sun.*,org.netbeans.*'
+-runvm: -server -Xmx1024m -Xms1024m
+-runee: JavaSE-1.8
+javac.source:          1.8
+javac.target:          1.8
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/scenario.bnd b/dependencymanager/org.apache.felix.dependencymanager.benchmark/scenario.bnd
new file mode 100644
index 0000000..8ede3fc
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/scenario.bnd
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+Export-Package:  \
+	org.apache.felix.dm.benchmark.scenario.impl,\
+	org.apache.felix.dm.benchmark.scenario
\ No newline at end of file
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/.gitignore b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/.gitignore
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/ScenarioController.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/ScenarioController.java
new file mode 100644
index 0000000..bca5cf5
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/ScenarioController.java
@@ -0,0 +1,64 @@
+/*
+ * 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.felix.dm.benchmark.controller;
+
+import org.apache.felix.dm.benchmark.scenario.Album;
+import org.apache.felix.dm.benchmark.scenario.Artist;
+import org.apache.felix.dm.benchmark.scenario.Track;
+
+/**
+ * This service is injected in each scenario bundle. All scenario bundle components must depend on this 
+ * service, and must invoke the xxAdded() method once the component is fully initialized, and 
+ * the xxRemoved() method when the component is stopped.
+ * This benchmark expect scenario bundles to register some "Artists" components. Each "Artist" component is
+ * then expected to depend on many "Albums", and each "Album" then depends on many music "Tracks".
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface ScenarioController {
+    /**
+     * An Artist is added (service is started)
+     */
+    void artistAdded(Artist artist);
+
+    /**
+     * An Artist is removed (service is stopped)
+     */
+    void artistRemoved(Artist artist);
+
+    /**
+     * An Album is added (service is started)
+     */
+    void albumAdded(Album artist);
+ 
+    /**
+     * An Album is removed (service is stopped)
+     */
+    void albumRemoved(Album artist);
+ 
+    /**
+     * A Music Track is added (service is started)
+     */
+    void trackAdded(Track artist);
+  
+    /**
+     * A Music Track is removed (service is stopped)
+     */
+    void trackRemoved(Track artist);
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/impl/Activator.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/impl/Activator.java
new file mode 100644
index 0000000..d2e4f9a
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/impl/Activator.java
@@ -0,0 +1,36 @@
+/*
+ * 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.felix.dm.benchmark.controller.impl;
+
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+
+/**
+ * This activator triggers the scenario controller thread, which will do some microbenchmarks for a given
+ * set of scenario bundles. The controller thread is fired only once the framework is started.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Activator extends DependencyActivatorBase {
+    @Override
+    public void init(BundleContext context, DependencyManager m) throws Exception {
+        m.add(createComponent().setImplementation(ScenarioControllerImpl.class));
+    }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/impl/ScenarioControllerImpl.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/impl/ScenarioControllerImpl.java
new file mode 100644
index 0000000..a384e8a
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/impl/ScenarioControllerImpl.java
@@ -0,0 +1,299 @@
+/*
+ * 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.felix.dm.benchmark.controller.impl;
+
+import static java.lang.System.out;
+import static java.util.stream.Collectors.joining;
+import static java.util.stream.Collectors.toList;
+import static org.apache.felix.dm.benchmark.scenario.Artist.ALBUMS;
+import static org.apache.felix.dm.benchmark.scenario.Artist.ARTISTS;
+import static org.apache.felix.dm.benchmark.scenario.Artist.TRACKS;
+import static org.apache.felix.dm.benchmark.scenario.Helper.debug;
+
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.text.NumberFormat;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.Optional;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.stream.LongStream;
+import java.util.stream.Stream;
+
+import org.apache.felix.dm.benchmark.controller.ScenarioController;
+import org.apache.felix.dm.benchmark.scenario.Album;
+import org.apache.felix.dm.benchmark.scenario.Artist;
+import org.apache.felix.dm.benchmark.scenario.Helper;
+import org.apache.felix.dm.benchmark.scenario.Track;
+import org.apache.felix.dm.benchmark.scenario.Unchecked;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The controller which perform microbenchmarks on some scenario bundles.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ScenarioControllerImpl implements Runnable, ScenarioController {
+    /**
+     * List of bundles to be executed by the benchmark.
+     */
+    final List<String> TESTS = Arrays.asList(
+        "org.apache.felix.dependencymanager.benchmark.dependencymanager",
+        "org.apache.felix.dependencymanager.benchmark.dependencymanager.parallel"
+    );
+    
+    /**
+     * Our injected bundle context, used to lookup the bundles to benchmark.
+     */
+    private volatile BundleContext m_bctx;
+    
+    /**
+     * Latches used to detect when expected services are registered, or unregistered.
+     */
+    private volatile CountDownLatch m_startLatch, m_stopLatch;
+
+    /**
+     * When a components is called in its start or stop method, we'll perform some processing if the following
+     * attribute is true.
+     */
+    private volatile boolean m_doProcessingInStartStop;
+        
+    /**
+     * Our component is starting: we'll first stop all bundles participating in the benchmark, then we'll 
+     * fire a thread, and from that thread we'll iterate on all bundles in order to do a benchmark on each.
+     * (we'll call start/stop N times, and will display the elapsed times for each bundle).
+     */
+    void start() {
+        new Thread(this).start();
+    }
+    
+    void stop() {
+    }
+    
+    @Override
+    public void run() {
+        // wait a bit in order to let the gogo banner be displayed before we start the bench.
+        Unchecked.run(() -> Thread.sleep(500)); 
+        
+        out.println("Starting benchmarks (each tested bundle will add/remove " + (ARTISTS + (ARTISTS * (ALBUMS + (ALBUMS * TRACKS)))) 
+           + " components during bundle activation).");
+       
+        // Stop all tested bundles.
+        forEachScenarioBundle(TESTS, Unchecked.consumer(bundle -> {
+            debug(() -> "Stopping bundle " + bundle.getSymbolicName());
+            bundle.stop();
+        }));
+        
+        // Register our controller service
+        m_bctx.registerService(ScenarioController.class.getName(), this, null);
+        
+        // Start/stop several times the tested bundles. (no processing done in components start methods).
+        m_doProcessingInStartStop = false;
+        out.println("\n\t[Starting benchmarks with no processing done in components start methods]");
+        startStopScenarioBundles(TESTS, 50);
+       
+        // Start/stop several times the tested bundles (processing is done in components start methods).
+        m_doProcessingInStartStop = true;
+        out.println("\n\t[Starting benchmarks with processing done in components start methods]");
+        startStopScenarioBundles(TESTS, 5);
+    }
+
+    @Override
+    public void artistAdded(Artist artist) {
+        int size = artist.getAlbums().size();
+        if (size != Artist.ALBUMS) {
+            throw new IllegalStateException("Artist has not created expected number of albums:" + size);
+        }
+        artist.play();
+        componentAdded();
+        Helper.debug(() -> "Artist added : " + artist);
+    }
+    
+    @Override
+    public void artistRemoved(Artist artist) {
+        componentRemoved();
+        Helper.debug(() -> "Artist removed : " + artist);
+    }
+    
+    @Override
+    public void albumAdded(Album album) {
+        int size = album.getMusicTracks().size();
+        if (size != Artist.TRACKS) {
+            throw new IllegalStateException("Album does not contain expected number of music tracks:" + size);
+        }
+        componentAdded();
+        Helper.debug(() -> "Album added : " + album);
+    }
+    
+    @Override
+    public void albumRemoved(Album album) {
+        componentRemoved();
+        Helper.debug(() -> "Album removed : " + album);
+    }
+    
+    @Override
+    public void trackAdded(Track track) {
+        componentAdded();
+        Helper.debug(() -> "Track added : " + track);
+    }
+    
+    @Override
+    public void trackRemoved(Track track) {
+        componentRemoved();
+        Helper.debug(() -> "Track removed : " + track);
+    }
+            
+    // ------------------- Private methods -----------------------------------------------------
+        
+    private void startStopScenarioBundles(List<String> tests, int iterations) {
+        forEachScenarioBundle(tests, bundle -> {
+            out.print("\nBenchmarking bundle: " + bundle.getSymbolicName() + " ");            
+            List<Long> sortedResults = LongStream.range(0, iterations)
+                .peek(i -> out.print("."))
+                .map(n -> durationOf(() -> startAndStop(bundle)))
+                .sorted().boxed().collect(toList());
+            out.println();
+            displaySortedResults(sortedResults);
+            Unchecked.run(() -> Thread.sleep(500));
+        });        
+    }
+
+    /**
+     * Displays meaningful values in the sorted results (first=fastest, midle=average, last entry=slowest)
+     * @param sortedResults
+     */
+    private void displaySortedResults(List<Long> sortedResults) {
+        // We don't display an average of the duration times; Instead, we sort the results,
+        // and we display the significant results (the first entry is the fastest, the middle entry is the
+        // average, the last entry is the slowest ...)
+        out.printf("-> results in nanos: [%s]%n",  
+            Stream.of(0f, 24.99f, 49.99f, 74.99f, 99.99f)
+                .mapToInt(perc -> (int) (perc * sortedResults.size() / 100))
+                .mapToObj(sortedResults::get)
+                .map(this::formatNano)
+                .collect(joining(" | ")));
+    }
+    
+    /**
+     * Displays a nanosecond value using thousands separator. 
+     * Example: 1000000 -> 1,000,000
+     */
+    private String formatNano(Long nanoseconds) {
+		DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US);
+		DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
+		symbols.setGroupingSeparator(',');
+		return formatter.format(nanoseconds);
+    }
+
+    private void componentAdded() {
+        doProcessing();
+        m_startLatch.countDown();
+    }
+
+    private void componentRemoved() {
+        //doProcessing();
+        m_stopLatch.countDown();
+    }
+
+    private void doProcessing() {
+        if (m_doProcessingInStartStop) {
+            long duration = TimeUnit.MILLISECONDS.toNanos(ThreadLocalRandom.current().nextLong(5));
+            long t1 = System.nanoTime();
+            while (System.nanoTime() - t1 < duration)
+                ;
+        }
+    }
+    
+    /**
+     * Maps a function to all bundles participating in the benchmark.
+     */
+    private void forEachScenarioBundle(List<String> tests, Consumer<Bundle> consumer) {
+        tests.stream().forEach(test -> {
+            Optional<Bundle> bundle = Stream.of(m_bctx.getBundles()).filter(b -> b.getSymbolicName().equals(test)).findFirst();
+            bundle.ifPresent(b -> {
+                consumer.accept(b);
+            });
+        });   
+    }
+    
+   /**
+     * This function does this:
+     * 
+     * 1) start a bundle, and register the ScenarioController service (this will trigger all components activation)
+     * 2) wait for all expected components to be fully started
+     * 3) stop the bundle and wait for all expected components to be fully stopped
+     * 
+     * @param b the benchmarked scenario bundle
+     */
+    void startAndStop(Bundle b) {
+        try {
+            initLatches();
+
+            debug(() -> "starting bundle " + b.getSymbolicName());
+            b.start();
+                                    
+            if (! m_startLatch.await(60, TimeUnit.SECONDS)) {
+                out.println("Could not start components timely: current start latch=" + m_startLatch.getCount() + ", stop latch=" + m_stopLatch.getCount());
+                Unchecked.run(() -> Thread.sleep(Integer.MAX_VALUE));
+            }
+                        
+            debug(() -> "stopping bundle " + b.getSymbolicName());
+            b.stop();
+            
+            // Wait for all component deactivations
+            if (! m_stopLatch.await(60, TimeUnit.SECONDS)) {
+                out.println("Could not stop components timely: current start latch=" + m_startLatch.getCount() + ", stop latch=" + m_stopLatch.getCount());
+                Unchecked.run(() -> Thread.sleep(Integer.MAX_VALUE));
+            }            
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+    
+    /**
+     * Initialize the latches used to track when all scenario bundle components are started or stopped.
+     */
+    private void initLatches() {
+        m_startLatch = new CountDownLatch(ARTISTS
+            + (ARTISTS * (ALBUMS + (ALBUMS * TRACKS))));
+        
+        m_stopLatch = new CountDownLatch(ARTISTS
+            + (ARTISTS * (ALBUMS + (ALBUMS * TRACKS))));
+    }
+
+    /**
+     * Returns the time consumed by the given runnable, ²ch is executed by this method.
+     */
+    private long durationOf(Runnable scenario) {
+        long start = System.nanoTime();
+        long end = 0;
+        try {
+            scenario.run();
+            end = System.nanoTime();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+        return (end - start);
+    }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/packageinfo b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/packageinfo
new file mode 100644
index 0000000..a4f1546
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/controller/packageinfo
@@ -0,0 +1 @@
+version 1.0
\ No newline at end of file
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/dependencymanager/Activator.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/dependencymanager/Activator.java
new file mode 100644
index 0000000..740fcf2
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/dependencymanager/Activator.java
@@ -0,0 +1,39 @@
+/*
+ * 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.felix.dm.benchmark.dependencymanager;
+
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.benchmark.controller.ScenarioController;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Activator for a scenario based on Dependency Manager 4.0
+ * We'll create many Artists, each one is depending on many Albums, and each Album depends on many Tracks.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Activator extends DependencyActivatorBase {
+    @Override
+    public void init(BundleContext context, DependencyManager dm) throws Exception {  
+        dm.add(createComponent()
+            .setImplementation(Benchmark.class)
+            .add(createServiceDependency().setService(ScenarioController.class).setRequired(true)));
+    }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/dependencymanager/Benchmark.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/dependencymanager/Benchmark.java
new file mode 100644
index 0000000..10384fb
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/dependencymanager/Benchmark.java
@@ -0,0 +1,108 @@
+/*
+ * 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.felix.dm.benchmark.dependencymanager;
+
+import static org.apache.felix.dm.benchmark.scenario.Artist.ALBUMS;
+import static org.apache.felix.dm.benchmark.scenario.Artist.ARTISTS;
+import static org.apache.felix.dm.benchmark.scenario.Artist.TRACKS;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.benchmark.controller.ScenarioController;
+import org.apache.felix.dm.benchmark.scenario.Album;
+import org.apache.felix.dm.benchmark.scenario.Artist;
+import org.apache.felix.dm.benchmark.scenario.Helper;
+import org.apache.felix.dm.benchmark.scenario.Track;
+import org.apache.felix.dm.benchmark.scenario.impl.AlbumImpl;
+import org.apache.felix.dm.benchmark.scenario.impl.ArtistImpl;
+import org.apache.felix.dm.benchmark.scenario.impl.TrackImpl;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Benchmark {
+    volatile DependencyManager m_dm;
+    volatile ScenarioController m_controller;
+    final List<Component> m_components = new ArrayList<>();
+
+    /**
+     * Initialize our Artists, Albums/Tracks, possibly using a parallel dependency manager.
+     */
+    @SuppressWarnings("unused")
+    private void start() {
+        Helper.debug(() -> "Benchmark.start");
+        
+        IntStream.range(0, ARTISTS)
+            .mapToObj(i -> createArtists(m_dm)).peek(m_components::add)
+            .flatMap(artist -> createAlbums(m_dm, artist)).peek(m_components::add)
+            .flatMap(album -> createTracks(m_dm, album)).forEach(m_components::add);
+                            
+        m_components.stream().forEach(m_dm::add);
+    }
+    
+    @SuppressWarnings("unused")
+    private void stop() {
+        m_components.forEach(m_dm::remove);
+    }
+
+    private Component createArtists(DependencyManager dm) {
+        Component artist = dm.createComponent()
+            .setInterface(Artist.class.getName(), null)
+            .setImplementation(new ArtistImpl(m_controller));
+        return artist;
+    }
+    
+    private Stream<Component> createAlbums(DependencyManager dm, Component artist) {
+        return IntStream.range(0, ALBUMS).mapToObj(i -> {
+            long id = Helper.generateId();
+            String filter = "(id=" + id + ")";
+            artist.add(dm.createServiceDependency()
+                         .setService(Album.class, filter).setRequired(true).setCallbacks("addAlbum", null));            
+            
+            Hashtable<String, Object> props = new Hashtable<>();
+            props.put("id", String.valueOf(id));
+            Component c = dm.createComponent()
+                .setInterface(Album.class.getName(), props)
+                .setImplementation(new AlbumImpl(m_controller));
+            return c;
+        });
+    }
+        
+    private Stream<Component> createTracks(DependencyManager dm, Component album) {
+        return IntStream.range(0, TRACKS).mapToObj(i -> {
+            long id = Helper.generateId();
+            String f = "(id=" + String.valueOf(id) + ")";
+            album.add(dm.createServiceDependency()
+                        .setService(Track.class, f).setRequired(true).setCallbacks("addTrack", null));
+
+            Hashtable<String, Object> p = new Hashtable<>();
+            p.put("id", String.valueOf(id));
+            Component c = dm.createComponent()
+                .setInterface(Track.class.getName(), p)
+                .setImplementation(new TrackImpl(m_controller));
+            return c;
+        });
+    }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/dependencymanager/ParallelActivator.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/dependencymanager/ParallelActivator.java
new file mode 100644
index 0000000..cdcb6b3
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/dependencymanager/ParallelActivator.java
@@ -0,0 +1,44 @@
+/*
+ * 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.felix.dm.benchmark.dependencymanager;
+
+import java.util.concurrent.Executor;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.ComponentExecutorFactory;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.benchmark.scenario.Helper;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Parallel version of our default Activator.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ParallelActivator extends Activator {
+    public void init(BundleContext context, DependencyManager mgr) throws Exception {
+        context.registerService(ComponentExecutorFactory.class.getName(), new ComponentExecutorFactory() {
+            @Override
+            public Executor getExecutorFor(Component component) {
+                return Helper.getThreadPool(); // Return our thread pool shared for all components
+            }
+        }, null);
+        super.init(context, mgr);
+    }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Album.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Album.java
new file mode 100644
index 0000000..1d6ac0c
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Album.java
@@ -0,0 +1,38 @@
+/*
+ * 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.felix.dm.benchmark.scenario;
+
+import java.util.List;
+
+/**
+ * A single release of musics, comprising some music tracks.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface Album {
+    /**
+     * Returns the music tracks this Album is comprising.
+     */
+    List<Track> getMusicTracks();
+
+    /**
+     * Play all tracks from all albums.
+     */
+    void play();
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Artist.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Artist.java
new file mode 100644
index 0000000..eb78702
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Artist.java
@@ -0,0 +1,56 @@
+/*
+ * 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.felix.dm.benchmark.scenario;
+
+import java.util.List;
+
+/**
+ * An individual who creates musical Albums
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface Artist {
+    /**
+     * When a scenario bundles starts, it creates the following number of Artists (service)
+     * (you have to regenerate the SCR xml descriptor if you modify this, see README)
+     */
+    public final int ARTISTS = 30;
+    
+    /**
+     * Each Artist creates the following number of musical Albums.
+     * (you have to regenerate the SCR xml descriptor if you modify this, see README)
+     */
+    public final int ALBUMS = 5;
+    
+    /**
+     * Each Album contains the following number of musical Tracks.
+     * (you have to regenerate the SCR xml descriptor if you modify this, see README)
+     */
+    public final int TRACKS = 3;
+    
+    /**
+     * Returns the Albums that this Artist has created
+     */
+    List<Album> getAlbums();
+    
+    /**
+     * Play all tracks from all albums (this test method invocation time between services).
+     */
+    void play();
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Helper.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Helper.java
new file mode 100644
index 0000000..9ada693
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Helper.java
@@ -0,0 +1,69 @@
+/*
+ * 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.felix.dm.benchmark.scenario;
+
+import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Supplier;
+
+/**
+ * Helper class containing misc functions, and constants.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Helper {
+    /**
+     * Activate this flag for debugging.
+     */
+    private final static boolean DEBUG = false;
+
+    /** 
+     * Generator used to create unique identifiers.
+     */
+    private final static AtomicLong m_idGenerator = new AtomicLong();
+
+    /**
+     * Threadpool which can be optionally used by parallel scenarios.
+     */
+    private final static int CORES = Runtime.getRuntime().availableProcessors();
+    private final static ForkJoinPool TPOOL = new ForkJoinPool(CORES);
+    
+    /**
+     * Get the threadpool, possibly needed by some scenario supporting parallel mode
+     */
+    public static ForkJoinPool getThreadPool() {
+        return TPOOL;
+    }
+    
+    /**
+     * Display some debug messages.
+     */
+    public static void debug(Supplier<String> message) {
+        if (DEBUG) {
+            System.out.println(message.get());
+        }
+    }
+
+    /**
+     * Generates a unique id.
+     */
+    public static long generateId() {
+        return m_idGenerator.incrementAndGet();
+    }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Track.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Track.java
new file mode 100644
index 0000000..0e4d414
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Track.java
@@ -0,0 +1,31 @@
+/*
+ * 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.felix.dm.benchmark.scenario;
+
+/**
+ * A piece of music
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface Track {
+    /**
+     * Play this single piece of music.
+     */
+    void play();
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Unchecked.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Unchecked.java
new file mode 100644
index 0000000..c9849d9
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/Unchecked.java
@@ -0,0 +1,103 @@
+/*
+ * 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.felix.dm.benchmark.scenario;
+
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+/**
+ * Helper functions used to work around the java.util.function.* functions, which don't support 
+ * methods throwing a checked exception.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Unchecked {
+    /**
+     * Same functional interface as java.util.function.Consumer, except that the accept method may throw an exception.
+     */
+    @FunctionalInterface
+    public static interface CheckedConsumer<T> {
+        public void accept(T t) throws Exception;
+    }
+    
+    /**
+     * Same interface as Runnable, except that the run method may throw an exception.
+     */
+    @FunctionalInterface
+    public static interface CheckedRunnable {
+        public void run() throws Exception;
+    }
+    
+    /**
+     * Same interface as Function, except that the accept method may throw an exception.
+     */
+    @FunctionalInterface
+    public static interface CheckedFunction<T,U> {
+        public U apply(T t) throws Exception;
+    }
+    
+    /**
+     * Wraps a Consumer whose accept method may throw an exception behind a regular java.util.function.Consumer
+     */
+    public static <T> Consumer<T> consumer(CheckedConsumer<T> c) {
+        return (t) -> {
+            try {
+                c.accept(t);
+            }
+            catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            catch (Throwable err) {
+                throw err;
+            }
+        };
+    }
+    
+    /**
+     * Wraps a Consumer whose accept method may throw an exception behind a regular java.util.function.Consumer
+     */
+    public static <T,U> Function<T, U> func(CheckedFunction<T, U> f) {
+        return (t) -> {
+            try {
+                return f.apply(t);
+            }
+            catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            catch (Throwable err) {
+                throw err;
+            }
+        };
+    }
+
+    /**
+     * Runs a runnable which may throw an exception without having to catch it.
+     */
+    public static void run(CheckedRunnable r) {
+        try {
+            r.run();
+        }
+        catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        catch (Throwable err) {
+            throw err;
+        }
+    }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/AlbumImpl.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/AlbumImpl.java
new file mode 100644
index 0000000..1de8bb7
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/AlbumImpl.java
@@ -0,0 +1,64 @@
+/*
+ * 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.felix.dm.benchmark.scenario.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.dm.benchmark.controller.ScenarioController;
+import org.apache.felix.dm.benchmark.scenario.Album;
+import org.apache.felix.dm.benchmark.scenario.Track;
+
+/**
+ * An album comprising several music tracks.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class AlbumImpl implements Album {
+    final List<Track> m_musicTracks = new ArrayList<>();
+    final ScenarioController m_controller;
+    
+    public AlbumImpl(ScenarioController controller) {
+        m_controller = controller;
+    }
+    
+    void addTrack(Track dep) {
+        m_musicTracks.add(dep);
+    }
+        
+    void start() {
+        m_controller.albumAdded(this);
+    }
+    
+    void stop() {
+        m_controller.albumRemoved(this);
+    }
+
+    @Override
+    public List<Track> getMusicTracks() {
+        return m_musicTracks;
+    }
+
+    @Override
+    public void play() {
+        for (Track track : m_musicTracks) {
+            track.play();
+        }
+    }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/ArtistImpl.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/ArtistImpl.java
new file mode 100644
index 0000000..2bfbc28
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/ArtistImpl.java
@@ -0,0 +1,63 @@
+/*
+ * 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.felix.dm.benchmark.scenario.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.dm.benchmark.controller.ScenarioController;
+import org.apache.felix.dm.benchmark.scenario.Album;
+import org.apache.felix.dm.benchmark.scenario.Artist;
+
+/**
+ * One artist who depends on multiple Albums.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ArtistImpl implements Artist {
+    final List<Album> m_albums = new ArrayList<>();
+    final ScenarioController m_controller;
+    
+    public ArtistImpl(ScenarioController controller) {
+        m_controller = controller;
+    }
+    
+    void addAlbum(Album dep) {
+        m_albums.add(dep);
+    }
+
+    void start() {
+        m_controller.artistAdded(this);
+    }
+    
+    void stop() {
+        m_controller.artistRemoved(this);
+    }
+
+    @Override
+    public List<Album> getAlbums() {
+        return m_albums;
+    }
+    
+    public void play() {
+        for (Album album : m_albums) {
+            album.play();
+        }
+    }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/TrackImpl.java b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/TrackImpl.java
new file mode 100644
index 0000000..3115b3b
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/TrackImpl.java
@@ -0,0 +1,47 @@
+/*
+ * 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.felix.dm.benchmark.scenario.impl;
+
+import org.apache.felix.dm.benchmark.controller.ScenarioController;
+import org.apache.felix.dm.benchmark.scenario.Track;
+
+/**
+ * One single music.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class TrackImpl implements Track {
+    final ScenarioController m_controller;
+
+    public TrackImpl(ScenarioController controller) {
+        m_controller = controller;
+    }
+
+    void start() {
+        m_controller.trackAdded(this);
+    }
+    
+    void stop() {
+        m_controller.trackRemoved(this);
+    }
+
+    @Override
+    public void play() {
+    }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/packageinfo b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/packageinfo
new file mode 100644
index 0000000..a4f1546
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/impl/packageinfo
@@ -0,0 +1 @@
+version 1.0
\ No newline at end of file
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/packageinfo b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/packageinfo
new file mode 100644
index 0000000..a4f1546
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/src/org/apache/felix/dm/benchmark/scenario/packageinfo
@@ -0,0 +1 @@
+version 1.0
\ No newline at end of file
diff --git a/dependencymanager/org.apache.felix.dependencymanager.benchmark/test/.gitignore b/dependencymanager/org.apache.felix.dependencymanager.benchmark/test/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.benchmark/test/.gitignore