View Javadoc

1   package jgroup.test.performance;
2   
3   import java.io.InputStream;
4   import java.rmi.RemoteException;
5   
6   import jgroup.core.ConfigManager;
7   import jgroup.core.GroupManager;
8   import jgroup.core.MemberId;
9   import jgroup.core.MembershipListener;
10  import jgroup.core.MergingListener;
11  import jgroup.core.View;
12  import jgroup.core.multicast.MulticastListener;
13  import jgroup.relacs.gm.MembershipLayer;
14  import jgroup.relacs.gm.MergingLayer;
15  import jgroup.relacs.gm.MulticastLayer;
16  import jgroup.relacs.gm.NewDispatcherLayer;
17  import jgroup.relacs.gmi.JeriEGMILayer;
18  import jgroup.relacs.rmi.IntGroupHandler;
19  import jgroup.test.hello.Answer;
20  import jgroup.test.hello.Hello;
21  import jgroup.test.hello.InternalHello;
22  
23  /**
24   *  Simple class to test the performance of the dynamic
25   *  <code>GroupManager</code> composition framework.  To compare
26   *  with static composition.
27   *
28   *  @author Hein Meling <meling@acm.org>
29   */
30  public final class PerfGroupManager
31    implements Hello, InternalHello, MembershipListener, MulticastListener, MergingListener
32  {
33  
34    private static final int NUM_ROUNDS = 10;
35  
36    /**
37     * Constructor for PerfGroupManager.
38     */
39    public PerfGroupManager() { }
40  
41    public void staticComposition()
42      throws Exception
43    {
44      /* Min, max and average time; initialization */
45      long min = Long.MAX_VALUE, max = 0, emax = 0, eavg = 0, avg = 0, start = 0, time = 0;
46  
47      start = System.currentTimeMillis();
48      for (int i=0; i < NUM_ROUNDS; i++) {
49  
50        // Perform test and measure times
51        start = System.currentTimeMillis();
52  
53        NewDispatcherLayer disp = NewDispatcherLayer.getLayer();
54        MembershipLayer pgms = MembershipLayer.getLayer(disp);
55        MulticastLayer mcast = MulticastLayer.getLayer(disp, pgms);
56        //FIXME gm must be set
57        JeriEGMILayer egmi = JeriEGMILayer.getLayer(null, mcast, pgms);
58        IntGroupHandler igmi = IntGroupHandler.getLayer(mcast);
59        MergingLayer sms = MergingLayer.getLayer(pgms, mcast);
60        
61        disp.addListener(pgms);
62        pgms.addListener(this);
63        pgms.addListener(sms);
64        mcast.addListener(sms);
65        mcast.addListener(egmi);
66        mcast.addListener(igmi);
67        egmi.addListener(this);
68        igmi.addListener(this);
69        sms.addListener(this);
70  
71        // Compute statics
72        time = System.currentTimeMillis() - start;
73        if (time < min)
74          min = time;
75        if (time > max)
76          max = time;
77        avg += time;
78        if (time != max) {
79          eavg += time;
80          if (time > emax)
81            emax = time;
82        }
83      }
84      // Print statistics
85      System.out.println((avg/NUM_ROUNDS) + " ; " + (eavg/(NUM_ROUNDS-1)) + " ; " + emax + " ; " + max + " ; " + min);
86    }
87  
88    public void dynamicComposition(String[] serviceSet)
89      throws Exception
90    {
91      /* Min, max and average time; initialization */
92      long min = Long.MAX_VALUE, max = 0, emax = 0, eavg = 0, avg = 0, start = 0, time = 0;
93  
94      start = System.currentTimeMillis();
95      for (int i=0; i < NUM_ROUNDS; i++) {
96  
97        // Perform test and measure times
98        start = System.currentTimeMillis();
99  
100       GroupManager gm = GroupManager.getGroupManager(99, serviceSet, this);
101 
102       // Compute statics
103       time = System.currentTimeMillis() - start;
104       if (time < min)
105         min = time;
106       if (time > max)
107         max = time;
108       avg += time;
109       if (time != max) {
110         eavg += time;
111         if (time > emax)
112           emax = time;
113       }
114     }
115     // Print statistics
116     System.out.println((avg/NUM_ROUNDS) + " ; " + (eavg/(NUM_ROUNDS-1)) + " ; " + emax + " ; " + max + " ; " + min);
117   }
118 
119 
120   public static void main(String[] args)
121     throws Exception
122   {
123     ConfigManager.init();
124     PerfGroupManager perfObj = new PerfGroupManager();
125 
126     if (args[0].equals("--static")) {
127       perfObj.staticComposition();
128     } else if (args[0].equals("--dynamic")) {
129       String[] serviceSet = new String[] { "Dispatcher", "PGMS", "Mcast", "EGMI", "IGMI", "SMS" };
130       perfObj.dynamicComposition(serviceSet);
131     }
132 
133     System.exit(0);
134   }
135 
136   /**
137    *  The external interface.
138    */
139   public Answer sayHello()
140     throws RemoteException
141   {
142     return new Answer("Test");
143   }
144 
145 
146   /**
147    *  The internal interface.
148    */
149   public Object time()
150     throws RemoteException
151   {
152     return new Integer(2);
153   }
154 
155   /**
156    *  The <code>MembershipListener</code> interface.
157    */
158   public void viewChange(View v){}
159 
160   public void hasLeft(){}
161 
162   public void prepareChange(){}
163 
164   /**
165    *  The <code>MulticastListener</code> interface.
166    */
167   public String getProtocolName()
168   {
169     return "Test";
170   }
171 
172   public Object deliverStream(InputStream msg, MemberId sender, int seqNo)
173   {
174     throw new UnsupportedOperationException();
175   }
176 
177   public Object deliverObject(Object msg, MemberId sender, int seqNo)
178   {
179     throw new UnsupportedOperationException();
180   }
181   
182   /**
183    *  The <code>MergingListener</code> interface.
184    */
185   public Object getState(MemberId[] dests)
186   {
187     return this;
188   }
189 
190   public void putState(Object status, MemberId[] sources) {}
191 
192   public double doCompute() throws RemoteException
193   {
194     return 0;
195   }
196 }