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 jgroup.core.registry.DependableRegistry;
22  import jgroup.core.registry.RegistryFactory;
23  import jgroup.test.performance.SpeedTest;
24  
25  /**
26   *  Test for measuring the performance of GMI invocations.
27   *  Can be executed remotely through the <t>Executor</t> class,
28   *  since it implements the <t>Server</t> interface.
29   *
30   *  @author       Marcin Solarski
31   *  @since        Jgroup 2.1
32   */
33  public class UpgradeSpeedTestClient
34  {
35  
36  
37    private static void help() {
38       System.out.println("UpgradeSpeedTestClient [-v][-method N][-calibrate C][-rate R][-time T][-clients][-server ServerName]");
39    }
40  
41    
42    public static void main(String[] argv)
43      throws Exception
44    {
45      if( argv.length <1 ) help();
46      boolean verbose = (PUtil.getStringParameter(argv, "-v", "verbose").compareTo("verbose") != 0);
47      int method = PUtil.getIntParameter(argv, "-method", "1");
48      int calibReqCallNo = PUtil.getIntParameter(argv, "-calibrate", "10");
49      int rps = PUtil.getIntParameter(argv, "-rate", "1");
50      int expTime = PUtil.getIntParameter(argv, "-time", "10");
51      int client_no = PUtil.getIntParameter(argv, "-clients", "1");
52      String serverName = PUtil.getStringParameter(argv, "-server", "UpgradeServer");
53      if( verbose ) 
54         System.out.println("Testing server " + serverName + " calibrating with " + calibReqCallNo + " calls of method " + method + " with rate " + rps + " sending for each of " + client_no + " clients for time of " + expTime +" sec.");
55      ClientThreadPool client[] = new ClientThreadPool[client_no];
56      
57      DependableRegistry reg = RegistryFactory.getRegistry();
58      SpeedTest server = (SpeedTest) reg.lookup(serverName);
59      int times = expTime * rps;
60      for(int i=0; i<client_no; i++) {
61        client[i]= new ClientThreadPool(method, calibReqCallNo, rps, times, server);
62        client[i].start();
63      }
64      ClientThreadPool.allStart();
65    }
66  
67   
68  
69    /** True when the action requested is completed */
70    private static boolean completed = false;
71    private int method;
72    private int rps;
73    private int times;
74    private int calibReqCallNo;
75    private String serverName;
76    
77    public UpgradeSpeedTestClient(int method, int calibReqCallNo, int rps, int times, String serverName)
78    {
79       this.method = method;
80       this.calibReqCallNo = calibReqCallNo;
81       this.rps = rps;
82       this.times = times;
83       this.serverName = serverName;
84  
85    }
86  
87  
88    public synchronized void start()
89      throws Exception
90    {
91      UpgradeClientTest test = new UpgradeClientTest(serverName);
92      test.calibrate(method, calibReqCallNo);
93      test.generate_traffic(rps, times);
94      
95      completed = true;
96      notify();
97    }
98  
99    public synchronized void halt()
100     throws Exception
101   {
102     while (!completed)
103       try { wait(); } catch (Exception e) { }
104   }
105 
106 } // END UpgradeSpeedTestClient