View Javadoc

1   /*
2    * Copyright (c) 1998-2002 The Jgroup Team.
3    *
4    * This program is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU Lesser General Public License version 2 as
6    * published by the Free Software Foundation.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Lesser General Public License for more details.
12   *
13   * You should have received a copy of the GNU Lesser General Public License
14   * along with this program; if not, write to the Free Software
15   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16   *
17   */
18  
19  package jgroup.test.performance.upgrade;
20  
21  import java.util.Date;
22  
23  import jgroup.core.ConfigManager;
24  import jgroup.core.registry.DependableRegistry;
25  import jgroup.core.registry.RegistryFactory;
26  import jgroup.test.performance.SpeedTest;
27  import jgroup.upgrade.UpgradeManagementClient;
28  
29  import org.apache.log4j.Logger;
30  
31  
32  
33  /**
34   *  Test suite for measuring the performance of a server during the upgrade process.
35   *  The class parses the experiment parameter from command line. The following
36   *  parameters are interpreted:
37   *
38   *  <p>
39   *  @param -method type of test calls sent to the server
40   *  @param -calibrate number of calibration calls
41   *  @param -rate the rate at which requests are sent to the test server
42   *  @param -time the time of the cycle in seconds
43   *  @param -cycles number of cycles of request bursts
44   *  @param -upgradeStart the cycle number at which the upgrade starts
45   *  @param -clients number of local clients generating the requests
46   *  @param -server name at which the test server is registered at the repository
47   *  @param -verbose verbose way of performing the experiment 
48   *
49   *  @author       Marcin Solarski
50   *  @since        Jgroup 2.1
51   */
52  public class UpgradeTestSuite
53  {
54  
55  
56    /** Obtain logger for this class */
57    private static Logger log = Logger.getLogger(UpgradeTestSuite.class);
58    private static UpgradeTestSuite instance = null;
59  
60  
61    public static void main(String[] argv) throws Exception
62    {
63      ConfigManager.init();
64      if (instance == null)
65        instance = new UpgradeTestSuite(argv);
66    }
67    
68    public UpgradeTestSuite(String argv[]) throws Exception {
69      if( argv.length <1 ) help();
70      boolean verbose = PUtil.getSwitch(argv, "-v");
71      int method = PUtil.getIntParameter(argv, "-method", "1");
72      int calibReqCallNo = PUtil.getIntParameter(argv, "-calibrate", "10");
73      int rps = PUtil.getIntParameter(argv, "-rate", "1");
74      int expTime = PUtil.getIntParameter(argv, "-time", "10");
75      int cycles = PUtil.getIntParameter(argv, "-cycles", "1");
76      int upgrade_cycle = PUtil.getIntParameter(argv, "-upgradeStart", "-1");
77      int client_no = PUtil.getIntParameter(argv, "-clients", "1");
78      String serverName = PUtil.getStringParameter(argv, "-server", "UpgradeServer");
79      if( verbose ) {
80         String date = new Date(System.currentTimeMillis()).toString();
81         log.info("Experiment started at: " + date);
82         log.info("Testing suite with the following parameters: ");
83         log.info("Server name:                \t"+ serverName);
84         log.info("Number of calibration calls:\t" + calibReqCallNo);
85         log.info("Test method:                \t" + method);
86         log.info("Request rate per sec:       \t" + rps);
87         log.info("Cycle time:                 \t" + expTime);
88         log.info("Cycles number:              \t"+ cycles);
89         log.info("Staring upgrade at cycle:   \t" + upgrade_cycle);
90      }
91  
92      ClientThreadPool client[] = new ClientThreadPool[client_no];
93  
94      int times = expTime*rps;
95      DependableRegistry reg = RegistryFactory.getRegistry();
96      SpeedTest server = (SpeedTest) reg.lookup(serverName);
97      int call_no = 0, time_tick = expTime/cycles;
98      UpgradeStart upgradeT;
99      upgradeT = new UpgradeStart();
100     ClientThreadPool.init(client_no, cycles);
101     for(int i=0; i<client_no; i++) {
102         client[i]= new ClientThreadPool(method, calibReqCallNo, rps, times, server);
103         client[i].start();
104     }
105     for(int j=0; j< cycles; j++) { 
106       //try{ Thread.sleep(5000); } catch(InterruptedException e) {};
107       ClientThreadPool.allStart();
108       if(j == upgrade_cycle ) upgradeT.start();
109     }
110    
111     for(int i=0; i< client_no; i++) 
112       client[i].CycleDone(cycles);
113     ClientThreadPool.allStop();
114 
115     //header printout
116     StringBuilder header = new StringBuilder("Cycle\tT0");
117     for(int i=0; i< client_no; i++) 
118       header.append("\t" + "RT[" + i +"]");
119     log.info(header);
120 
121     for(int j=1; j< cycles; j++) {
122       long roundTime = j>1 ? ClientThreadPool.getStartCycleTime(j)-ClientThreadPool.getStartCycleTime(j-1) : 0;
123       StringBuilder line = new StringBuilder(""+j + "\t" + roundTime);
124       for(int i=0; i< client_no; i++) 
125           line.append("\t" + ClientThreadPool.getRespTime(i, j));
126       log.info(line);
127     }
128       
129     //log.info("Stopping all threads");
130     //ClientThreadPool.allStop();
131     System.exit(0);
132   } 
133 
134   static void help() {
135      System.out.println("UpgradeTestSuite [-v][-method M][-calibrate C][-rate R][-time T][cycles Y][-clientsi N][-upgradeStart U][-server ServerName]");
136   } 
137 
138 
139   class UpgradeStart extends Thread { 
140 	  String argv[] = new String[] {"u"}; 
141      public void run(){
142 	 try { UpgradeManagementClient.main(argv);
143 	 } catch(Exception e) {log.error("Exception in main", e);}
144 
145      }
146 
147 
148   }
149 
150   
151 }