KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > rubis > client > ClientEmulator


1 /*
2  * RUBiS
3  * Copyright (C) 2002, 2003, 2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: jmob@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet, Julie Marguerite
22  * Contributor(s): Jeremy Philippe, Niraj Tolia
23  */

24  
25 package edu.rice.rubis.client;
26
27 import java.io.BufferedReader JavaDoc;
28 import java.io.File JavaDoc;
29 import java.io.FileNotFoundException JavaDoc;
30 import java.io.FileOutputStream JavaDoc;
31 import java.io.IOException JavaDoc;
32 import java.io.InputStreamReader JavaDoc;
33 import java.io.PrintStream JavaDoc;
34 import java.util.GregorianCalendar JavaDoc;
35
36 import edu.rice.rubis.beans.TimeManagement;
37 import edu.rice.rubis.client.RUBiSProperties;
38 import edu.rice.rubis.client.Stats;
39 import edu.rice.rubis.client.TransitionTable;
40 import edu.rice.rubis.client.URLGenerator;
41 import edu.rice.rubis.client.UserSession;
42
43 /**
44  * RUBiS client emulator.
45  * This class plays random user sessions emulating a Web browser.
46  *
47  * @author <a HREF="mailto:cecchet@rice.edu">Emmanuel Cecchet</a> and <a HREF="mailto:julie.marguerite@inrialpes.fr">Julie Marguerite</a>
48  *
49  * @version 1.0
50  */

