| CODENOTIFIER | HelpYou are not signed inSign in |
Project: ProActive
Revision: 10086
Author: bsauvan
Date: 05 Sep 2008 03:35:13
Changes:Add monitor controller for components. See PROACTIVE-463
Files:| ... | ...@@ -0,0 +1,15 @@ | |
| 1 | package functionalTests.component.monitoring; | |
| 2 | ||
| 3 | public interface Runner { | |
| 4 | public void run(); | |
| 5 | ||
| 6 | public int getTotalNbMethodCalls(); | |
| 7 | ||
| 8 | public long getSleepTime(); | |
| 9 | ||
| 10 | public String[] getItfNamesForEachMethod(); | |
| 11 | ||
| 12 | public String[] getMethodNames(); | |
| 13 | ||
| 14 | public int[] getNbCallsPerMethod(); | |
| 15 | } |
| ... | ...@@ -0,0 +1,138 @@ | |
| 1 | package org.objectweb.proactive.core.component.controller; | |
| 2 | ||
| 3 | import java.util.List; | |
| 4 | ||
| 5 | ||
| 6 | public interface MethodStatistics { | |
| 7 | /** | |
| 8 | * Maximum number of requests saved. | |
| 9 | */ | |
| 10 | public static int maxNbRequests = 10000; | |
| 11 | ||
| 12 | /** | |
| 13 | * Get the current length of the requests incoming queue related to the monitored method. | |
| 14 | * | |
| 15 | * @return The current number of pending request in the queue. | |
| 16 | */ | |
| 17 | public int getCurrentLengthQueue(); | |
| 18 | ||
| 19 | /** | |
| 20 | * Get the average number of requests incoming queue per second related to the monitored | |
| 21 | * method since the monitoring has been started. | |
| 22 | * | |
| 23 | * @return The average number of requests per second. | |
| 24 | */ | |
| 25 | public double getAverageLengthQueue(); | |
| 26 | ||
| 27 | /** | |
| 28 | * Get the average number of requests incoming queue per second related to the monitored | |
| 29 | * method in the last past X milliseconds. | |
| 30 | * | |
| 31 | * @param pastXMilliseconds The last past X milliseconds. | |
| 32 | * @return The average number of requests per second. | |
| 33 | */ | |
| 34 | public double getAverageLengthQueue(long pastXMilliseconds); | |
| 35 | ||
| 36 | /** | |
| 37 | * Get the latest service time for the monitored method. | |
| 38 | * | |
| 39 | * @return The latest service time in milliseconds. | |
| 40 | */ | |
| 41 | public long getLatestServiceTime(); | |
| 42 | ||
| 43 | /** | |
| 44 | * Get the average service time for the monitored method since the monitoring has been started. | |
| 45 | * | |
| 46 | * @return The average service time in milliseconds. | |
| 47 | */ | |
| 48 | public double getAverageServiceTime(); | |
| 49 | ||
| 50 | /** | |
| 51 | * Get the average service time for the monitored method during the last N method calls. | |
| 52 | * | |
| 53 | * @param lastNRequest The last N method calls. | |
| 54 | * @return The average service time in milliseconds. | |
| 55 | */ | |
| 56 | public double getAverageServiceTime(int lastNRequest); | |
| 57 | ||
| 58 | /** | |
| 59 | * Get the average service time for the monitored method in the last past X milliseconds. | |
| 60 | * | |
| 61 | * @param pastXMilliseconds The last past X milliseconds. | |
| 62 | * @return The average service time in milliseconds. | |
| 63 | */ | |
| 64 | public double getAverageServiceTime(long pastXMilliseconds); | |
| 65 | ||
| 66 | /** | |
| 67 | * Get the latest inter-arrival time for the monitored method. | |
| 68 | * | |
| 69 | * @return The latest inter-arrival time in milliseconds. | |
| 70 | */ | |
| 71 | public long getLatestInterArrivalTime(); | |
| 72 | ||
| 73 | /** | |
| 74 | * Get the average inter-arrival time for the monitored method since the monitoring has | |
| 75 | * been started. | |
| 76 | * | |
| 77 | * @return The average inter-arrival time in milliseconds. | |
| 78 | */ | |
| 79 | public double getAverageInterArrivalTime(); | |
| 80 | ||
| 81 | /** | |
| 82 | * Get the average inter-arrival time for the monitored method during the last | |
| 83 | * N method calls. | |
| 84 | * | |
| 85 | * @param lastNRequest The last N method calls. | |
| 86 | * @return The average inter-arrival time in milliseconds. | |
| 87 | */ | |
| 88 | public double getAverageInterArrivalTime(int lastNRequest); | |
| 89 | ||
| 90 | /** | |
| 91 | * Get the average inter-arrival time for the monitored method in the last past X | |
| 92 | * milliseconds. | |
| 93 | * | |
| 94 | * @param pastXMilliseconds The last past X milliseconds. | |
| 95 | * @return The average inter-arrival time in milliseconds. | |
| 96 | */ | |
| 97 | public double getAverageInterArrivalTime(long pastXMilliseconds); | |
| 98 | ||
| 99 | /** | |
| 100 | * Get the average permanence time in the incoming queue for a request of the monitored method | |
| 101 | * since the monitoring has been started. | |
| 102 | * | |
| 103 | * @return The average permanence time in the incoming queue in milliseconds. | |
| 104 | */ | |
| 105 | public double getAveragePermanenceTimeInQueue(); | |
| 106 | ||
| 107 | /** | |
| 108 | * Get the average permanence time in the incoming queue for a request of the monitored method | |
| 109 | * during the last N method calls. | |
| 110 | * | |
| 111 | * @param lastNRequest The last N method calls. | |
| 112 | * @return The average permanence time in the incoming queue in milliseconds. | |
| 113 | */ | |
| 114 | public double getAveragePermanenceTimeInQueue(int lastNRequest); | |
| 115 | ||
| 116 | /** | |
| 117 | * Get the average permanence time in the incoming queue for a request of the monitored method | |
| 118 | * in the last past X milliseconds. | |
| 119 | * | |
| 120 | * @param pastXMilliseconds The last past X milliseconds. | |
| 121 | * @return The average permanence time in the incoming queue in milliseconds. | |
| 122 | */ | |
| 123 | public double getAveragePermanenceTimeInQueue(long pastXMilliseconds); | |
| 124 | ||
| 125 | /* | |
| 126 | * The fourth information "the list of all the method calls (server interfaces) invoked by a | |
| 127 | * given invocation" will be provided later with the DSO as described in Pisa. But, you can | |
| 128 | * already dependencies | |
| 129 | */ | |
| 130 | ||
| 131 | /** | |
| 132 | * Get the list of all the method calls (server interfaces) invoked by a given invocation. | |
| 133 | * | |
| 134 | * @return The list of the used interfaces. | |
| 135 | * TODO which kind of information do you need (Interface reference, name, ...?) | |
| 136 | */ | |
| 137 | public List<String> getInvokedMethodList(); | |
| 138 | } |
| ... | ...@@ -0,0 +1,81 @@ | |
| 1 | package org.objectweb.proactive.core.component.controller; | |
| 2 | ||
| 3 | import java.util.Map; | |
| 4 | ||
| 5 | import org.objectweb.proactive.annotation.PublicAPI; | |
| 6 | import org.objectweb.proactive.core.ProActiveRuntimeException; | |
| 7 | import org.objectweb.proactive.core.util.wrapper.BooleanWrapper; | |
| 8 | ||
| 9 | ||
| 10 | /** | |
| 11 | * The monitor controller interface. This controller manages the statistics for each methods exposed by the | |
| 12 | * component server interfaces. It's an optional controller. | |
| 13 | * <br> | |
| 14 | * The statistics of a given method are stored in a {@link org.objectweb.proactive.core.component.controller.MethodStatistics} | |
| 15 | * object. | |
| 16 | * <br> | |
| 17 | * The implementation class org.objectweb.proactive.core.component.controller.MonitorControllerImpl provides in | |
| 18 | * immediate services the following methods: getStatistics(String itfName, String methodName), | |
| 19 | * getStatistics(String itfName, String methodName, Class<?>[] parametersTypes), getAllStatistics(). | |
| 20 | * | |
| 21 | * @author The ProActive Team | |
| 22 | * @see org.objectweb.proactive.core.component.controller.MonitorControllerImpl | |
| 23 | * | |
| 24 | */ | |
| 25 | @PublicAPI | |
| 26 | public interface MonitorController { | |
| 27 | /** | |
| 28 | * Check if the monitoring of the component is started. | |
| 29 | * | |
| 30 | * @return True if the monitoring is started, false otherwise. | |
| 31 | */ | |
| 32 | public BooleanWrapper isMonitoringStarted(); | |
| 33 | ||
| 34 | /** | |
| 35 | * Start the monitoring of the component. | |
| 36 | */ | |
| 37 | public void startMonitoring(); | |
| 38 | ||
| 39 | /** | |
| 40 | * Stop the monitoring of the component. | |
| 41 | */ | |
| 42 | public void stopMonitoring(); | |
| 43 | ||
| 44 | /** | |
| 45 | * Reset the monitoring. All the previous data registered are erased. | |
| 46 | */ | |
| 47 | public void resetMonitoring(); | |
| 48 | ||
| 49 | /** | |
| 50 | * Get the statistics of a method exposed by a component server interface. | |
| 51 | * | |
| 52 | * @param itfName Name of the server interface where the method is exposed. | |
| 53 | * @param methodName Name of the method. | |
| 54 | * @return MethodStatistics instance containing all the statistics of the desired methods. | |
| 55 | * @throws Exception If the method cannot be identified or found. | |
| 56 | */ | |
| 57 | public MethodStatistics getStatistics(String itfName, String methodName) throws ProActiveRuntimeException; | |
| 58 | ||
| 59 | /** | |
| 60 | * Get the statistics of a method exposed by a component server interface. | |
| 61 | * | |
| 62 | * @param itfName Name of the server interface where the method is exposed. | |
| 63 | * @param methodName Name of the method. | |
| 64 | * @param parametersTypes Types of the parameters of the method. | |
| 65 | * @return MethodStatistics instance containing all the statistics of the desired methods. | |
| 66 | * @throws Exception If the method cannot be identified or found. | |
| 67 | */ | |
| 68 | public MethodStatistics getStatistics(String itfName, String methodName, Class<?>[] parametersTypes) | |
| 69 | throws ProActiveRuntimeException; | |
| 70 | ||
| 71 | /** | |
| 72 | * Get the statistics for each methods exposed by the component server interfaces. | |
| 73 | * Use the {@link org.objectweb.proactive.core.component.controller.MonitorControllerHelper.generateKey} | |
| 74 | * method to retrieve desired method statistics. | |
| 75 | * | |
| 76 | * @return All the statistics in a map structured like this | |
| 77 | * Map<itfName-MethodName-ClassNameParam1-ClassNameParam2-..., MethodStatistics>. | |
| 78 | * @see org.objectweb.proactive.core.component.controller.MonitorControllerHelper.generateKey | |
| 79 | */ | |
| 80 | public Map<String, MethodStatistics> getAllStatistics(); | |
| 81 | } |
| ... | ...@@ -0,0 +1,27 @@ | |
| 1 | package org.objectweb.proactive.core.component.controller; | |
| 2 | ||
| 3 | import org.objectweb.proactive.core.util.wrapper.StringWrapper; | |
| 4 | ||
| 5 | ||
| 6 | public class MonitorControllerHelper { | |
| 7 | private static final String KEY_INFO_SEPARATOR = "-"; | |
| 8 | ||
| 9 | /** | |
| 10 | * Generate an unique key according to the name of the server interface, the name of the method | |
| 11 | * and the class names of the parameters of the method. | |
| 12 | * | |
| 13 | * @param itfName Name of the server interface where the method is exposed. | |
| 14 | * @param methodName Name of the method. | |
| 15 | * @param parametersTypes Types of the parameters of the method. | |
| 16 | * @return Key built like this itfName-MethodName-ClassNameParam1-ClassNameParam2-... | |
| 17 | */ | |
| 18 | public static StringWrapper generateKey(String itfName, String methodName, Class<?>[] parametersTypes) { | |
| 19 | String key = itfName + KEY_INFO_SEPARATOR + methodName; | |
| 20 | ||
| 21 | for (int i = 0; i < parametersTypes.length; i++) { | |
| 22 | key += KEY_INFO_SEPARATOR + parametersTypes[i].getName(); | |
| 23 | } | |
| 24 | ||
| 25 | return new StringWrapper(key); | |
| 26 | } | |
| 27 | } |
| ... | ...@@ -229,6 +229,12 @@ | |
| 229 | 229 | return true; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | protected Group<ProActiveInterface> getDelegatee(String clientItfName) { | |
| 233 | ProxyForComponentInterfaceGroup clientSideProxy = (ProxyForComponentInterfaceGroup) clientSideProxies | |
| 234 | .get(clientItfName); | |
| 235 | return clientSideProxy.getDelegatee(); | |
| 236 | } | |
| 237 | ||
| 232 | 238 | /* |
| 233 | 239 | * @see org.objectweb.proactive.core.component.controller.MulticastController#bindFc(java.lang.String, |
| 234 | 240 | * org.objectweb.proactive.core.component.ProActiveInterface) |
| ... | ...@@ -32,6 +32,10 @@ | |
| 32 | 32 | <interface>org.objectweb.proactive.core.component.controller.MigrationController</interface> |
| 33 | 33 | <implementation>org.objectweb.proactive.core.component.controller.MigrationControllerImpl</implementation> |
| 34 | 34 | </controller> |
| 35 | <controller> | |
| 36 | <interface>org.objectweb.proactive.core.component.controller.MonitorController</interface> | |
| 37 | <implementation>org.objectweb.proactive.core.component.controller.MonitorControllerImpl</implementation> | |
| 38 | </controller> | |
| 35 | 39 | </controllers> |
| 36 | 40 | |
| 37 | 41 | </componentConfiguration> |
| ... | ...@@ -0,0 +1,56 @@ | |
| 1 | package org.objectweb.proactive.core.component.controller; | |
| 2 | ||
| 3 | import java.io.Serializable; | |
| 4 | import java.util.ArrayList; | |
| 5 | import java.util.Collections; | |
| 6 | import java.util.List; | |
| 7 | ||
| 8 | ||
| 9 | public class MethodStatisticsCompositeImpl extends MethodStatisticsAbstract implements Serializable { | |
| 10 | private List<MonitorController> subcomponentMonitors; | |
| 11 | ||
| 12 | public MethodStatisticsCompositeImpl(String itfName, String methodName, Class<?>[] parametersTypes, | |
| 13 | List<MonitorController> subcomponentMonitors) { | |
| 14 | this.itfName = itfName; | |
| 15 | this.methodName = methodName; | |
| 16 | this.parametersTypes = parametersTypes; | |
| 17 | this.subcomponentMonitors = subcomponentMonitors; | |
| 18 | this.requestsStats = Collections.synchronizedList(new ArrayList<RequestStatistics>()); | |
| 19 | reset(); | |
| 20 | } | |
| 21 | ||
| 22 | public long getLatestServiceTime() { | |
| 23 | long latestServiceTime = 0; | |
| 24 | for (int i = 0; i < subcomponentMonitors.size(); i++) | |
| 25 | latestServiceTime = Math.max(latestServiceTime, subcomponentMonitors.get(i).getStatistics( | |
| 26 | itfName, methodName, parametersTypes).getLatestServiceTime()); | |
| 27 | return latestServiceTime; | |
| 28 | } | |
| 29 | ||
| 30 | public double getAverageServiceTime() { | |
| 31 | double averageServiceTime = 0; | |
| 32 | for (int i = 0; i < subcomponentMonitors.size(); i++) | |
| 33 | averageServiceTime = Math.max(averageServiceTime, subcomponentMonitors.get(i).getStatistics( | |
| 34 | itfName, methodName, parametersTypes).getAverageServiceTime()); | |
| 35 | return averageServiceTime; | |
| 36 | } | |
| 37 | ||
| 38 | public double getAverageServiceTime(int lastNRequest) { | |
| 39 | if (lastNRequest != 0) { | |
| 40 | double averageServiceTime = 0; | |
| 41 | for (int i = 0; i < subcomponentMonitors.size(); i++) | |
| 42 | averageServiceTime = Math.max(averageServiceTime, subcomponentMonitors.get(i).getStatistics( | |
| 43 | itfName, methodName, parametersTypes).getAverageServiceTime(lastNRequest)); | |
| 44 | return averageServiceTime; | |
| 45 | } else | |
| 46 | return 0; | |
| 47 | } | |
| 48 | ||
| 49 | public double getAverageServiceTime(long pastXMilliseconds) { | |
| 50 | double averageServiceTime = 0; | |
| 51 | for (int i = 0; i < subcomponentMonitors.size(); i++) | |
| 52 | averageServiceTime = Math.max(averageServiceTime, subcomponentMonitors.get(i).getStatistics( | |
| 53 | itfName, methodName, parametersTypes).getAverageServiceTime(pastXMilliseconds)); | |
| 54 | return averageServiceTime; | |
| 55 | } | |
| 56 | } | |
| 0 | 57 | \ No newline at end of file |
| ... | ...@@ -0,0 +1,13 @@ | |
| 1 | package functionalTests.component.monitoring; | |
| 2 | ||
| 3 | import org.objectweb.proactive.core.util.wrapper.IntWrapper; | |
| 4 | import org.objectweb.proactive.core.util.wrapper.StringWrapper; | |
| 5 | ||
| 6 | ||
| 7 | public interface Service1 { | |
| 8 | public IntWrapper getInt(); | |
| 9 | ||
| 10 | public void doSomething(); | |
| 11 | ||
| 12 | public StringWrapper hello(); | |
| 13 | } |
| ... | ...@@ -0,0 +1,107 @@ | |
| 1 | package functionalTests.component.monitoring; | |
| 2 | ||
| 3 | import org.objectweb.fractal.api.NoSuchInterfaceException; | |
| 4 | import org.objectweb.fractal.api.control.BindingController; | |
| 5 | import org.objectweb.fractal.api.control.IllegalBindingException; | |
| 6 | import org.objectweb.fractal.api.control.IllegalLifeCycleException; | |
| 7 | import org.objectweb.proactive.core.ProActiveRuntimeException; | |
| 8 | import org.objectweb.proactive.core.util.wrapper.IntMutableWrapper; | |
| 9 | ||
| 10 | ||
| 11 | public class Client1Impl implements Runner, BindingController { | |
| 12 | private static final long SLEEP_TIME = 20; | |
| 13 | private static final String[] ITF_NAMES_FOR_EACH_METHOD = { "service1", "service1", "service1" }; //, "service3", "service3" }; | |
| 14 | private static final String[] METHOD_NAMES = { "getInt", "doSomething", "hello" }; //, "foo", "executeAlone" }; | |
| 15 | private static final int NB_ITERATIONS = 100; | |
| 16 | private Service1 service1; | |
| 17 | private Service3 service3; | |
| 18 | private int[] nbCallsPerMethod = new int[METHOD_NAMES.length]; | |
| 19 | ||
| 20 | private void sleep() { | |
| 21 | try { | |
| 22 | Thread.sleep(SLEEP_TIME); | |
| 23 | } catch (InterruptedException e) { | |
| 24 | e.printStackTrace(); | |
| 25 | } | |
| 26 | } | |
| 27 | ||
| 28 | public void run() { | |
| 29 | for (int i = 0; i < METHOD_NAMES.length; i++) { | |
| 30 | nbCallsPerMethod[i] = 0; | |
| 31 | } | |
| 32 | for (int i = 0; i < NB_ITERATIONS; i++) { | |
| 33 | sleep(); | |
| 34 | int indexMethod = i % METHOD_NAMES.length; | |
| 35 | nbCallsPerMethod[indexMethod]++; | |
| 36 | switch (indexMethod) { | |
| 37 | case 0: | |
| 38 | service1.getInt(); | |
| 39 | break; | |
| 40 | case 1: | |
| 41 | service1.doSomething(); | |
| 42 | break; | |
| 43 | case 2: | |
| 44 | service1.hello(); | |
| 45 | break; | |
| 46 | case 3: | |
| 47 | service3.foo(new IntMutableWrapper(1)); | |
| 48 | break; | |
| 49 | case 4: | |
| 50 | service3.executeAlone(); | |
| 51 | break; | |
| 52 | default: | |
| 53 | break; | |
| 54 | } | |
| 55 | } | |
| 56 | } | |
| 57 | ||
| 58 | public int getTotalNbMethodCalls() { | |
| 59 | return NB_ITERATIONS; | |
| 60 | } | |
| 61 | ||
| 62 | public long getSleepTime() { | |
| 63 | return SLEEP_TIME; | |
| 64 | } | |
| 65 | ||
| 66 | public String[] getItfNamesForEachMethod() { | |
| 67 | return ITF_NAMES_FOR_EACH_METHOD; | |
| 68 | } | |
| 69 | ||
| 70 | public String[] getMethodNames() { | |
| 71 | return METHOD_NAMES; | |
| 72 | } | |
| 73 | ||
| 74 | public int[] getNbCallsPerMethod() { | |
| 75 | return nbCallsPerMethod; | |
| 76 | } | |
| 77 | ||
| 78 | public void bindFc(String clientItfName, Object serverItf) throws NoSuchInterfaceException, | |
| 79 | IllegalBindingException, IllegalLifeCycleException { | |
| 80 | if ("service1".equals(clientItfName)) { | |
| 81 | service1 = (Service1) serverItf; | |
| 82 | } else if ("service3".equals(clientItfName)) { | |
| 83 | service3 = (Service3) serverItf; | |
| 84 | } else { | |
| 85 | throw new NoSuchInterfaceException(clientItfName); | |
| 86 | } | |
| 87 | } | |
| 88 | ||
| 89 | public String[] listFc() { | |
| 90 | return new String[] { "service1", "service3" }; | |
| 91 | } | |
| 92 | ||
| 93 | public Object lookupFc(String clientItfName) throws NoSuchInterfaceException { | |
| 94 | if ("service1".equals(clientItfName)) { | |
| 95 | return service1; | |
| 96 | } else if ("service3".equals(clientItfName)) { | |
| 97 | return service3; | |
| 98 | } else { | |
| 99 | throw new NoSuchInterfaceException(clientItfName); | |
| 100 | } | |
| 101 | } | |
| 102 | ||
| 103 | public void unbindFc(String arg0) throws NoSuchInterfaceException, IllegalBindingException, | |
| 104 | IllegalLifeCycleException { | |
| 105 | throw new ProActiveRuntimeException("not implemented!"); | |
| 106 | } | |
| 107 | } |
| ... | ...@@ -0,0 +1,13 @@ | |
| 1 | package functionalTests.component.monitoring; | |
| 2 | ||
| 3 | import org.objectweb.proactive.core.util.wrapper.BooleanWrapper; | |
| 4 | import org.objectweb.proactive.core.util.wrapper.DoubleWrapper; | |
| 5 | ||
| 6 | ||
| 7 | public interface Service2 { | |
| 8 | public void doAnotherThing(); | |
| 9 | ||
| 10 | public DoubleWrapper getDouble(); | |
| 11 | ||
| 12 | public BooleanWrapper getBoolean(); | |
| 13 | } |
| ... | ...@@ -0,0 +1,107 @@ | |
| 1 | package functionalTests.component.monitoring; | |
| 2 | ||
| 3 | import org.objectweb.fractal.api.NoSuchInterfaceException; | |
| 4 | import org.objectweb.fractal.api.control.BindingController; | |
| 5 | import org.objectweb.fractal.api.control.IllegalBindingException; | |
| 6 | import org.objectweb.fractal.api.control.IllegalLifeCycleException; | |
| 7 | import org.objectweb.proactive.core.ProActiveRuntimeException; | |
| 8 | import org.objectweb.proactive.core.util.wrapper.IntMutableWrapper; | |
| 9 | ||
| 10 | ||
| 11 | public class Client2Impl implements Runner, BindingController { | |
| 12 | private static final long SLEEP_TIME = 20; | |
| 13 | private static final String[] ITF_NAMES_FOR_EACH_METHOD = { "service2", "service2", "service2" }; // , "service3", "service3" }; | |
| 14 | private static final String[] METHOD_NAMES = { "doAnotherThing", "getDouble", "getBoolean" }; //, "foo", "executeAlone" }; | |
| 15 | private static final int NB_ITERATIONS = 100; | |
| 16 | private Service2 service2; | |
| 17 | private Service3 service3; | |
| 18 | private int[] nbCallsPerMethod = new int[METHOD_NAMES.length]; | |
| 19 | ||
| 20 | private void sleep() { | |
| 21 | try { | |
| 22 | Thread.sleep(SLEEP_TIME); | |
| 23 | } catch (InterruptedException e) { | |
| 24 | e.printStackTrace(); | |
| 25 | } | |
| 26 | } | |
| 27 | ||
| 28 | public void run() { | |
| 29 | for (int i = 0; i < METHOD_NAMES.length; i++) { | |
| 30 | nbCallsPerMethod[i] = 0; | |
| 31 | } | |
| 32 | for (int i = 0; i < NB_ITERATIONS; i++) { | |
| 33 | sleep(); | |
| 34 | int indexMethod = i % METHOD_NAMES.length; | |
| 35 | nbCallsPerMethod[indexMethod]++; | |
| 36 | switch (indexMethod) { | |
| 37 | case 0: | |
| 38 | service2.doAnotherThing(); | |
| 39 | break; | |
| 40 | case 1: | |
| 41 | service2.getDouble(); | |
| 42 | break; | |
| 43 | case 2: | |
| 44 | service2.getBoolean(); | |
| 45 | break; | |
| 46 | case 3: | |
| 47 | service3.foo(new IntMutableWrapper(2)); | |
| 48 | break; | |
| 49 | case 4: | |
| 50 | service3.executeAlone(); | |
| 51 | break; | |
| 52 | default: | |
| 53 | break; | |
| 54 | } | |
| 55 | } | |
| 56 | } | |
| 57 | ||
| 58 | public int getTotalNbMethodCalls() { | |
| 59 | return NB_ITERATIONS; | |
| 60 | } | |
| 61 | ||
| 62 | public long getSleepTime() { | |
| 63 | return SLEEP_TIME; | |
| 64 | } | |
| 65 | ||
| 66 | public String[] getItfNamesForEachMethod() { | |
| 67 | return ITF_NAMES_FOR_EACH_METHOD; | |
| 68 | } | |
| 69 | ||
| 70 | public String[] getMethodNames() { | |
| 71 | return METHOD_NAMES; | |
| 72 | } | |
| 73 | ||
| 74 | public int[] getNbCallsPerMethod() { | |
| 75 | return nbCallsPerMethod; | |
| 76 | } | |
| 77 | ||
| 78 | public void bindFc(String clientItfName, Object serverItf) throws NoSuchInterfaceException, | |
| 79 | IllegalBindingException, IllegalLifeCycleException { | |
| 80 | if ("service2".equals(clientItfName)) { | |
| 81 | service2 = (Service2) serverItf; | |
| 82 | } else if ("service3".equals(clientItfName)) { | |
| 83 | service3 = (Service3) serverItf; | |
| 84 | } else { | |
| 85 | throw new NoSuchInterfaceException(clientItfName); | |
| 86 | } | |
| 87 | } | |
| 88 | ||
| 89 | public String[] listFc() { | |
| 90 | return new String[] { "service2", "service3" }; | |
| 91 | } | |
| 92 | ||
| 93 | public Object lookupFc(String clientItfName) throws NoSuchInterfaceException { | |
| 94 | if ("service2".equals(clientItfName)) { | |
| 95 | return service2; | |
| 96 | } else if ("service3".equals(clientItfName)) { | |
| 97 | return service3; | |
| 98 | } else { | |
| 99 | throw new NoSuchInterfaceException(clientItfName); | |
| 100 | } | |
| 101 | } | |
| 102 | ||
| 103 | public void unbindFc(String arg0) throws NoSuchInterfaceException, IllegalBindingException, | |
| 104 | IllegalLifeCycleException { | |
| 105 | throw new ProActiveRuntimeException("not implemented!"); | |
| 106 | } | |
| 107 | } |
| ... | ...@@ -0,0 +1,11 @@ | |
| 1 | package functionalTests.component.monitoring; | |
| 2 | ||
| 3 | import org.objectweb.proactive.core.util.wrapper.IntMutableWrapper; | |
| 4 | import org.objectweb.proactive.core.util.wrapper.StringWrapper; | |
| 5 | ||
| 6 | ||
| 7 | public interface Service3 { | |
| 8 | public void foo(IntMutableWrapper i); | |
| 9 | ||
| 10 | public StringWrapper executeAlone(); | |
| 11 | } |
| ... | ...@@ -0,0 +1,42 @@ | |
| 1 | package org.objectweb.proactive.core.component.controller; | |
| 2 | ||
| 3 | import java.io.Serializable; | |
| 4 | import java.util.ArrayList; | |
| 5 | import java.util.Collections; | |
| 6 | ||
| 7 | ||
| 8 | public class MethodStatisticsPrimitiveImpl extends MethodStatisticsAbstract implements Serializable { | |
| 9 | ||
| 10 | public MethodStatisticsPrimitiveImpl(String itfName, String methodName, Class<?>[] parametersTypes) { | |
| 11 | this.itfName = itfName; | |
| 12 | this.methodName = methodName; | |
| 13 | this.parametersTypes = parametersTypes; | |
| 14 | this.requestsStats = Collections.synchronizedList(new ArrayList<RequestStatistics>()); | |
| 15 | reset(); | |
| 16 | } | |
| 17 | ||
| 18 | public long getLatestServiceTime() { | |
| 19 | return requestsStats.get(indexNextReply - 1).getServiceTime() / 1000; | |
| 20 | } | |
| 21 | ||
| 22 | public double getAverageServiceTime() { | |
| 23 | return getAverageServiceTime(indexNextReply); | |
| 24 | } | |
| 25 | ||
| 26 | public double getAverageServiceTime(int lastNRequest) { | |
| 27 | if (lastNRequest != 0) { | |
| 28 | double res = 0; | |
| 29 | int indexToReach = Math.max(indexNextReply - 1 - lastNRequest, 0); // To avoid to have negative index | |
| 30 | for (int i = indexNextReply - 1; i >= indexToReach; i--) { | |
| 31 | res += requestsStats.get(i).getServiceTime(); | |
| 32 | } | |
| 33 | ||
| 34 | return res / lastNRequest / 1000; | |
| 35 | } else | |
| 36 | return 0; | |
| 37 | } | |
| 38 | ||
| 39 | public double getAverageServiceTime(long pastXMilliseconds) { | |
| 40 | return getAverageServiceTime(findNumberOfRequests(pastXMilliseconds, indexNextReply)); | |
| 41 | } | |
| 42 | } |
| ... | ...@@ -0,0 +1,130 @@ | |
| 1 | package functionalTests.component.monitoring; | |
| 2 | ||
| 3 | import static org.junit.Assert.assertTrue; | |
| 4 | ||
| 5 | import java.util.HashMap; | |
| 6 | import java.util.Iterator; | |
| 7 | import java.util.Map; | |
| 8 | ||
| 9 | import org.objectweb.fractal.adl.Factory; | |
| 10 | import org.objectweb.fractal.api.Component; | |
| 11 | import org.objectweb.fractal.api.control.NameController; | |
| 12 | import org.objectweb.fractal.util.Fractal; | |
| 13 | import org.objectweb.proactive.core.component.Constants; | |
| 14 | import org.objectweb.proactive.core.component.controller.MethodStatistics; | |
| 15 | import org.objectweb.proactive.core.component.controller.MonitorController; | |
| 16 | ||
| 17 | import functionalTests.ComponentTest; | |
| 18 | ||
| 19 | ||
| 20 | /** | |
| 21 | * Test the monitor controller. | |
| 22 | * | |
| 23 | * @author The ProActive Team | |
| 24 | */ | |
| 25 | public class TestMonitoring extends ComponentTest { | |
| 26 | private Factory factory; | |
| 27 | private Component root; | |
| 28 | private MonitorController monitor; | |
| 29 | ||
| 30 | @org.junit.Test | |
| 31 | public void testMonitoringPrimitiveComponent() throws Exception { | |
| 32 | factory = org.objectweb.proactive.core.component.adl.FactoryFactory.getFactory(); | |
| 33 | Map<Object, Object> context = new HashMap<Object, Object>(); | |
| 34 | root = (Component) factory.newComponent("functionalTests.component.monitoring.adl.TestPrimitive", | |
| 35 | context); | |
| 36 | ||
| 37 | Component[] subComponents = Fractal.getContentController(root).getFcSubComponents(); | |
| 38 | for (int i = 0; i < subComponents.length; i++) { | |
| 39 | if (((NameController) subComponents[i].getFcInterface(Constants.NAME_CONTROLLER)).getFcName() | |
| 40 | .equals("server")) | |
| 41 | monitor = (MonitorController) subComponents[i].getFcInterface(Constants.MONITOR_CONTROLLER); | |
| 42 | } | |
| 43 | ||
| 44 | Fractal.getLifeCycleController(root).startFc(); | |
| 45 | start(); | |
| 46 | } | |
| 47 | ||
| 48 | @org.junit.Test | |
| 49 | public void testMonitoringCompositeComponent() throws Exception { | |
| 50 | factory = org.objectweb.proactive.core.component.adl.FactoryFactory.getFactory(); | |
| 51 | Map<Object, Object> context = new HashMap<Object, Object>(); | |
| 52 | root = (Component) factory.newComponent("functionalTests.component.monitoring.adl.TestComposite", | |
| 53 | context); | |
| 54 | ||
| 55 | Component[] subComponents = Fractal.getContentController(root).getFcSubComponents(); | |
| 56 | for (int i = 0; i < subComponents.length; i++) { | |
| 57 | if (((NameController) subComponents[i].getFcInterface(Constants.NAME_CONTROLLER)).getFcName() | |
| 58 | .equals("servercomposite")) | |
| 59 | monitor = (MonitorController) subComponents[i].getFcInterface(Constants.MONITOR_CONTROLLER); | |
| 60 | } | |
| 61 | ||
| 62 | Fractal.getLifeCycleController(root).startFc(); | |
| 63 | start(); | |
| 64 | } | |
| 65 | ||
| 66 | private void printStats() { | |
| 67 | Iterator<MethodStatistics> stats = monitor.getAllStatistics().values().iterator(); | |
| 68 | while (stats.hasNext()) | |
| 69 | System.out.println(stats.next().toString()); | |
| 70 | } | |
| 71 | ||
| 72 | private boolean checkTime(double supposedTime, double realTime) { | |
| 73 | return ((supposedTime * 0.70) <= realTime); | |
| 74 | } | |
| 75 | ||
| 76 | private void checkMethodStatistics(String itfName, String methodName, int nbCalls, int nbMethods, | |
| 77 | long sleepTimeCallMethod) throws Exception { | |
| 78 | MethodStatistics methodStats = monitor.getStatistics(itfName, methodName); | |
| 79 | assertTrue(checkTime(ServerImpl.EXECUTION_TIME, methodStats.getAverageServiceTime())); | |
| 80 | assertTrue(checkTime(nbMethods * sleepTimeCallMethod, methodStats.getAverageInterArrivalTime())); | |
| 81 | } | |
| 82 | ||
| 83 | public void start() throws Exception { | |
| 84 | Runner runner1 = ((Runner) root.getFcInterface("runner1")); | |
| 85 | Runner runner2 = ((Runner) root.getFcInterface("runner2")); | |
| 86 | monitor.startMonitoring(); | |
| 87 | ||
| 88 | System.out.println(); | |
| 89 | System.out.println("-----------------------------------------------------------"); | |
| 90 | System.out.println("Before execution:"); | |
| 91 | System.out.println(); | |
| 92 | printStats(); | |
| 93 | ||
| 94 | runner1.run(); | |
| 95 | runner2.run(); | |
| 96 | ||
| 97 | int totalNbMethodCalls = runner1.getTotalNbMethodCalls() + runner2.getTotalNbMethodCalls(); | |
| 98 | ||
| 99 | Thread.sleep(ServerImpl.EXECUTION_TIME * totalNbMethodCalls / 2); | |
| 100 | ||
| 101 | System.out.println(); | |
| 102 | System.out.println("-----------------------------------------------------------"); | |
| 103 | System.out.println("During execution:"); | |
| 104 | System.out.println(); | |
| 105 | printStats(); | |
| 106 | ||
| 107 | Thread.sleep(ServerImpl.EXECUTION_TIME * totalNbMethodCalls / 2); | |
| 108 | ||
| 109 | System.out.println(); | |
| 110 | System.out.println("-----------------------------------------------------------"); | |
| 111 | System.out.println("After execution:"); | |
| 112 | System.out.println(); | |
| 113 | printStats(); | |
| 114 | ||
| 115 | String[] itfNamesForEachMethod = runner1.getItfNamesForEachMethod(); | |
| 116 | String[] methodNames = runner1.getMethodNames(); | |
| 117 | int[] nbCallsPerMethod = runner1.getNbCallsPerMethod(); | |
| 118 | for (int i = 0; i < methodNames.length; i++) { | |
| 119 | checkMethodStatistics(itfNamesForEachMethod[i], methodNames[i], nbCallsPerMethod[i], | |
| 120 | methodNames.length, runner1.getSleepTime()); | |
| 121 | } | |
| 122 | itfNamesForEachMethod = runner2.getItfNamesForEachMethod(); | |
| 123 | methodNames = runner2.getMethodNames(); | |
| 124 | nbCallsPerMethod = runner2.getNbCallsPerMethod(); | |
| 125 | for (int i = 0; i < methodNames.length; i++) { | |
| 126 | checkMethodStatistics(itfNamesForEachMethod[i], methodNames[i], nbCallsPerMethod[i], | |
| 127 | methodNames.length, runner2.getSleepTime()); | |
| 128 | } | |
| 129 | } | |
| 130 | } |
| ... | ...@@ -0,0 +1,60 @@ | |
| 1 | package functionalTests.component.monitoring; | |
| 2 | ||
| 3 | import java.util.List; | |
| 4 | ||
| 5 | import org.objectweb.proactive.core.util.wrapper.BooleanWrapper; | |
| 6 | import org.objectweb.proactive.core.util.wrapper.DoubleWrapper; | |
| 7 | import org.objectweb.proactive.core.util.wrapper.IntMutableWrapper; | |
| 8 | import org.objectweb.proactive.core.util.wrapper.IntWrapper; | |
| 9 | import org.objectweb.proactive.core.util.wrapper.StringWrapper; | |
| 10 | ||
| 11 | ||
| 12 | public class ServerImpl implements Service1, Service2, Service3Gathercast { | |
| 13 | public static final long EXECUTION_TIME = 50; | |
| 14 | ||
| 15 | private void sleep() { | |
| 16 | try { | |
| 17 | Thread.sleep(EXECUTION_TIME); | |
| 18 | } catch (InterruptedException e) { | |
| 19 | e.printStackTrace(); | |
| 20 | } | |
| 21 | } | |
| 22 | ||
| 23 | public void doSomething() { | |
| 24 | sleep(); | |
| 25 | } | |
| 26 | ||
| 27 | public IntWrapper getInt() { | |
| 28 | sleep(); | |
| 29 | return null; | |
| 30 | } | |
| 31 | ||
| 32 | public StringWrapper hello() { | |
| 33 | sleep(); | |
| 34 | return null; | |
| 35 | } | |
| 36 | ||
| 37 | public void doAnotherThing() { | |