51 public class ClientEmulator
52 {
53   private RUBiSProperties rubis = null; // access to rubis.properties file
54
private URLGenerator urlGen = null;
55   // URL generator corresponding to the version to be used (PHP, EJB or Servlets)
56
private static float slowdownFactor = 0;
57   private static boolean endOfSimulation = false;
58
59   /**
60    * Creates a new <code>ClientEmulator</code> instance.
61    * The program is stopped on any error reading the configuration files.
62    */

63   public ClientEmulator(String JavaDoc propertiesFileName)
64   {
65     // Initialization, check that all files are ok
66
rubis = new RUBiSProperties(propertiesFileName);
67     urlGen = rubis.checkPropertiesFileAndGetURLGenerator();
68     if (urlGen == null)
69       Runtime.getRuntime().exit(1);
70     // Check that the transition table is ok and print it
71
TransitionTable transition =
72       new TransitionTable(
73         rubis.getNbOfColumns(),
74         rubis.getNbOfRows(),
75         null,
76         rubis.useTPCWThinkTime());
77     if (!transition.ReadExcelTextFile(rubis.getTransitionTable()))
78       Runtime.getRuntime().exit(1);
79     else
80       transition.displayMatrix();
81   }
82
83   /**
84    * Updates the slowdown factor.
85    *
86    * @param newValue new slowdown value
87    */

88   private synchronized void setSlowDownFactor(float newValue)
89   {
90     slowdownFactor = newValue;
91   }
92
93   /**
94    * Get the slowdown factor corresponding to current ramp (up, session or down).
95    *
96    * @return slowdown factor of current ramp
97    */

98   public static synchronized float getSlowDownFactor()
99   {
100     return slowdownFactor;
101   }
102
103   /**
104    * Set the end of the current simulation
105    */

106   private synchronized void setEndOfSimulation()
107   {
108     endOfSimulation = true;
109   }
110
111   /**
112    * True if end of simulation has been reached.
113    * @return true if end of simulation
114    */

115   public static synchronized boolean isEndOfSimulation()
116   {
117     return endOfSimulation;
118   }
119
120   /**
121    * As the monitoring program now logs activity in a temporary
122    * location, we need to scp the files over
123    **
124    * @param node node to launch monitoring program on
125    * @param fileName full path and name of file that has the monitoring data
126    * @param outputDir full path name of the local directory the log
127    * file shoudl be copied into
128    */

129   private void getMonitoredData(String JavaDoc node, String JavaDoc fileName,
130                 String JavaDoc outputDir)
131   {
132       String JavaDoc [] scpCmd = new String JavaDoc[3];
133       String JavaDoc lastName = fileName.substring(fileName.lastIndexOf('/')+1);
134
135       scpCmd[0] = rubis.getMonitoringScp();
136       scpCmd[1] = node + ":"+fileName;
137       // As the sar log is a binary file, rename it
138
scpCmd[2] = outputDir+"/" + lastName + ".bin";
139
140       try
141       {
142         System.out.println(
143                            "&nbsp &nbsp Command is: "
144                            + scpCmd[0]
145                            + " "
146                            + scpCmd[1]
147                            + " "
148                            + scpCmd[2]
149                            + "<br>\n");
150
151         Process JavaDoc p = Runtime.getRuntime().exec(scpCmd);
152         p.waitFor();
153         // Now, convert the binary file into ascii form
154
int fullTimeInSec =
155           (rubis.getUpRampTime()
156            + rubis.getSessionTime()
157            + rubis.getDownRampTime())
158            / 1000
159            + 5;
160         String JavaDoc[] convCmd = new String JavaDoc[6];
161         convCmd[0] = rubis.getMonitoringRsh();
162         convCmd[1] = "-x";
163         convCmd[2] = "localhost";
164         convCmd[3] = "/bin/bash";
165         convCmd[4] = "-c";
166         convCmd[5] = "'LANG=en_GB.UTF-8 "
167             + rubis.getMonitoringProgram()
168             + " "
169             + rubis.getMonitoringOptions()
170             + " "
171             + rubis.getMonitoringSampling()
172             + " "
173             + fullTimeInSec
174             + " -f "
175             + outputDir + "/" + lastName
176             + ".bin"
177             + " > "
178             + outputDir
179             + "/"
180             + lastName
181             + "'";
182         System.out.println("&nbsp &nbsp Command is: "+convCmd[0]+" "+convCmd[1]+" "+convCmd[2]+" "+convCmd[3]+" "+convCmd[4]+" "+convCmd[5]+"<br>\n");
183         p = Runtime.getRuntime().exec(convCmd);
184         p.waitFor();
185       }
186       catch (InterruptedException JavaDoc ie)
187       {
188           System.out.println(
189                  "An error occured while executing "
190                  + "monitoring program ("
191                  + ie.getMessage()
192                  + ")");
193
194       }
195       catch (IOException JavaDoc ioe)
196       {
197           System.out.println(
198                  "An error occured while executing "
199                  + "monitoring program ("
200                  + ioe.getMessage()
201                  + ")");
202       }
203   }
204
205   /**
206    * As the remote HTML files are created in a temporary
207    * location, we need to scp these files over
208    **
209    * @param node node to launch monitoring program on
210    * @param fileName full path and name of file that has the monitoring data
211    * @param outputDir full path name of the local directory the log
212    * file shoudl be copied into
213    */

214   private void getHTMLData(String JavaDoc node, String JavaDoc fileName,
215                 String JavaDoc outputDir)
216   {
217       String JavaDoc [] scpCmd = new String JavaDoc[3];
218
219       scpCmd[0] = rubis.getMonitoringScp();
220       scpCmd[1] = node + ":"+fileName;
221       scpCmd[2] = outputDir+"/";
222
223       try
224       {
225           System.out.println(
226                              "&nbsp &nbsp Command is: "
227                              + scpCmd[0]
228                              + " "
229                              + scpCmd[1]
230                              + " "
231                              + scpCmd[2]
232                              + "<br>\n");
233
234           Process JavaDoc p = Runtime.getRuntime().exec(scpCmd);
235           p.waitFor();
236
237       }
238       catch (InterruptedException JavaDoc ie)
239       {
240           System.out.println(
241                  "An error occured while executing "
242                  + "monitoring program ("
243                  + ie.getMessage()
244                  + ")");
245
246       }
247       catch (IOException JavaDoc ioe)
248       {
249           System.out.println(
250                  "An error occured while executing "
251                  + "monitoring program ("
252                  + ioe.getMessage()
253                  + ")");
254       }
255   }
256
257   /**
258    * Start the monitoring program specified in rubis.properties
259    * on a remote node and redirect the output in a file local
260    * to this node (we are more happy if it is on a NFS volume)
261    *
262    * @param node node to launch monitoring program on
263    * @param outputFileName full path and name of file to redirect output into
264    * @return the <code>Process</code> object created
265    */

266   private Process JavaDoc startMonitoringProgram(String JavaDoc node, String JavaDoc outputFileName)
267   {
268     int fullTimeInSec =
269       (rubis.getUpRampTime()
270         + rubis.getSessionTime()
271         + rubis.getDownRampTime())
272         / 1000
273         + 5;
274     // Give 5 seconds extra for init
275

276     // First, try to wipe out the old log files as sar (sysstat)
277
// appends for binary mode
278
try
279     {
280       String JavaDoc[] delFiles = new String JavaDoc[4];
281       Process JavaDoc delProcess;
282       delFiles[0] = rubis.getMonitoringRsh();
283       delFiles[1] = "-x";
284       delFiles[2] = node.trim();
285       delFiles[3] = "rm -f "+outputFileName;
286       System.out.println("&nbsp &nbsp Command is: "+delFiles[0]+" "+delFiles[1]+" "+delFiles[2]+" "+delFiles[3]+"<br>\n");
287       delProcess = Runtime.getRuntime().exec(delFiles);
288       delProcess.waitFor();
289     }
290     catch (IOException JavaDoc ioe)
291     {
292       System.out.println(
293         "An error occured while deleting old log files ("
294           + ioe.getMessage()
295           + ")");
296       return null;
297     }
298     catch (InterruptedException JavaDoc ie)
299     {
300       System.out.println(
301         "An error occured while deleting old log files ("
302           + ie.getMessage()
303           + ")");
304       return null;
305     }
306
307     try
308     {
309       String JavaDoc[] cmd = new String JavaDoc[6];
310       cmd[0] = rubis.getMonitoringRsh();
311       cmd[1] = "-x";
312       cmd[2] = node.trim();
313       cmd[3] = "/bin/bash";
314       cmd[4] = "-c";
315       cmd[5] = "'LANG=en_GB.UTF-8 "
316           + rubis.getMonitoringProgram()
317           + " "
318           + rubis.getMonitoringOptions()
319           + " "
320           + rubis.getMonitoringSampling()
321           + " "
322           + fullTimeInSec
323           + " -o "
324           + outputFileName
325       + "'";
326       System.out.println(
327         "&nbsp &nbsp Command is: "
328           + cmd[0]
329           + " "
330           + cmd[1]
331           + " "
332           + cmd[2]
333           + " "
334           + cmd[3]
335           + " "
336           + cmd[4]
337           + " "
338           + cmd[5]
339           + "<br>\n");
340       return Runtime.getRuntime().exec(cmd);
341     }
342     catch (IOException JavaDoc ioe)
343     {
344       System.out.println(
345         "An error occured while executing monitoring program ("
346           + ioe.getMessage()
347           + ")");
348       return null;
349     }
350   }
351
352   /**
353    * Run the node_info.sh script on the remote node and
354    * just forward what we get from standard output.
355    *
356    * @param node node to get information from
357    */

358   private void printNodeInformation(String JavaDoc node)
359   {
360     try
361     {
362       File JavaDoc dir = new File JavaDoc(".");
363       /* String nodeInfoProgram = dir.getCanonicalPath() + "/bench/node_info.sh"; */
364       String JavaDoc nodeInfoProgram = "/bin/echo \"Host : \"`/bin/hostname` ; " +
365           "/bin/echo \"Kernel: \"`/bin/cat /proc/version` ; " +
366           "/bin/grep net /proc/pci ; " +
367           "/bin/grep processor /proc/cpuinfo ; " +
368           "/bin/grep vendor_id /proc/cpuinfo ; " +
369           "/bin/grep model /proc/cpuinfo ; " +
370           "/bin/grep MHz /proc/cpuinfo ; " +
371           "/bin/grep cache /proc/cpuinfo ; " +
372           "/bin/grep MemTotal /proc/meminfo ; " +
373           "/bin/grep SwapTotal /proc/meminfo ";
374
375       String JavaDoc[] cmd = new String JavaDoc[4];
376       cmd[0] = rubis.getMonitoringRsh();
377       cmd[1] = "-x";
378       cmd[2] = node;
379       cmd[3] = nodeInfoProgram;
380       Process JavaDoc p = Runtime.getRuntime().exec(cmd);
381       BufferedReader JavaDoc read =
382         new BufferedReader JavaDoc(new InputStreamReader JavaDoc(p.getInputStream()));
383       String JavaDoc msg;
384       while ((msg = read.readLine()) != null) {
385     System.out.println(msg + "<br>");
386       }
387       read.close();
388     }
389     catch (Exception JavaDoc ioe)
390     {
391       System.out.println(
392         "An error occured while getting node information ("
393           + ioe.getMessage()
394           + ")");
395     }
396   }
397
398   /**
399    * Main program take an optional output file argument only
400    * if it is run on as a remote client.
401    *
402    * @param args optional output file if run as remote client
403    */

404   public static void main(String JavaDoc[] args)
405   {
406     GregorianCalendar JavaDoc startDate;
407     GregorianCalendar JavaDoc endDate;
408     GregorianCalendar JavaDoc upRampDate;
409     GregorianCalendar JavaDoc runSessionDate;
410     GregorianCalendar JavaDoc downRampDate;
411     GregorianCalendar JavaDoc endDownRampDate;
412     Process JavaDoc webServerMonitor = null;
413     Process JavaDoc cjdbcServerMonitor = null;
414     Process JavaDoc[] dbServerMonitor = null;
415     Process JavaDoc[] ejbServerMonitor = null;
416     Process JavaDoc[] servletsServerMonitor = null;
417     Process JavaDoc clientMonitor;
418     Process JavaDoc[] remoteClientMonitor = null;
419     Process JavaDoc[] remoteClient = null;
420     String JavaDoc reportDir = "";
421     String JavaDoc tmpDir = "/tmp/";
422     boolean isMainClient = (args.length <= 2); // Check if we are the main client
423
String JavaDoc propertiesFileName;
424     
425     if (isMainClient)
426     {
427       // Start by creating a report directory and redirecting output to an index.html file
428
System.out.println(
429         "RUBiS client emulator - (C) Rice University/INRIA 2001\n");
430
431       if (args.length <= 1)
432       {
433         reportDir = "bench/"+TimeManagement.currentDateToString()+"/";
434         reportDir = reportDir.replace(' ', '@');
435       }
436       else
437       {
438         reportDir = "bench/"+args[1];
439       }
440       try
441       {
442         System.out.println("Creating report directory " + reportDir);
443         File JavaDoc dir = new File JavaDoc(reportDir);
444         dir.mkdirs();
445         if (!dir.isDirectory())
446         {
447           System.out.println(
448             "Unable to create "
449               + reportDir
450               + " using current directory instead");
451           reportDir = "./";
452         }
453         else
454           reportDir = dir.getCanonicalPath() + "/";
455         System.out.println(
456           "Redirecting output to '" + reportDir + "index.html'");
457         PrintStream JavaDoc outputStream =
458           new PrintStream JavaDoc(new FileOutputStream JavaDoc(reportDir + "index.html"));
459         System.out.println("Please wait while experiment is running ...");
460         System.setOut(outputStream);
461         System.setErr(outputStream);
462       }
463       catch (Exception JavaDoc e)
464       {
465         System.out.println(
466           "Output redirection failed, displaying results on standard output ("
467             + e.getMessage()
468             + ")");
469       }
470       System.out.println(
471         "<h2>RUBiS client emulator - (C) Rice University/INRIA 2001</h2><p>\n");
472       startDate = new GregorianCalendar JavaDoc();
473       System.out.println(
474         "<h3>Test date: "
475           + TimeManagement.dateToString(startDate)
476           + "</h3><br>\n");
477
478       System.out.println("<A HREF=\"#config\">Test configuration</A><br>");
479       System.out.println("<A HREF=\"trace_client0.html\">Test trace</A><br>");
480       System.out.println(
481         "<A HREF=\"perf.html\">Test performance report</A><br><p>");
482       System.out.println("<p><hr><p>");
483
484       System.out.println(
485         "<CENTER><A NAME=\"config\"></A><h2>*** Test configuration ***</h2></CENTER>");
486       if (args.length == 0)
487         propertiesFileName = "rubis";
488       else
489         propertiesFileName = args[0];
490     }
491     else
492     {
493       System.out.println(
494         "RUBiS remote client emulator - (C) Rice University/INRIA 2001\n");
495       startDate = new GregorianCalendar JavaDoc();
496       propertiesFileName = args[2];
497     }
498
499     ClientEmulator client = new ClientEmulator(propertiesFileName);
500     // Get also rubis.properties info
501

502     Stats stats = new Stats(client.rubis.getNbOfRows());
503     Stats upRampStats = new Stats(client.rubis.getNbOfRows());
504     Stats runSessionStats = new Stats(client.rubis.getNbOfRows());
505     Stats downRampStats = new Stats(client.rubis.getNbOfRows());
506     Stats allStats = new Stats(client.rubis.getNbOfRows());
507     UserSession[] sessions = new UserSession[client.rubis.getNbOfClients()];
508     boolean cjdbcFlag = client.rubis.getCJDBCServerName() != null
509         && !client.rubis.getCJDBCServerName().equals("");
510     System.out.println("<p><hr><p>");
511
512     if (isMainClient)
513     {
514       // Start remote clients
515
System.out.println(
516         "Total number of clients for this experiment: "
517           + (client.rubis.getNbOfClients()
518             * (client.rubis.getRemoteClients().size() + 1))
519           + "<br>");
520       remoteClient = new Process JavaDoc[client.rubis.getRemoteClients().size()];
521       for (int i = 0; i < client.rubis.getRemoteClients().size(); i++)
522       {
523         try
524         {
525           System.out.println(
526             "ClientEmulator: Starting remote client on "
527               + client.rubis.getRemoteClients().get(i)
528               + "<br>\n");
529           String JavaDoc[] rcmdClient = new String JavaDoc[3];
530           rcmdClient[0] = client.rubis.getMonitoringRsh();
531           rcmdClient[1] = (String JavaDoc) client.rubis.getRemoteClients().get(i);
532           rcmdClient[2] =
533             client.rubis.getClientsRemoteCommand()
534               + " "
535               + tmpDir
536               + "trace_client"
537               + (i + 1)
538               + ".html "
539               + tmpDir
540               + "stat_client"
541               + (i + 1)
542               + ".html"
543               + " "
544               + propertiesFileName;
545           remoteClient[i] = Runtime.getRuntime().exec(rcmdClient);
546           System.out.println(
547             "&nbsp &nbsp Command is: "
548               + rcmdClient[0]
549               + " "
550               + rcmdClient[1]
551               + " "
552               + rcmdClient[2]
553               + "<br>\n");
554         }
555         catch (IOException JavaDoc ioe)
556         {
557           System.out.println(
558             "An error occured while executing remote client ("
559               + ioe.getMessage()
560               + ")");
561         }
562       }
563
564       // Start monitoring programs
565
System.out.println(
566         "<CENTER></A><A NAME=\"trace\"><h2>*** Monitoring ***</h2></CENTER>");
567
568       // Monitor Web server
569
System.out.println(
570         "ClientEmulator: Starting monitoring program on Web server "
571           + client.rubis.getWebServerName()
572           + "<br>\n");
573       webServerMonitor =
574         client.startMonitoringProgram(
575           client.rubis.getWebServerName(),
576           tmpDir + "web_server");
577
578       // Monitor C-JDBC server (if any)
579
if (cjdbcFlag)
580       {
581         System.out.println(
582           "ClientEmulator: Starting monitoring program on CJDBC server "
583             + client.rubis.getCJDBCServerName()
584             + "<br>\n");
585         cjdbcServerMonitor =
586           client.startMonitoringProgram(
587             client.rubis.getCJDBCServerName(),
588             tmpDir + "cjdbc_server");
589       }
590
591       if (client.rubis.getDBServerNames().size() > 0)
592         dbServerMonitor = new Process JavaDoc[client.rubis.getDBServerNames().size()];
593       // Monitor Database server
594
for (int i = 0; i < client.rubis.getDBServerNames().size(); i++)
595       {
596         System.out.println("ClientEmulator: Starting monitoring program on Database server "+client.rubis.getDBServerNames().get(i)+"<br>\n");
597         dbServerMonitor[i] = client.startMonitoringProgram((String JavaDoc)client.rubis.getDBServerNames().get(i), tmpDir+"db_server"+i);
598       }
599         
600       if (client.rubis.getServletsServerNames().size() > 0)
601       servletsServerMonitor = new Process JavaDoc[client.rubis.getServletsServerNames().size()];
602       // Monitoring Servlets server, if any
603
for (int i = 0; i < client.rubis.getServletsServerNames().size(); i++)
604       {
605         System.out.println("ClientEmulator: Starting monitoring program on Servlets server "+client.rubis.getServletsServerNames().get(i)+"<br>\n");
606         servletsServerMonitor[i] = client.startMonitoringProgram((String JavaDoc)client.rubis.getServletsServerNames().get(i), tmpDir+"servlets_server"+i);
607       }
608      
609       if (client.rubis.getEJBServerNames().size() > 0)
610       ejbServerMonitor = new Process JavaDoc[client.rubis.getEJBServerNames().size()];
611       // Monitoring EJB server, if any
612
for (int i = 0; i < client.rubis.getEJBServerNames().size(); i++)
613       {
614         System.out.println("ClientEmulator: Starting monitoring program on EJB server "+client.rubis.getEJBServerNames().get(i)+"<br>\n");
615         ejbServerMonitor[i] = client.startMonitoringProgram((String JavaDoc)client.rubis.getEJBServerNames().get(i), tmpDir+"ejb_server"+i);
616       }
617
618       // Monitor local client
619
System.out.println(
620         "ClientEmulator: Starting monitoring program locally on client<br>\n");
621       clientMonitor =
622         client.startMonitoringProgram("localhost", tmpDir + "client0");
623
624       remoteClientMonitor = new Process JavaDoc[client.rubis.getRemoteClients().size()];
625       // Monitor remote clients
626
for (int i = 0; i < client.rubis.getRemoteClients().size(); i++)
627       {
628         System.out.println(
629           "ClientEmulator: Starting monitoring program locally on client<br>\n");
630         remoteClientMonitor[i] =
631           client.startMonitoringProgram(
632             (String JavaDoc) client.rubis.getRemoteClients().get(i),
633             tmpDir + "client" + (i + 1));
634       }
635
636       // Redirect output for traces
637
try
638       {
639         PrintStream JavaDoc outputStream =
640           new PrintStream JavaDoc(
641             new FileOutputStream JavaDoc(reportDir + "trace_client0.html"));
642         System.setOut(outputStream);
643         System.setErr(outputStream);
644       }
645       catch (FileNotFoundException JavaDoc fnf)
646       {
647         System.err.println(
648           "Unable to redirect main client output, got error ("
649             + fnf.getMessage()
650             + ")<br>");
651       }
652     }
653     else
654     { // Redirect output of remote clients
655
System.out.println("Redirecting output to '" + args[0] + "'");
656       try
657       {
658         PrintStream JavaDoc outputStream =
659           new PrintStream JavaDoc(new FileOutputStream JavaDoc(args[0]));
660         System.out.println("Please wait while experiment is running ...");
661         System.setOut(outputStream);
662         System.setErr(outputStream);
663       }
664       catch (Exception JavaDoc e)
665       {
666         System.out.println(
667           "Output redirection failed, displaying results on standard output ("
668             + e.getMessage()
669             + ")");
670       }
671       startDate = new GregorianCalendar JavaDoc();
672     }
673
674     // #############################
675
// ### TEST TRACE BEGIN HERE ###
676
// #############################
677

678     System.out.println(
679       "<CENTER></A><A NAME=\"trace\"><h2>*** Test trace ***</h2></CENTER><p>");
680     System.out.println(
681       "<A HREF=\"trace_client0.html\">Main client traces</A><br>");
682     for (int i = 0; i < client.rubis.getRemoteClients().size(); i++)
683       System.out.println(
684         "<A HREF=\"trace_client"
685           + (i + 1)
686           + ".html\">client1 ("
687           + client.rubis.getRemoteClients().get(i)
688           + ") traces</A><br>");
689     System.out.println("<br><p>");
690     System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#up\">Up ramp trace</A><br>");
691     System.out.println(
692       "&nbsp&nbsp&nbsp<A HREF=\"#run\">Runtime session trace</A><br>");
693     System.out.println(
694       "&nbsp&nbsp&nbsp<A HREF=\"#down\">Down ramp trace</A><br><p><p>");
695
696     // Run user sessions
697
System.out.println(
698       "ClientEmulator: Starting "
699         + client.rubis.getNbOfClients()
700         + " session threads<br>");
701     for (int i = 0; i < client.rubis.getNbOfClients(); i++)
702     {
703       sessions[i] =
704         new UserSession("UserSession" + i, client.urlGen, client.rubis, stats);
705       sessions[i].start();
706     }
707
708     // Start up-ramp
709
System.out.println("<br><A NAME=\"up\"></A>");
710     System.out.println(
711       "<h3>ClientEmulator: Switching to ** UP RAMP **</h3><br><p>");
712     client.setSlowDownFactor(client.rubis.getUpRampSlowdown());
713     upRampDate = new GregorianCalendar JavaDoc();
714     try
715     {
716       Thread.currentThread().sleep(client.rubis.getUpRampTime());
717     }
718     catch (java.lang.InterruptedException JavaDoc ie)
719     {
720       System.err.println("ClientEmulator has been interrupted.");
721     }
722     upRampStats.merge(stats);
723     stats.reset();
724     // Note that as this is not atomic we may lose some stats here ...
725

726     // Start runtime session
727
System.out.println("<br><A NAME=\"run\"></A>");
728     System.out.println(
729       "<h3>ClientEmulator: Switching to ** RUNTIME SESSION **</h3><br><p>");
730     client.setSlowDownFactor(1);
731     runSessionDate = new GregorianCalendar JavaDoc();
732     try
733     {
734       Thread.currentThread().sleep(client.rubis.getSessionTime());
735     }
736     catch (java.lang.InterruptedException JavaDoc ie)
737     {
738       System.err.println("ClientEmulator has been interrupted.");
739     }
740     runSessionStats.merge(stats);
741     stats.reset();
742     // Note that as this is not atomic we may lose some stats here ...
743

744     // Start down-ramp
745
System.out.println("<br><A NAME=\"down\"></A>");
746     System.out.println(
747       "<h3>ClientEmulator: Switching to ** DOWN RAMP **</h3><br><p>");
748     client.setSlowDownFactor(client.rubis.getDownRampSlowdown());
749     downRampDate = new GregorianCalendar JavaDoc();
750     try
751     {
752       Thread.currentThread().sleep(client.rubis.getDownRampTime());
753     }
754     catch (java.lang.InterruptedException JavaDoc ie)
755     {
756       System.err.println("ClientEmulator has been interrupted.");
757     }
758     downRampStats.merge(stats);
759     endDownRampDate = new GregorianCalendar JavaDoc();
760
761     // Wait for completion
762
client.setEndOfSimulation();
763     System.out.println("ClientEmulator: Shutting down threads ...<br>");
764     for (int i = 0; i < client.rubis.getNbOfClients(); i++)
765     {
766       try
767       {
768         sessions[i].join(2000);
769       }
770       catch (java.lang.InterruptedException JavaDoc ie)
771       {
772         System.err.println(
773           "ClientEmulator: Thread " + i + " has been interrupted.");
774       }
775     }
776     System.out.println("Done\n");
777     endDate = new GregorianCalendar JavaDoc();
778     allStats.merge(stats);
779     allStats.merge(runSessionStats);
780     allStats.merge(upRampStats);
781     System.out.println("<p><hr><p>");
782
783     // #############################################
784
// ### EXPERIMENT IS OVER, COLLECT THE STATS ###
785
// #############################################
786

787     // All clients completed, here is the performance report !
788
// but first redirect the output
789
try
790     {
791       PrintStream JavaDoc outputStream;
792       if (isMainClient)
793         outputStream =
794           new PrintStream JavaDoc(new FileOutputStream JavaDoc(reportDir + "perf.html"));
795       else
796         outputStream = new PrintStream JavaDoc(new FileOutputStream JavaDoc(args[1]));
797       System.setOut(outputStream);
798       System.setErr(outputStream);
799     }
800     catch (Exception JavaDoc e)
801     {
802       System.out.println(
803         "Output redirection failed, displaying results on standard output ("
804           + e.getMessage()
805           + ")");
806     }
807
808     System.out.println(
809       "<center><h2>*** Performance Report ***</h2></center><br>");
810     System.out.println(
811       "<A HREF=\"perf.html\">Overall performance report</A><br>");
812     System.out.println(
813       "<A HREF=\"stat_client0.html\">Main client (localhost) statistics</A><br>");
814     for (int i = 0; i < client.rubis.getRemoteClients().size(); i++)
815       System.out.println(
816         "<A HREF=\"stat_client"
817           + (i + 1)
818           + ".html\">client1 ("
819           + client.rubis.getRemoteClients().get(i)
820           + ") statistics</A><br>");
821     System.out.println("<A HREF=\"db_graphs.html\">Database graphs</A><br>");
822     if (client.rubis.getServletsServerNames().size() > 0)
823       System.out.println("<A HREF=\"servlets_graphs.html\">Servlets graphs</A><br>");
824     if (client.rubis.getEJBServerNames().size() > 0)
825       System.out.println("<A HREF=\"ejb_graphs.html\">EJB graphs</A><br>");
826     
827     System.out.println(
828       "<p><br>&nbsp&nbsp&nbsp<A HREF=\"perf.html#node\">Node information</A><br>");
829     System.out.println(
830       "&nbsp&nbsp&nbsp<A HREF=\"#time\">Test timing information</A><br>");
831     System.out.println(
832       "&nbsp&nbsp&nbsp<A HREF=\"#up_stat\">Up ramp statistics</A><br>");
833     System.out.println(
834       "&nbsp&nbsp&nbsp<A HREF=\"#run_stat\">Runtime session statistics</A><br>");
835     System.out.println(
836       "&nbsp&nbsp&nbsp<A HREF=\"#down_stat\">Down ramp statistics</A><br>");
837     System.out.println(
838       "&nbsp&nbsp&nbsp<A HREF=\"#all_stat\">Overall statistics</A><br>");
839     System.out.println(
840       "&nbsp&nbsp&nbsp<A HREF=\"#cpu_graph\">CPU usage graphs</A><br>");
841     System.out.println(
842       "&nbsp&nbsp&nbsp<A HREF=\"#procs_graph\">Processes usage graphs</A><br>");
843     System.out.println(
844       "&nbsp&nbsp&nbsp<A HREF=\"#mem_graph\">Memory usage graph</A><br>");
845     System.out.println(
846       "&nbsp&nbsp&nbsp<A HREF=\"#disk_graph\">Disk usage graphs</A><br>");
847     System.out.println(
848       "&nbsp&nbsp&nbsp<A HREF=\"#net_graph\">Network usage graphs</A><br>");
849
850     if (isMainClient)
851     {
852       // Get information about each node
853
System.out.println(
854         "<br><A NAME=\"node\"></A><h3>Node Information</h3><br>");
855
856       // Web server
857
System.out.println("<B>Web server</B><br>");
858       client.printNodeInformation(client.rubis.getWebServerName());
859
860       // C-JDBC server
861
if (cjdbcFlag)
862       {
863         System.out.println("<br><B>C-JDBC server</B><br>");
864         client.printNodeInformation((String JavaDoc)client.rubis.getCJDBCServerName());
865       }
866
867       // Database server
868
System.out.println("<br><B>Database server</B><br>");
869       client.printNodeInformation((String JavaDoc)client.rubis.getDBServerNames().get(0));
870       
871       // Servlets server, if any
872
if (client.rubis.getServletsServerNames().size() > 0)
873       {
874          System.out.println("<br><B>Servlets server</B><br>");
875           client.printNodeInformation((String JavaDoc)client.rubis.getServletsServerNames().get(0));
876       }
877       
878       // EJB server, if any
879
if (client.rubis.getEJBServerNames().size() > 0)
880        {
881           System.out.println("<br><B>EJB server</B><br>");
882           client.printNodeInformation((String JavaDoc)client.rubis.getEJBServerNames().get(0));
883        }
884       
885       // Client
886
System.out.println("<br><B>Local client</B><br>");
887       client.printNodeInformation("localhost");
888
889       // Remote Clients
890
for (int i = 0; i < client.rubis.getRemoteClients().size(); i++)
891       {
892         System.out.println("<br><B>Remote client " + i + "</B><br>");
893         client.printNodeInformation(
894           (String JavaDoc) client.rubis.getRemoteClients().get(i));
895       }
896
897       try
898       {
899         PrintStream JavaDoc outputStream = new PrintStream JavaDoc(new FileOutputStream JavaDoc(reportDir+"db_graphs.html"));
900         System.setOut(outputStream);
901         System.setErr(outputStream);
902       }
903       catch (Exception JavaDoc ioe)
904       {
905         System.out.println("An error occured while creating file ("+ioe.getMessage()+")");
906       }
907
908       System.out.println("<center><h2>*** Database servers graphs ***</h2></center><br>");
909       System.out.println("<A HREF=\"perf.html\">Overall performance report</A><br>");
910       System.out.println("<A HREF=\"stat_client0.html\">Main client (localhost) statistics</A><br>");
911       for (int i = 0 ; i < client.rubis.getRemoteClients().size() ; i++)
912         System.out.println("<A HREF=\"stat_client"+(i+1)+".html\">client1 ("+client.rubis.getRemoteClients().get(i)+") statistics</A><br>");
913       System.out.println("<A HREF=\"db_graphs.html\">Database graphs</A><br>");
914       if (client.rubis.getServletsServerNames().size() > 0)
915         System.out.println("<A HREF=\"servlets_graphs.html\">Servlets graphs</A><br>");
916       if (client.rubis.getEJBServerNames().size() > 0)
917         System.out.println("<A HREF=\"ejb_graphs.html\">EJB graphs</A><br>");
918
919       System.out.println("<p><br>&nbsp&nbsp&nbsp<A HREF=\"#node\">Node information</A><br>");
920       System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#cpu_graph\">CPU usage graphs</A><br>");
921       System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#procs_graph\">Processes usage graphs</A><br>");
922       System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#mem_graph\">Memory usage graph</A><br>");
923       System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#disk_graph\">Disk usage graphs</A><br>");
924       System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#net_graph\">Network usage graphs</A><br>");
925
926       System.out.println("<br><A NAME=\"node\"></A><h3>Node Information</h3><br>");
927       for (int i = 0; i < client.rubis.getDBServerNames().size(); i++)
928       {
929         System.out.println("<br><B>Database server "+i+"</B><br>");
930         client.printNodeInformation((String JavaDoc)client.rubis.getDBServerNames().get(i));
931       }
932
933       System.out.println("<br><A NAME=\"cpu_graph\"></A>");
934       System.out.println("<br><h3>CPU Usage graphs</h3><p>");
935       System.out.println("<IMG SRC=\"db_cpu_busy."+client.rubis.getGnuPlotTerminal()+"\">");
936       System.out.println("<IMG SRC=\"db_cpu_idle."+client.rubis.getGnuPlotTerminal()+"\">");
937       System.out.println("<IMG SRC=\"db_cpu_user_kernel."+client.rubis.getGnuPlotTerminal()+"\">");
938
939       System.out.println("<br><A NAME=\"procs_graph\"></A>");
940       System.out.println("<br><h3>Processes Usage graphs</h3><p>");
941       System.out.println("<IMG SRC=\"db_procs."+client.rubis.getGnuPlotTerminal()+"\">");
942       System.out.println("<IMG SRC=\"db_ctxtsw."+client.rubis.getGnuPlotTerminal()+"\">");
943
944       System.out.println("<br><A NAME=\"mem_graph\"></A>");
945       System.out.println("<br><h3>Memory Usage graphs</h3><p>");
946       System.out.println("<IMG SRC=\"db_mem_usage."+client.rubis.getGnuPlotTerminal()+"\">");
947       System.out.println("<IMG SRC=\"db_mem_cache."+client.rubis.getGnuPlotTerminal()+"\">");
948
949       System.out.println("<br><A NAME=\"disk_graph\"></A>");
950       System.out.println("<br><h3>Disk Usage graphs</h3><p>");
951       System.out.println("<IMG SRC=\"db_disk_rw_req."+client.rubis.getGnuPlotTerminal()+"\">");
952       System.out.println("<IMG SRC=\"db_disk_tps."+client.rubis.getGnuPlotTerminal()+"\">");
953
954       System.out.println("<br><A NAME=\"net_graph\"></A>");
955       System.out.println("<br><h3>Network Usage graphs</h3><p>");
956       System.out.println("<IMG SRC=\"db_net_rt_byt."+client.rubis.getGnuPlotTerminal()+"\">");
957       System.out.println("<IMG SRC=\"db_net_rt_pack."+client.rubis.getGnuPlotTerminal()+"\">");
958       System.out.println("<IMG SRC=\"db_socks."+client.rubis.getGnuPlotTerminal()+"\">");
959
960       if (client.rubis.getServletsServerNames().size() > 0)
961       {
962         try
963         {
964           PrintStream JavaDoc outputStream = new PrintStream JavaDoc(new FileOutputStream JavaDoc(reportDir+"servlets_graphs.html"));
965           System.setOut(outputStream);
966           System.setErr(outputStream);
967         }
968         catch (Exception JavaDoc ioe)
969         {
970           System.out.println("An error occured while creating file ("+ioe.getMessage()+")");
971         }
972
973         System.out.println("<center><h2>*** Servlets servers graphs ***</h2></center><br>");
974         System.out.println("<A HREF=\"perf.html\">Overall performance report</A><br>");
975         System.out.println("<A HREF=\"stat_client0.html\">Main client (localhost) statistics</A><br>");
976         for (int i = 0 ; i < client.rubis.getRemoteClients().size() ; i++)
977           System.out.println("<A HREF=\"stat_client"+(i+1)+".html\">client1 ("+client.rubis.getRemoteClients().get(i)+") statistics</A><br>");
978         System.out.println("<A HREF=\"db_graphs.html\">Database graphs</A><br>");
979         if (client.rubis.getServletsServerNames().size() > 0)
980           System.out.println("<A HREF=\"servlets_graphs.html\">Servlets graphs</A><br>");
981         if (client.rubis.getEJBServerNames().size() > 0)
982           System.out.println("<A HREF=\"ejb_graphs.html\">EJB graphs</A><br>");
983
984         System.out.println("<p><br>&nbsp&nbsp&nbsp<A HREF=\"#node\">Node information</A><br>");
985         System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#cpu_graph\">CPU usage graphs</A><br>");
986         System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#procs_graph\">Processes usage graphs</A><br>");
987         System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#mem_graph\">Memory usage graph</A><br>");
988         System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#disk_graph\">Disk usage graphs</A><br>");
989         System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#net_graph\">Network usage graphs</A><br>");
990
991         System.out.println("<br><A NAME=\"node\"></A><h3>Node Information</h3><br>");
992         for (int i = 0; i < client.rubis.getServletsServerNames().size(); i++)
993         {
994           System.out.println("<br><B>Servlets server "+i+"</B><br>");
995           client.printNodeInformation((String JavaDoc)client.rubis.getServletsServerNames().get(i));
996         }
997
998         System.out.println("<br><A NAME=\"cpu_graph\"></A>");
999         System.out.println("<br><h3>CPU Usage graphs</h3><p>");
1000        System.out.println("<IMG SRC=\"servlets_cpu_busy."+client.rubis.getGnuPlotTerminal()+"\">");
1001        System.out.println("<IMG SRC=\"servlets_cpu_idle."+client.rubis.getGnuPlotTerminal()+"\">");
1002        System.out.println("<IMG SRC=\"servlets_cpu_user_kernel."+client.rubis.getGnuPlotTerminal()+"\">");
1003
1004        System.out.println("<br><A NAME=\"procs_graph\"></A>");
1005        System.out.println("<br><h3>Processes Usage graphs</h3><p>");
1006        System.out.println("<IMG SRC=\"servlets_procs."+client.rubis.getGnuPlotTerminal()+"\">");
1007        System.out.println("<IMG SRC=\"servlets_ctxtsw."+client.rubis.getGnuPlotTerminal()+"\">");
1008
1009        System.out.println("<br><A NAME=\"mem_graph\"></A>");
1010        System.out.println("<br><h3>Memory Usage graphs</h3><p>");
1011        System.out.println("<IMG SRC=\"servlets_mem_usage."+client.rubis.getGnuPlotTerminal()+"\">");
1012        System.out.println("<IMG SRC=\"servlets_mem_cache."+client.rubis.getGnuPlotTerminal()+"\">");
1013
1014        System.out.println("<br><A NAME=\"disk_graph\"></A>");
1015        System.out.println("<br><h3>Disk Usage graphs</h3><p>");
1016        System.out.println("<IMG SRC=\"servlets_disk_rw_req."+client.rubis.getGnuPlotTerminal()+"\">");
1017        System.out.println("<IMG SRC=\"servlets_disk_tps."+client.rubis.getGnuPlotTerminal()+"\">");
1018
1019        System.out.println("<br><A NAME=\"net_graph\"></A>");
1020        System.out.println("<br><h3>Network Usage graphs</h3><p>");
1021        System.out.println("<IMG SRC=\"servlets_net_rt_byt."+client.rubis.getGnuPlotTerminal()+"\">");
1022        System.out.println("<IMG SRC=\"servlets_net_rt_pack."+client.rubis.getGnuPlotTerminal()+"\">");
1023        System.out.println("<IMG SRC=\"servlets_socks."+client.rubis.getGnuPlotTerminal()+"\">");
1024      }
1025
1026      if (client.rubis.getEJBServerNames().size() > 0)
1027      {
1028        try
1029        {
1030          PrintStream JavaDoc outputStream = new PrintStream JavaDoc(new FileOutputStream JavaDoc(reportDir+"ejb_graphs.html"));
1031          System.setOut(outputStream);
1032          System.setErr(outputStream);
1033        }
1034        catch (Exception JavaDoc ioe)
1035        {
1036          System.out.println("An error occured while creating file ("+ioe.getMessage()+")");
1037        }
1038
1039        System.out.println("<center><h2>*** EJB servers graphs ***</h2></center><br>");
1040        System.out.println("<A HREF=\"perf.html\">Overall performance report</A><br>");
1041        System.out.println("<A HREF=\"stat_client0.html\">Main client (localhost) statistics</A><br>");
1042        for (int i = 0 ; i < client.rubis.getRemoteClients().size() ; i++)
1043          System.out.println("<A HREF=\"stat_client"+(i+1)+".html\">client1 ("+client.rubis.getRemoteClients().get(i)+") statistics</A><br>");
1044        System.out.println("<A HREF=\"db_graphs.html\">Database graphs</A><br>");
1045        if (client.rubis.getServletsServerNames().size() > 0)
1046          System.out.println("<A HREF=\"servlets_graphs.html\">Servlets graphs</A><br>");
1047        if (client.rubis.getEJBServerNames().size() > 0)
1048          System.out.println("<A HREF=\"ejb_graphs.html\">EJB graphs</A><br>");
1049
1050        System.out.println("<p><br>&nbsp&nbsp&nbsp<A HREF=\"#node\">Node information</A><br>");
1051        System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#cpu_graph\">CPU usage graphs</A><br>");
1052        System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#procs_graph\">Processes usage graphs</A><br>");
1053        System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#mem_graph\">Memory usage graph</A><br>");
1054        System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#disk_graph\">Disk usage graphs</A><br>");
1055        System.out.println("&nbsp&nbsp&nbsp<A HREF=\"#net_graph\">Network usage graphs</A><br>");
1056
1057        System.out.println("<br><A NAME=\"node\"></A><h3>Node Information</h3><br>");
1058        for (int i = 0; i < client.rubis.getEJBServerNames().size(); i++)
1059        {
1060          System.out.println("<br><B>EJB server "+i+"</B><br>");
1061          client.printNodeInformation((String JavaDoc)client.rubis.getEJBServerNames().get(i));
1062        }
1063
1064       System.out.println("<br><A NAME=\"cpu_graph\"></A>");
1065        System.out.println("<br><h3>CPU Usage graphs</h3><p>");
1066        System.out.println("<IMG SRC=\"ejb_cpu_busy."+client.rubis.getGnuPlotTerminal()+"\">");
1067        System.out.println("<IMG SRC=\"ejb_cpu_idle."+client.rubis.getGnuPlotTerminal()+"\">");
1068        System.out.println("<IMG SRC=\"ejb_cpu_user_kernel."+client.rubis.getGnuPlotTerminal()+"\">");
1069
1070        System.out.println("<br><A NAME=\"procs_graph\"></A>");
1071        System.out.println("<br><h3>Processes Usage graphs</h3><p>");
1072        System.out.println("<IMG SRC=\"ejb_procs."+client.rubis.getGnuPlotTerminal()+"\">");
1073        System.out.println("<IMG SRC=\"ejb_ctxtsw."+client.rubis.getGnuPlotTerminal()+"\">");
1074
1075        System.out.println("<br><A NAME=\"mem_graph\"></A>");
1076        System.out.println("<br><h3>Memory Usage graphs</h3><p>");
1077        System.out.println("<IMG SRC=\"ejb_mem_usage."+client.rubis.getGnuPlotTerminal()+"\">");
1078        System.out.println("<IMG SRC=\"ejb_mem_cache."+client.rubis.getGnuPlotTerminal()+"\">");
1079
1080        System.out.println("<br><A NAME=\"disk_graph\"></A>");
1081        System.out.println("<br><h3>Disk Usage graphs</h3><p>");
1082        System.out.println("<IMG SRC=\"ejb_disk_rw_req."+client.rubis.getGnuPlotTerminal()+"\">");
1083        System.out.println("<IMG SRC=\"ejb_disk_tps."+client.rubis.getGnuPlotTerminal()+"\">");
1084
1085        System.out.println("<br><A NAME=\"net_graph\"></A>");
1086        System.out.println("<br><h3>Network Usage graphs</h3><p>");
1087        System.out.println("<IMG SRC=\"ejb_net_rt_byt."+client.rubis.getGnuPlotTerminal()+"\">");
1088        System.out.println("<IMG SRC=\"ejb_net_rt_pack."+client.rubis.getGnuPlotTerminal()+"\">");
1089        System.out.println("<IMG SRC=\"ejb_socks."+client.rubis.getGnuPlotTerminal()+"\">");
1090      }
1091
1092      try
1093      {
1094        PrintStream JavaDoc outputStream =
1095          new PrintStream JavaDoc(
1096            new FileOutputStream JavaDoc(reportDir + "stat_client0.html"));
1097        System.setOut(outputStream);
1098        System.setErr(outputStream);
1099        System.out.println(
1100          "<center><h2>*** Performance Report ***</h2></center><br>");
1101        System.out.println(
1102          "<A HREF=\"perf.html\">Overall performance report</A><br>");
1103        System.out.println(
1104          "<A HREF=\"stat_client0.html\">Main client (localhost) statistics</A><br>");
1105        for (int i = 0; i < client.rubis.getRemoteClients().size(); i++)
1106          System.out.println(
1107            "<A HREF=\"stat_client"
1108              + (i + 1)
1109              + ".html\">client1 ("
1110              + client.rubis.getRemoteClients().get(i)
1111              + ") statistics</A><br>");
1112              
1113        System.out.println("<A HREF=\"db_graphs.html\">Database graphs</A><br>");
1114          if (client.rubis.getServletsServerNames().size() > 0)
1115        System.out.println("<A HREF=\"servlets_graphs.html\">Servlets graphs</A><br>");
1116        if (client.rubis.getEJBServerNames().size() > 0)
1117          System.out.println("<A HREF=\"ejb_graphs.html\">EJB graphs</A><br>");
1118          
1119        System.out.println(
1120          "<p><br>&nbsp&nbsp&nbsp<A HREF=\"perf.html#node\">Node information</A><br>");
1121        System.out.println(
1122          "&nbsp&nbsp&nbsp<A HREF=\"#time\">Test timing information</A><br>");
1123        System.out.println(
1124          "&nbsp&nbsp&nbsp<A HREF=\"#up_stat\">Up ramp statistics</A><br>");
1125        System.out.println(
1126          "&nbsp&nbsp&nbsp<A HREF=\"#run_stat\">Runtime session statistics</A><br>");
1127        System.out.println(
1128          "&nbsp&nbsp&nbsp<A HREF=\"#down_stat\">Down ramp statistics</A><br>");
1129        System.out.println(
1130          "&nbsp&nbsp&nbsp<A HREF=\"#all_stat\">Overall statistics</A><br>");
1131        System.out.println(
1132          "&nbsp&nbsp&nbsp<A HREF=\"#cpu_graph\">CPU usage graphs</A><br>");
1133        System.out.println(
1134          "&nbsp&nbsp&nbsp<A HREF=\"#procs_graph\">Processes usage graphs</A><br>");
1135        System.out.println(
1136          "&nbsp&nbsp&nbsp<A HREF=\"#mem_graph\">Memory usage graph</A><br>");
1137        System.out.println(
1138          "&nbsp&nbsp&nbsp<A HREF=\"#disk_graph\">Disk usage graphs</A><br>");
1139        System.out.println(
1140          "&nbsp&nbsp&nbsp<A HREF=\"#net_graph\">Network usage graphs</A><br>");
1141      }
1142      catch (Exception JavaDoc ioe)
1143      {
1144        System.out.println(
1145          "An error occured while getting node information ("
1146            + ioe.getMessage()
1147            + ")");
1148      }
1149    }
1150
1151    // Test timing information
1152
System.out.println(
1153      "<br><p><A NAME=\"time\"></A><h3>Test timing information</h3><p>");
1154    System.out.println("<TABLE BORDER=1>");
1155    System.out.println(
1156      "<TR><TD><B>Test start</B><TD>" + TimeManagement.dateToString(startDate));
1157    System.out.println(
1158      "<TR><TD><B>Up ramp start</B><TD>"
1159        + TimeManagement.dateToString(upRampDate));
1160    System.out.println(
1161      "<TR><TD><B>Runtime session start</B><TD>"
1162        + TimeManagement.dateToString(runSessionDate));
1163    System.out.println(
1164      "<TR><TD><B>Down ramp start</B><TD>"
1165        + TimeManagement.dateToString(downRampDate));
1166    System.out.println(
1167      "<TR><TD><B>Test end</B><TD>" + TimeManagement.dateToString(endDate));
1168    System.out.println(
1169      "<TR><TD><B>Up ramp length</B><TD>"
1170        + TimeManagement.diffTime(upRampDate, runSessionDate)
1171        + " (requested "
1172        + client.rubis.getUpRampTime()
1173        + " ms)");
1174    System.out.println(
1175      "<TR><TD><B>Runtime session length</B><TD>"
1176        + TimeManagement.diffTime(runSessionDate, downRampDate)
1177        + " (requested "
1178        + client.rubis.getSessionTime()
1179        + " ms)");
1180    System.out.println(
1181      "<TR><TD><B>Down ramp length</B><TD>"
1182        + TimeManagement.diffTime(downRampDate, endDownRampDate)
1183        + " (requested "
1184        + client.rubis.getDownRampTime()
1185        + " ms)");
1186    System.out.println(
1187      "<TR><TD><B>Total test length</B><TD>"
1188        + TimeManagement.diffTime(startDate, endDate));
1189    System.out.println("</TABLE><p>");
1190
1191    // Stats for each ramp
1192
System.out.println("<br><A NAME=\"up_stat\"></A>");
1193    upRampStats.display_stats(
1194      "Up ramp",
1195      TimeManagement.diffTimeInMs(upRampDate, runSessionDate),
1196      false);
1197    System.out.println("<br><A NAME=\"run_stat\"></A>");
1198    runSessionStats.display_stats(
1199      "Runtime session",
1200      TimeManagement.diffTimeInMs(runSessionDate, downRampDate),
1201      false);
1202    System.out.println("<br><A NAME=\"down_stat\"></A>");
1203    downRampStats.display_stats(
1204      "Down ramp",
1205      TimeManagement.diffTimeInMs(downRampDate, endDownRampDate),
1206      false);
1207    System.out.println("<br><A NAME=\"all_stat\"></A>");
1208    allStats.display_stats(
1209      "Overall",
1210      TimeManagement.diffTimeInMs(upRampDate, endDownRampDate),
1211      false);
1212
1213    if (isMainClient)
1214    {
1215      
1216      try
1217      {
1218        // Wait for end of all monitors and remote clients
1219
for (int i = 0; i < client.rubis.getRemoteClients().size(); i++)
1220        {
1221         // The waitFor method only does not work: it hangs forever
1222
if (remoteClientMonitor[i].exitValue() != 0)
1223            {
1224                remoteClientMonitor[i].waitFor();
1225            }
1226            if (remoteClient[i].exitValue() != 0)
1227            {
1228               remoteClient[i].waitFor();
1229            }
1230          //remoteClientMonitor[i].waitFor();
1231
//remoteClient[i].waitFor();
1232
}
1233        if (webServerMonitor.exitValue() != 0)
1234        {
1235          webServerMonitor.waitFor();
1236        }
1237        if (cjdbcServerMonitor.exitValue() != 0)
1238        {
1239          cjdbcServerMonitor.waitFor();
1240        }
1241        for (int i = 0; i < dbServerMonitor.length; i++)
1242          dbServerMonitor[i].waitFor();
1243        if (servletsServerMonitor != null)
1244        {
1245          for (int i = 0; i < servletsServerMonitor.length; i++)
1246                  servletsServerMonitor[i].waitFor();
1247        }
1248        if (ejbServerMonitor != null)
1249        {
1250          for (int i = 0; i < ejbServerMonitor.length; i++)
1251                  ejbServerMonitor[i].waitFor();
1252        }
1253      }
1254      catch (Exception JavaDoc e)
1255      {
1256        System.out.println(
1257          "An error occured while waiting for remote processes termination ("
1258            + e.getMessage()
1259            + ")");
1260      }
1261
1262      // Time to transfer (scp all the files over)
1263
try
1264      {
1265        for (int i = 0; i < client.rubis.getRemoteClients().size(); i++)
1266        {
1267          client.getMonitoredData(
1268                        (String JavaDoc) client.rubis.getRemoteClients().get(i),
1269                        tmpDir + "client" + (i + 1),
1270                        reportDir);
1271        }
1272
1273        for (int i = 0; i < dbServerMonitor.length; i++)
1274        {
1275             client.getMonitoredData((String JavaDoc)client.rubis.getDBServerNames().get(i),
1276                                  tmpDir+"db_server"+i,
1277                                  reportDir);
1278        }
1279
1280        // Web server
1281
client.getMonitoredData(client.rubis.getWebServerName(),
1282                                tmpDir + "web_server",
1283                                reportDir);
1284
1285        // Local client
1286
client.getMonitoredData("localhost",
1287                                tmpDir + "client0",
1288                                reportDir);
1289
1290        // C-JDBC server
1291
if (cjdbcFlag)
1292        {
1293          client.getMonitoredData(client.rubis.getCJDBCServerName(),
1294                                  tmpDir + "cjdbc_server",
1295                                  reportDir);
1296        }
1297      
1298        if (servletsServerMonitor != null)
1299        {
1300          for (int i = 0; i < servletsServerMonitor.length; i++)
1301              client.getMonitoredData((String JavaDoc)client.rubis.getServletsServerNames().get(i),
1302                                      tmpDir+"servlets_server"+i,
1303                                      reportDir);
1304        }
1305        if (ejbServerMonitor != null)
1306        {
1307          for (int i = 0; i < ejbServerMonitor.length; i++)
1308            client.getMonitoredData((String JavaDoc)client.rubis.getEJBServerNames().get(i),
1309                                    tmpDir+"ejb_server"+i,
1310                                    reportDir);
1311        }
1312        // Now transfer the remote client html files
1313
for (int i = 0; i < client.rubis.getRemoteClients().size(); i++)
1314        {
1315          client.getHTMLData((String JavaDoc) client.rubis.getRemoteClients().get(i),
1316                                  tmpDir + "trace_client" + (i + 1) + ".html ",
1317                                  reportDir);
1318          client.getHTMLData((String JavaDoc) client.rubis.getRemoteClients().get(i),
1319                                  tmpDir + "stat_client" + (i + 1) + ".html ",
1320                                  reportDir);
1321        }
1322      }
1323      catch (Exception JavaDoc e)
1324      {
1325          System.out.println(
1326                             "An error occured while transferring log files ("
1327                             + e.getMessage()
1328                             + ")");
1329      }
1330
1331      // Generate the graphics
1332
try
1333      {
1334        String JavaDoc[] cmd = null;
1335        if (client.rubis.getEJBServerNames().size() > 0)
1336        {
1337          cmd = new String JavaDoc[7];
1338          cmd[0] = "bench/ejb_generate_graphs.sh";
1339        }
1340        else if (client.rubis.getServletsServerNames().size() > 0)
1341        {
1342          cmd = new String JavaDoc[6];
1343          cmd[0] = "bench/servlets_generate_graphs.sh";
1344        }
1345        else
1346        {
1347          cmd = new String JavaDoc[5];
1348          cmd[0] = "bench/generate_graphs.sh";
1349        }
1350        cmd[1] = reportDir;
1351        cmd[2] = client.rubis.getGnuPlotTerminal();
1352        cmd[3] = Integer.toString(client.rubis.getRemoteClients().size() + 1);
1353        cmd[4] = Integer.toString(client.rubis.getDBServerNames().size());
1354        if (client.rubis.getServletsServerNames().size() > 0)
1355          cmd[5] = Integer.toString(client.rubis.getServletsServerNames().size());
1356        if (client.rubis.getEJBServerNames().size() > 0)
1357          cmd[6] = Integer.toString(client.rubis.getEJBServerNames().size());
1358        Process JavaDoc graph = Runtime.getRuntime().exec(cmd);
1359        // Need to read input so program does not stall.
1360
BufferedReader JavaDoc read = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(graph.getInputStream()));
1361        String JavaDoc msg;
1362        while ((msg = read.readLine()) != null) {
1363      // System.out.println(msg+"<br>");
1364
}
1365        read.close();
1366        graph.waitFor();
1367      }
1368      catch (Exception JavaDoc e)
1369      {
1370        System.out.println(
1371          "An error occured while generating the graphs ("
1372            + e.getMessage()
1373            + ")");
1374      }
1375    }
1376
1377    System.out.println("<br><A NAME=\"cpu_graph\"></A>");
1378    System.out.println("<br><h3>CPU Usage graphs</h3><p>");
1379    System.out.println("<TABLE>");
1380    System.out.println(
1381      "<TR><TD><IMG SRC=\"cpu_busy."
1382        + client.rubis.getGnuPlotTerminal()
1383        + "\"><TD><IMG SRC=\"client_cpu_busy."
1384        + client.rubis.getGnuPlotTerminal()
1385        + "\">");
1386    if (cjdbcFlag)
1387    {
1388      System.out.println(
1389        "<TR><TD><IMG SRC=\"cjdbc_server_cpu_busy."
1390          + client.rubis.getGnuPlotTerminal()
1391          + "\">");
1392    }
1393    System.out.println(
1394      "<TR><TD><IMG SRC=\"cpu_idle."
1395        + client.rubis.getGnuPlotTerminal()
1396        + "\"><TD><IMG SRC=\"client_cpu_idle."
1397        + client.rubis.getGnuPlotTerminal()
1398        + "\">");
1399    if (cjdbcFlag)
1400    {
1401      System.out.println(
1402        "<TR><TD><IMG SRC=\"cjdbc_server_cpu_idle."
1403          + client.rubis.getGnuPlotTerminal()
1404          + "\">");
1405    }
1406    System.out.println(
1407      "<TR><TD><IMG SRC=\"cpu_user_kernel."
1408        + client.rubis.getGnuPlotTerminal()
1409        + "\"><TD><IMG SRC=\"client_cpu_user_kernel."
1410        + client.rubis.getGnuPlotTerminal()
1411        + "\">");
1412    if (cjdbcFlag)
1413    {
1414      System.out.println(
1415        "<TR><TD><IMG SRC=\"cjdbc_server_cpu_user_kernel."
1416          + client.rubis.getGnuPlotTerminal()
1417          + "\">");
1418    }
1419    System.out.println("</TABLE><p>");
1420
1421    System.out.println("<br><A NAME=\"procs_graph\"></A>");
1422    System.out.println("<TABLE>");
1423    System.out.println("<br><h3>Processes Usage graphs</h3><p>");
1424    System.out.println(
1425      "<TR><TD><IMG SRC=\"procs."
1426        + client.rubis.getGnuPlotTerminal()
1427        + "\"><TD><IMG SRC=\"client_procs."
1428        + client.rubis.getGnuPlotTerminal()
1429        + "\">");
1430    if (cjdbcFlag)
1431    {
1432      System.out.println(
1433        "<TR><TD><IMG SRC=\"cjdbc_server_procs."
1434          + client.rubis.getGnuPlotTerminal()
1435          + "\">");
1436    }
1437    System.out.println(
1438      "<TR><TD><IMG SRC=\"ctxtsw."
1439        + client.rubis.getGnuPlotTerminal()
1440        + "\"><TD><IMG SRC=\"client_ctxtsw."
1441        + client.rubis.getGnuPlotTerminal()
1442        + "\">");
1443    if (cjdbcFlag)
1444    {
1445      System.out.println(
1446        "<TR><TD><IMG SRC=\"cjdbc_server_ctxtsw."
1447          + client.rubis.getGnuPlotTerminal()
1448          + "\">");
1449    }
1450    System.out.println("</TABLE><p>");
1451
1452    System.out.println("<br><A NAME=\"mem_graph\"></A>");
1453    System.out.println("<br><h3>Memory Usage graph</h3><p>");
1454    System.out.println("<TABLE>");
1455    System.out.println(
1456      "<TR><TD><IMG SRC=\"mem_usage."
1457        + client.rubis.getGnuPlotTerminal()
1458        + "\"><TD><IMG SRC=\"client_mem_usage."
1459        + client.rubis.getGnuPlotTerminal()
1460        + "\">");
1461    if (cjdbcFlag)
1462    {
1463      System.out.println(
1464        "<TR><TD><IMG SRC=\"cjdbc_server_mem_usage."
1465          + client.rubis.getGnuPlotTerminal()
1466          + "\">");
1467    }
1468    System.out.println(
1469      "<TR><TD><IMG SRC=\"mem_cache."
1470        + client.rubis.getGnuPlotTerminal()
1471        + "\"><TD><IMG SRC=\"client_mem_cache."
1472        + client.rubis.getGnuPlotTerminal()
1473        + "\">");
1474    if (cjdbcFlag)
1475    {
1476      System.out.println(
1477        "<TR><TD><IMG SRC=\"cjdbc_server_mem_cache."
1478          + client.rubis.getGnuPlotTerminal()
1479          + "\">");
1480    }
1481    System.out.println("</TABLE><p>");
1482
1483    System.out.println("<br><A NAME=\"disk_graph\"></A>");
1484    System.out.println("<br><h3>Disk Usage graphs</h3><p>");
1485    System.out.println("<TABLE>");
1486    System.out.println(
1487      "<TR><TD><IMG SRC=\"disk_rw_req."
1488        + client.rubis.getGnuPlotTerminal()
1489        + "\"><TD><IMG SRC=\"client_disk_rw_req."
1490        + client.rubis.getGnuPlotTerminal()
1491        + "\">");
1492    if (cjdbcFlag)
1493    {
1494      System.out.println(
1495        "<TR><TD><IMG SRC=\"cjdbc_server_disk_rw_req."
1496          + client.rubis.getGnuPlotTerminal()
1497          + "\">");
1498    }
1499    System.out.println(
1500      "<TR><TD><IMG SRC=\"disk_tps."
1501        + client.rubis.getGnuPlotTerminal()
1502        + "\"><TD><IMG SRC=\"client_disk_tps."
1503        + client.rubis.getGnuPlotTerminal()
1504        + "\">");
1505    if (cjdbcFlag)
1506    {
1507      System.out.println(
1508        "<TR><TD><IMG SRC=\"cjdbc_server_disk_tps."
1509          + client.rubis.getGnuPlotTerminal()
1510          + "\">");
1511    }
1512    System.out.println("</TABLE><p>");
1513
1514    System.out.println("<br><A NAME=\"net_graph\"></A>");
1515    System.out.println("<br><h3>Network Usage graphs</h3><p>");
1516    System.out.println("<TABLE>");
1517    System.out.println(
1518      "<TR><TD><IMG SRC=\"net_rt_byt."
1519        + client.rubis.getGnuPlotTerminal()
1520        + "\"><TD><IMG SRC=\"client_net_rt_byt."
1521        + client.rubis.getGnuPlotTerminal()
1522        + "\">");
1523    if (cjdbcFlag)
1524    {
1525      System.out.println(
1526        "<TR><TD><IMG SRC=\"cjdbc_server_net_rt_byt."
1527          + client.rubis.getGnuPlotTerminal()
1528          + "\">");
1529    }
1530    System.out.println(
1531      "<TR><TD><IMG SRC=\"net_rt_pack."
1532        + client.rubis.getGnuPlotTerminal()
1533        + "\"><TD><IMG SRC=\"client_net_rt_pack."
1534        + client.rubis.getGnuPlotTerminal()
1535        + "\">");
1536    if (cjdbcFlag)
1537    {
1538      System.out.println(
1539        "<TR><TD><IMG SRC=\"cjdbc_server_net_rt_pack."
1540          + client.rubis.getGnuPlotTerminal()
1541          + "\">");
1542    }
1543    System.out.println(
1544      "<TR><TD><IMG SRC=\"socks."
1545        + client.rubis.getGnuPlotTerminal()
1546        + "\"><TD><IMG SRC=\"client_socks."
1547        + client.rubis.getGnuPlotTerminal()
1548        + "\">");
1549    if (cjdbcFlag)
1550    {
1551      System.out.println(
1552        "<TR><TD><IMG SRC=\"cjdbc_server_socks."
1553          + client.rubis.getGnuPlotTerminal()
1554          + "\">");
1555    }
1556    System.out.println("</TABLE><p>");
1557
1558    if (isMainClient)
1559    {
1560      // Compute the global stats
1561
try
1562      {
1563        String JavaDoc[] cmd = new String JavaDoc[6];
1564        cmd[0] = "bench/compute_global_stats.awk";
1565        cmd[1] = "-v";
1566        cmd[2] = "path=" + reportDir;
1567        cmd[3] = "-v";
1568        cmd[4] =
1569          "nbscript="
1570            + Integer.toString(client.rubis.getRemoteClients().size() + 1);
1571        cmd[5] = reportDir + "stat_client0.html";
1572        Process JavaDoc computeStats = Runtime.getRuntime().exec(cmd);
1573        computeStats.waitFor();
1574      }
1575      catch (Exception JavaDoc e)
1576      {
1577        System.out.println(
1578          "An error occured while generating the graphs ("
1579            + e.getMessage()
1580            + ")");
1581      }
1582    }
1583
1584    Runtime.getRuntime().exit(0);
1585  }
1586
1587}
1588
Popular Tags