1 package edu.rice.rubbos.client; 2 3 import edu.rice.rubbos.beans.TimeManagement; 4 import java.io.BufferedReader ; 5 import java.io.InputStreamReader ; 6 import java.io.IOException ; 7 import java.io.File ; 8 import java.io.FileOutputStream ; 9 import java.io.PrintStream ; 10 import java.lang.Runtime ; 11 import java.net.URL ; 12 import java.util.GregorianCalendar ; 13 import java.util.Random ; 14 import java.util.Vector ; 15 16 23 public class ClientEmulator 24 { 25 private RUBBoSProperties rubbos = null; private URLGenerator urlGen = null; private static float slowdownFactor = 0; 28 private static boolean endOfSimulation = false; 29 30 34 public ClientEmulator() 35 { 36 rubbos = new RUBBoSProperties(); 38 urlGen = rubbos.checkPropertiesFileAndGetURLGenerator(); 39 if (urlGen == null) 40 Runtime.getRuntime().exit(1); 41 TransitionTable transition = new TransitionTable(rubbos.getNbOfColumns(), rubbos.getNbOfRows(), null, rubbos.useTPCWThinkTime()); 43 if (!transition.ReadExcelTextFile(rubbos.getUserTransitionTable())) 44 Runtime.getRuntime().exit(1); 45 else 46 transition.displayMatrix("User"); 47 if (!transition.ReadExcelTextFile(rubbos.getAuthorTransitionTable())) 48 Runtime.getRuntime().exit(1); 49 else 50 transition.displayMatrix("Author"); 51 } 52 53 54 59 private synchronized void setSlowDownFactor(float newValue) 60 { 61 slowdownFactor = newValue; 62 } 63 64 65 68 public static synchronized float getSlowDownFactor() 69 { 70 return slowdownFactor; 71 } 72 73 74 77 private synchronized void setEndOfSimulation() 78 { 79 endOfSimulation = true; 80 } 81 82 83 86 public static synchronized boolean isEndOfSimulation() 87 { 88 return endOfSimulation; 89 } 90 91 92 98 public static void main(String [] args) 99 { 100 GregorianCalendar startDate; 101 GregorianCalendar endDate; 102 GregorianCalendar upRampDate; 103 GregorianCalendar runSessionDate; 104 GregorianCalendar downRampDate; 105 GregorianCalendar endDownRampDate; 106 Process webServerMonitor = null; 107 Process cjdbcServerMonitor = null; 108 Process dbServerMonitor = null; 109 Process clientMonitor = null; 110 Process [] remoteClientMonitor = null; 111 Process [] remoteClient = null; 112 String reportDir = ""; 113 String tmpDir = "/tmp/"; 114 boolean isMainClient = args.length == 0; 116 if (isMainClient) 117 { 118 System.out.println("RUBBoS client emulator - (C) Rice University/INRIA 2001\n"); 120 reportDir = "bench/"+TimeManagement.currentDateToString()+"/"; 121 reportDir = reportDir.replace(' ', '@'); 122 try 123 { 124 System.out.println("Creating report directory "+reportDir); 125 File dir = new File (reportDir); 126 dir.mkdirs(); 127 if (!dir.isDirectory()) 128 { 129 System.out.println("Unable to create "+reportDir+" using current directory instead"); 130 reportDir = "./"; 131 } 132 else 133 reportDir = dir.getCanonicalPath()+"/"; 134 System.out.println("Redirecting output to '"+reportDir+"index.html'"); 135 PrintStream outputStream = new PrintStream (new FileOutputStream (reportDir+"index.html")); 136 System.out.println("Please wait while experiment is running ..."); 137 System.setOut(outputStream); 138 System.setErr(outputStream); 139 } 140 catch (Exception e) 141 { 142 System.out.println("Output redirection failed, displaying results on standard output ("+e.getMessage()+")"); 143 } 144 System.out.println("<h2>RUBBoS client emulator - (C) Rice University/INRIA 2001</h2><p>\n"); 145 startDate = new GregorianCalendar (); 146 System.out.println("<h3>Test date: "+TimeManagement.dateToString(startDate)+"</h3><br>\n"); 147 148 System.out.println("<A HREF=\"#config\">Test configuration</A><br>"); 149 System.out.println("<A HREF=\"trace_client0.html\">Test trace</A><br>"); 150 System.out.println("<A HREF=\"perf.html\">Test performance report</A><br><p>"); 151 System.out.println("<p><hr><p>"); 152 153 System.out.println("<CENTER><A NAME=\"config\"></A><h2>*** Test configuration ***</h2></CENTER>"); 154 } 155 else 156 { 157 System.out.println("RUBBoS remote client emulator - (C) Rice University/INRIA 2001\n"); 158 startDate = new GregorianCalendar (); 159 } 160 161 ClientEmulator client = new ClientEmulator(); 163 Stats stats = new Stats(client.rubbos.getNbOfRows()); 164 Stats upRampStats = new Stats(client.rubbos.getNbOfRows()); 165 Stats runSessionStats = new Stats(client.rubbos.getNbOfRows()); 166 Stats downRampStats = new Stats(client.rubbos.getNbOfRows()); 167 Stats allStats = new Stats(client.rubbos.getNbOfRows()); 168 UserSession[] sessions = new UserSession[client.rubbos.getNbOfClients()]; 169 170 System.out.println("<p><hr><p>"); 171 172 if (isMainClient) 173 { 174 System.out.println("Total number of clients for this experiment: "+(client.rubbos.getNbOfClients()*(client.rubbos.getRemoteClients().size()+1))+"<br>"); 176 remoteClient = new Process [client.rubbos.getRemoteClients().size()]; 177 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 178 { 179 try 180 { 181 System.out.println("ClientEmulator: Starting remote client on "+client.rubbos.getRemoteClients().get(i)+"<br>\n"); 182 String [] rcmdClient = new String [4]; 183 rcmdClient[0] = client.rubbos.getMonitoringRsh(); 184 rcmdClient[1] = "-x"; 185 rcmdClient[2] = (String )client.rubbos.getRemoteClients().get(i); 186 rcmdClient[3] = client.rubbos.getClientsRemoteCommand()+" "+tmpDir+"trace_client"+(i+1)+".html "+tmpDir+"stat_client"+(i+1)+".html"; 187 remoteClient[i] = Runtime.getRuntime().exec(rcmdClient); 188 System.out.println("    Command is: "+rcmdClient[0]+" "+rcmdClient[1]+" "+rcmdClient[2]+" "+rcmdClient[3]+"<br>\n"); 189 } 190 catch (IOException ioe) 191 { 192 System.out.println("An error occured while executing remote client ("+ioe.getMessage()+")"); 193 } 194 } 195 196 System.out.println("<CENTER></A><A NAME=\"trace\"><h2>*** Monitoring ***</h2></CENTER>"); 198 try 199 { 200 201 try 204 { 205 String [] delFiles = new String [4]; 206 Process delProcess; 207 delFiles[0] = client.rubbos.getMonitoringRsh(); 208 delFiles[1] = "-x"; 209 delFiles[2] = client.rubbos.getWebServerName(); 211 delFiles[3] = "rm -f "+tmpDir+"web_server"; 212 System.out.println("    Command is: "+delFiles[0]+" "+delFiles[1]+" "+delFiles[2]+" "+delFiles[3]+"<br>\n"); 213 delProcess = Runtime.getRuntime().exec(delFiles); 214 delProcess.waitFor(); 215 if(client.rubbos.getCJDBCServerName() != null 217 && !client.rubbos.getCJDBCServerName().equals("")) 218 { 219 delFiles[2] = client.rubbos.getCJDBCServerName(); 220 delFiles[3] = "rm -f "+tmpDir+"cjdbc_server"; 221 System.out.println("    Command is: "+delFiles[0]+" "+delFiles[1]+" "+delFiles[2]+" "+delFiles[3]+"<br>\n"); 222 delProcess = Runtime.getRuntime().exec(delFiles); 223 delProcess.waitFor(); 224 } 225 delFiles[2] = client.rubbos.getDBServerName(); 227 delFiles[3] = "rm -f "+tmpDir+"db_server"; 228 System.out.println("    Command is: "+delFiles[0]+" "+delFiles[1]+" "+delFiles[2]+" "+delFiles[3]+"<br>\n"); 229 delProcess = Runtime.getRuntime().exec(delFiles); 230 delProcess.waitFor(); 231 delFiles[2] = "localhost"; 233 delFiles[3] = "rm -f "+tmpDir+"client0"; 234 System.out.println("    Command is: "+delFiles[0]+" "+delFiles[1]+" "+delFiles[2]+" "+delFiles[3]+"<br>\n"); 235 delProcess = Runtime.getRuntime().exec(delFiles); 236 delProcess.waitFor(); 237 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 239 { 240 delFiles[2] = (String )client.rubbos.getRemoteClients().get(i); 241 delFiles[3] = "rm -f "+tmpDir+"client"+(i+1); 242 System.out.println("    Command is: "+delFiles[0]+" "+delFiles[1]+" "+delFiles[2]+" "+delFiles[3]+"<br>\n"); 243 delProcess = Runtime.getRuntime().exec(delFiles); 244 delProcess.waitFor(); 245 } 246 } 247 catch(java.lang.InterruptedException ie) 248 { 249 ie.printStackTrace(); 250 } 251 System.out.println("    Finished deleting old files<br>\n"); 252 253 int fullTimeInSec = (client.rubbos.getUpRampTime()+client.rubbos.getSessionTime()+client.rubbos.getDownRampTime())/1000 + 5; System.out.println("ClientEmulator: Starting monitoring program on Web server "+client.rubbos.getWebServerName()+"<br>\n"); 256 String [] cmdWeb = new String [6]; 257 cmdWeb[0] = client.rubbos.getMonitoringRsh(); 258 cmdWeb[1] = "-x"; 259 cmdWeb[2] = client.rubbos.getWebServerName(); 260 cmdWeb[3] = "/bin/bash"; 261 cmdWeb[4] = "-c"; 262 cmdWeb[5] = "'LANG=en_GB.UTF-8 "+client.rubbos.getMonitoringProgram()+" "+client.rubbos.getMonitoringOptions()+" "+ 263 client.rubbos.getMonitoringSampling()+" "+fullTimeInSec+" -o "+tmpDir+"web_server'"; 264 webServerMonitor = Runtime.getRuntime().exec(cmdWeb); 265 System.out.println("    Command is: "+cmdWeb[0]+" "+cmdWeb[1]+" "+cmdWeb[2]+" "+cmdWeb[3]+" "+cmdWeb[4]+" "+cmdWeb[5]+"<br>\n"); 266 267 if(client.rubbos.getCJDBCServerName() != null 269 && !client.rubbos.getCJDBCServerName().equals("")) { 270 System.out.println("ClientEmulator: Starting monitoring program on CJDBC server "+client.rubbos.getCJDBCServerName()+"<br>\n"); 271 cmdWeb[0] = client.rubbos.getMonitoringRsh(); 272 cmdWeb[1] = "-x"; 273 cmdWeb[2] = client.rubbos.getCJDBCServerName(); 274 cmdWeb[3] = "/bin/bash"; 275 cmdWeb[4] = "-c"; 276 cmdWeb[5] = "'LANG=en_GB.UTF-8 "+client.rubbos.getMonitoringProgram()+" "+client.rubbos.getMonitoringOptions()+" "+ 277 client.rubbos.getMonitoringSampling()+" "+fullTimeInSec+" -o "+tmpDir+"cjdbc_server'"; 278 cjdbcServerMonitor = Runtime.getRuntime().exec(cmdWeb); 279 System.out.println("    Command is: "+cmdWeb[0]+" "+cmdWeb[1]+" "+cmdWeb[2]+" "+cmdWeb[3]+" "+cmdWeb[4]+" "+cmdWeb[5]+"<br>\n"); 280 } 281 282 System.out.println("ClientEmulator: Starting monitoring program on Database server "+client.rubbos.getDBServerName()+"<br>\n"); 284 String [] cmdDB = new String [6]; 285 cmdDB[0] = client.rubbos.getMonitoringRsh(); 286 cmdDB[1] = "-x"; 287 cmdDB[2] = client.rubbos.getDBServerName(); 288 cmdDB[3] = "/bin/bash"; 289 cmdDB[4] = "-c"; 290 cmdDB[5] = "'LANG=en_GB.UTF-8 "+client.rubbos.getMonitoringProgram()+" "+client.rubbos.getMonitoringOptions()+" "+ 291 client.rubbos.getMonitoringSampling()+" "+fullTimeInSec+" -o "+tmpDir+"db_server'"; 292 dbServerMonitor = Runtime.getRuntime().exec(cmdDB); 293 System.out.println("    Command is: "+cmdDB[0]+" "+cmdDB[1]+" "+cmdDB[2]+" "+cmdDB[3]+" "+cmdDB[4]+" "+cmdDB[5]+"<br>\n"); 294 295 System.out.println("ClientEmulator: Starting monitoring program locally on client<br>\n"); 297 String [] cmdClient = new String [6]; 298 cmdClient[0] = client.rubbos.getMonitoringRsh(); 299 cmdClient[1] = "-x"; 300 cmdClient[2] = "localhost"; 301 cmdClient[3] = "/bin/bash"; 302 cmdClient[4] = "-c"; 303 cmdClient[5] = "'LANG=en_GB.UTF-8 "+client.rubbos.getMonitoringProgram()+" "+client.rubbos.getMonitoringOptions()+" "+ 304 client.rubbos.getMonitoringSampling()+" "+fullTimeInSec+" -o "+reportDir+"client0'"; 305 clientMonitor = Runtime.getRuntime().exec(cmdClient); 306 System.out.println("    Command is: "+cmdClient[0]+" "+cmdClient[1]+" "+cmdClient[2]+" "+cmdClient[3]+" "+cmdClient[4]+" "+cmdClient[5]+"<br>\n"); 307 308 remoteClientMonitor = new Process [client.rubbos.getRemoteClients().size()]; 309 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 311 { 312 System.out.println("ClientEmulator: Starting monitoring program locally on client<br>\n"); 313 String [] rcmdClient = new String [6]; 314 rcmdClient[0] = client.rubbos.getMonitoringRsh(); 315 rcmdClient[1] = "-x"; 316 rcmdClient[2] = (String )client.rubbos.getRemoteClients().get(i); 317 rcmdClient[3] = "/bin/bash"; 318 rcmdClient[4] = "-c"; 319 rcmdClient[5] = "'LANG=en_GB.UTF-8 "+client.rubbos.getMonitoringProgram()+" "+client.rubbos.getMonitoringOptions()+" "+ 320 client.rubbos.getMonitoringSampling()+" "+fullTimeInSec+" -o "+tmpDir+"client"+(i+1)+"'"; 321 remoteClientMonitor[i] = Runtime.getRuntime().exec(rcmdClient); 322 System.out.println("    Command is: "+rcmdClient[0]+" "+rcmdClient[1]+" "+rcmdClient[2]+" "+rcmdClient[3]+" "+rcmdClient[4]+" "+rcmdClient[5]+"<br>\n"); 323 } 324 325 PrintStream outputStream = new PrintStream (new FileOutputStream (reportDir+"trace_client0.html")); 327 System.setOut(outputStream); 328 System.setErr(outputStream); 329 } 330 catch (IOException ioe) 331 { 332 System.out.println("An error occured while executing monitoring program ("+ioe.getMessage()+")"); 333 } 334 } 335 else 336 { System.out.println("Redirecting output to '"+args[0]+"'"); 338 try 339 { 340 PrintStream outputStream = new PrintStream (new FileOutputStream (args[0])); 341 System.out.println("Please wait while experiment is running ..."); 342 System.setOut(outputStream); 343 System.setErr(outputStream); 344 } 345 catch (Exception e) 346 { 347 System.out.println("Output redirection failed, displaying results on standard output ("+e.getMessage()+")"); 348 } 349 startDate = new GregorianCalendar (); 350 } 351 352 353 357 System.out.println("<CENTER></A><A NAME=\"trace\"><h2>*** Test trace ***</h2></CENTER><p>"); 358 System.out.println("<A HREF=\"trace_client0.html\">Main client traces</A><br>"); 359 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 360 System.out.println("<A HREF=\"trace_client"+(i+1)+".html\">client1 ("+client.rubbos.getRemoteClients().get(i)+") traces</A><br>"); 361 System.out.println("<br><p>"); 362 System.out.println("   <A HREF=\"#up\">Up ramp trace</A><br>"); 363 System.out.println("   <A HREF=\"#run\">Runtime session trace</A><br>"); 364 System.out.println("   <A HREF=\"#down\">Down ramp trace</A><br><p><p>"); 365 366 System.out.println("ClientEmulator: Starting "+client.rubbos.getNbOfClients()+" session threads<br>"); 368 Random rand = new Random (); for (int i = 0 ; i < client.rubbos.getNbOfClients() ; i++) 370 { 371 if (rand.nextInt(100) < client.rubbos.getPercentageOfAuthors()) 372 sessions[i] = new UserSession("AuthorSession"+i, client.urlGen, client.rubbos, stats, true); 373 else 374 sessions[i] = new UserSession("UserSession"+i, client.urlGen, client.rubbos, stats, false); 375 sessions[i].start(); 376 } 377 378 System.out.println("<br><A NAME=\"up\"></A>"); 380 System.out.println("<h3>ClientEmulator: Switching to ** UP RAMP **</h3><br><p>"); 381 client.setSlowDownFactor(client.rubbos.getUpRampSlowdown()); 382 upRampDate = new GregorianCalendar (); 383 try 384 { 385 Thread.currentThread().sleep(client.rubbos.getUpRampTime()); 386 } 387 catch (java.lang.InterruptedException ie) 388 { 389 System.err.println("ClientEmulator has been interrupted."); 390 } 391 upRampStats.merge(stats); 392 stats.reset(); 394 System.out.println("<br><A NAME=\"run\"></A>"); 396 System.out.println("<h3>ClientEmulator: Switching to ** RUNTIME SESSION **</h3><br><p>"); 397 client.setSlowDownFactor(1); 398 runSessionDate = new GregorianCalendar (); 399 try 400 { 401 Thread.currentThread().sleep(client.rubbos.getSessionTime()); 402 } 403 catch (java.lang.InterruptedException ie) 404 { 405 System.err.println("ClientEmulator has been interrupted."); 406 } 407 runSessionStats.merge(stats); 408 stats.reset(); 410 System.out.println("<br><A NAME=\"down\"></A>"); 412 System.out.println("<h3>ClientEmulator: Switching to ** DOWN RAMP **</h3><br><p>"); 413 client.setSlowDownFactor(client.rubbos.getDownRampSlowdown()); 414 downRampDate = new GregorianCalendar (); 415 try 416 { 417 Thread.currentThread().sleep(client.rubbos.getDownRampTime()); 418 } 419 catch (java.lang.InterruptedException ie) 420 { 421 System.err.println("ClientEmulator has been interrupted."); 422 } 423 downRampStats.merge(stats); 424 endDownRampDate = new GregorianCalendar (); 425 426 client.setEndOfSimulation(); 428 System.out.println("ClientEmulator: Shutting down threads ...<br>"); 429 for (int i = 0 ; i < client.rubbos.getNbOfClients() ; i++) 430 { 431 try 432 { 433 sessions[i].join(2000); 434 } 435 catch (java.lang.InterruptedException ie) 436 { 437 System.err.println("ClientEmulator: Thread "+i+" has been interrupted."); 438 } 439 } 440 System.out.println("Done\n"); 441 endDate = new GregorianCalendar (); 442 allStats.merge(stats); 443 allStats.merge(runSessionStats); 444 allStats.merge(upRampStats); 445 System.out.println("<p><hr><p>"); 446 447 448 452 try 455 { 456 PrintStream outputStream; 457 if (isMainClient) 458 outputStream = new PrintStream (new FileOutputStream (reportDir+"perf.html")); 459 else 460 outputStream = new PrintStream (new FileOutputStream (args[1])); 461 System.setOut(outputStream); 462 System.setErr(outputStream); 463 } 464 catch (Exception e) 465 { 466 System.out.println("Output redirection failed, displaying results on standard output ("+e.getMessage()+")"); 467 } 468 469 System.out.println("<center><h2>*** Performance Report ***</h2></center><br>"); 470 System.out.println("<A HREF=\"perf.html\">Overall performance report</A><br>"); 471 System.out.println("<A HREF=\"stat_client0.html\">Main client (localhost) statistics</A><br>"); 472 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 473 System.out.println("<A HREF=\"stat_client"+(i+1)+".html\">client1 ("+client.rubbos.getRemoteClients().get(i)+") statistics</A><br>"); 474 475 System.out.println("<p><br>   <A HREF=\"perf.html#node\">Node information</A><br>"); 476 System.out.println("   <A HREF=\"#time\">Test timing information</A><br>"); 477 System.out.println("   <A HREF=\"#up_stat\">Up ramp statistics</A><br>"); 478 System.out.println("   <A HREF=\"#run_stat\">Runtime session statistics</A><br>"); 479 System.out.println("   <A HREF=\"#down_stat\">Down ramp statistics</A><br>"); 480 System.out.println("   <A HREF=\"#all_stat\">Overall statistics</A><br>"); 481 System.out.println("   <A HREF=\"#cpu_graph\">CPU usage graphs</A><br>"); 482 System.out.println("   <A HREF=\"#procs_graph\">Processes usage graphs</A><br>"); 483 System.out.println("   <A HREF=\"#mem_graph\">Memory usage graph</A><br>"); 484 System.out.println("   <A HREF=\"#disk_graph\">Disk usage graphs</A><br>"); 485 System.out.println("   <A HREF=\"#net_graph\">Network usage graphs</A><br>"); 486 487 if (isMainClient) 488 { 489 System.out.println("<br><A NAME=\"node\"></A><h3>Node Information</h3><br>"); 491 try 492 { 493 File dir = new File ("."); 494 String nodeInfoProgram = "/bin/echo \"Host : \"`/bin/hostname` ; " + 495 "/bin/echo \"Kernel: \"`/bin/cat /proc/version` ; " + 496 "/bin/grep net /proc/pci ; " + 497 "/bin/grep processor /proc/cpuinfo ; " + 498 "/bin/grep vendor_id /proc/cpuinfo ; " + 499 "/bin/grep model /proc/cpuinfo ; " + 500 "/bin/grep MHz /proc/cpuinfo ; " + 501 "/bin/grep cache /proc/cpuinfo ; " + 502 "/bin/grep MemTotal /proc/meminfo ; " + 503 "/bin/grep SwapTotal /proc/meminfo "; 504 505 506 System.out.println("<B>Web server</B><br>"); 508 String [] cmdWeb = new String [3]; 509 cmdWeb[0] = client.rubbos.getMonitoringRsh(); 510 cmdWeb[1] = client.rubbos.getWebServerName(); 511 cmdWeb[2] = nodeInfoProgram; 512 Process p = Runtime.getRuntime().exec(cmdWeb); 513 BufferedReader read = new BufferedReader (new InputStreamReader (p.getInputStream())); 514 String msg; 515 while ((msg = read.readLine()) != null) 516 System.out.println(msg+"<br>"); 517 read.close(); 518 519 if(client.rubbos.getCJDBCServerName() != null 521 && !client.rubbos.getCJDBCServerName().equals("")) { 522 System.out.println("<br><B>CJDBC server</B><br>"); 523 cmdWeb[0] = client.rubbos.getMonitoringRsh(); 524 cmdWeb[1] = client.rubbos.getCJDBCServerName(); 525 cmdWeb[2] = nodeInfoProgram; 526 p = Runtime.getRuntime().exec(cmdWeb); 527 read = new BufferedReader (new InputStreamReader (p.getInputStream())); 528 while ((msg = read.readLine()) != null) 529 System.out.println(msg+"<br>"); 530 read.close(); 531 } 532 533 534 System.out.println("<br><B>Database server</B><br>"); 536 String [] cmdDB = new String [3]; 537 cmdDB[0] = client.rubbos.getMonitoringRsh(); 538 cmdDB[1] = client.rubbos.getDBServerName(); 539 cmdDB[2] =nodeInfoProgram; 540 p = Runtime.getRuntime().exec(cmdDB); 541 read = new BufferedReader (new InputStreamReader (p.getInputStream())); 542 while ((msg = read.readLine()) != null) 543 System.out.println(msg+"<br>"); 544 read.close(); 545 546 System.out.println("<br><B>Local client</B><br>"); 548 String [] cmdClient = new String [3]; 549 cmdClient[0] = client.rubbos.getMonitoringRsh(); 550 cmdClient[1] = "localhost"; 551 cmdClient[2] = nodeInfoProgram; 552 p = Runtime.getRuntime().exec(cmdClient); 553 read = new BufferedReader (new InputStreamReader (p.getInputStream())); 554 while ((msg = read.readLine()) != null) 555 System.out.println(msg+"<br>"); 556 read.close(); 557 558 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 560 { 561 System.out.println("<br><B>Remote client "+i+"</B><br>"); 562 String [] rcmdClient = new String [3]; 563 rcmdClient[0] = client.rubbos.getMonitoringRsh(); 564 rcmdClient[1] = (String )client.rubbos.getRemoteClients().get(i); 565 rcmdClient[2] = nodeInfoProgram; 566 p = Runtime.getRuntime().exec(rcmdClient); 567 read = new BufferedReader (new InputStreamReader (p.getInputStream())); 568 while ((msg = read.readLine()) != null) 569 System.out.println(msg+"<br>"); 570 read.close(); 571 } 572 573 PrintStream outputStream = new PrintStream (new FileOutputStream (reportDir+"stat_client0.html")); 574 System.setOut(outputStream); 575 System.setErr(outputStream); 576 System.out.println("<center><h2>*** Performance Report ***</h2></center><br>"); 577 System.out.println("<A HREF=\"perf.html\">Overall performance report</A><br>"); 578 System.out.println("<A HREF=\"stat_client0.html\">Main client (localhost) statistics</A><br>"); 579 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 580 System.out.println("<A HREF=\"stat_client"+(i+1)+".html\">client1 ("+client.rubbos.getRemoteClients().get(i)+") statistics</A><br>"); 581 System.out.println("<p><br>   <A HREF=\"perf.html#node\">Node information</A><br>"); 582 System.out.println("   <A HREF=\"#time\">Test timing information</A><br>"); 583 System.out.println("   <A HREF=\"#up_stat\">Up ramp statistics</A><br>"); 584 System.out.println("   <A HREF=\"#run_stat\">Runtime session statistics</A><br>"); 585 System.out.println("   <A HREF=\"#down_stat\">Down ramp statistics</A><br>"); 586 System.out.println("   <A HREF=\"#all_stat\">Overall statistics</A><br>"); 587 System.out.println("   <A HREF=\"#cpu_graph\">CPU usage graphs</A><br>"); 588 System.out.println("   <A HREF=\"#procs_graph\">Processes usage graphs</A><br>"); 589 System.out.println("   <A HREF=\"#mem_graph\">Memory usage graph</A><br>"); 590 System.out.println("   <A HREF=\"#disk_graph\">Disk usage graphs</A><br>"); 591 System.out.println("   <A HREF=\"#net_graph\">Network usage graphs</A><br>"); 592 593 } 594 catch (Exception ioe) 595 { 596 System.out.println("An error occured while getting node information ("+ioe.getMessage()+")"); 597 } 598 } 599 600 System.out.println("<br><p><A NAME=\"time\"></A><h3>Test timing information</h3><p>"); 602 System.out.println("<TABLE BORDER=1>"); 603 System.out.println("<TR><TD><B>Test start</B><TD>"+TimeManagement.dateToString(startDate)); 604 System.out.println("<TR><TD><B>Up ramp start</B><TD>"+TimeManagement.dateToString(upRampDate)); 605 System.out.println("<TR><TD><B>Runtime session start</B><TD>"+TimeManagement.dateToString(runSessionDate)); 606 System.out.println("<TR><TD><B>Down ramp start</B><TD>"+TimeManagement.dateToString(downRampDate)); 607 System.out.println("<TR><TD><B>Test end</B><TD>"+TimeManagement.dateToString(endDate)); 608 System.out.println("<TR><TD><B>Up ramp length</B><TD>"+TimeManagement.diffTime(upRampDate, runSessionDate)+ 609 " (requested "+client.rubbos.getUpRampTime()+" ms)"); 610 System.out.println("<TR><TD><B>Runtime session length</B><TD>"+TimeManagement.diffTime(runSessionDate, downRampDate)+ 611 " (requested "+client.rubbos.getSessionTime()+" ms)"); 612 System.out.println("<TR><TD><B>Down ramp length</B><TD>"+TimeManagement.diffTime(downRampDate, endDownRampDate)+ 613 " (requested "+client.rubbos.getDownRampTime()+" ms)"); 614 System.out.println("<TR><TD><B>Total test length</B><TD>"+TimeManagement.diffTime(startDate, endDate)); 615 System.out.println("</TABLE><p>"); 616 617 System.out.println("<br><A NAME=\"up_stat\"></A>"); 619 upRampStats.display_stats("Up ramp", TimeManagement.diffTimeInMs(upRampDate, runSessionDate), false); 620 System.out.println("<br><A NAME=\"run_stat\"></A>"); 621 runSessionStats.display_stats("Runtime session", TimeManagement.diffTimeInMs(runSessionDate, downRampDate), false); 622 System.out.println("<br><A NAME=\"down_stat\"></A>"); 623 downRampStats.display_stats("Down ramp", TimeManagement.diffTimeInMs(downRampDate, endDownRampDate), false); 624 System.out.println("<br><A NAME=\"all_stat\"></A>"); 625 allStats.display_stats("Overall", TimeManagement.diffTimeInMs(upRampDate, endDownRampDate), false); 626 627 628 if (isMainClient) 629 { 630 try 632 { 633 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 634 { 635 remoteClientMonitor[i].waitFor(); 636 remoteClient[i].waitFor(); 637 } 638 webServerMonitor.waitFor(); 639 dbServerMonitor.waitFor(); 640 cjdbcServerMonitor.waitFor(); 641 } 642 643 catch (Exception e) 644 { 645 System.out.println("An error occured while waiting for remote processes termination ("+e.getMessage()+")"); 646 } 647 648 try 650 { 651 String [] scpCmd = new String [3]; 652 Process p; 653 scpCmd[0] = client.rubbos.getMonitoringScp(); 654 scpCmd[2] = reportDir+"/"; 655 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 656 { 657 scpCmd[1] = (String )client.rubbos.getRemoteClients().get(i) + ":"+tmpDir+"/client"+(i+1); 658 p = Runtime.getRuntime().exec(scpCmd); 659 p.waitFor(); 660 } 661 scpCmd[1] = client.rubbos.getWebServerName() + ":"+tmpDir+"/web_server"; 662 p = Runtime.getRuntime().exec(scpCmd); 663 p.waitFor(); 664 if(client.rubbos.getCJDBCServerName() != null 665 && !client.rubbos.getCJDBCServerName().equals("")) { 666 scpCmd[1] = client.rubbos.getCJDBCServerName() + ":"+tmpDir+"/cjdbc_server"; 667 p = Runtime.getRuntime().exec(scpCmd); 668 p.waitFor(); 669 } 670 scpCmd[1] = client.rubbos.getDBServerName() + ":"+tmpDir+"/db_server"; 671 p = Runtime.getRuntime().exec(scpCmd); 672 p.waitFor(); 673 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 675 { 676 scpCmd[1] = (String )client.rubbos.getRemoteClients().get(i) 677 + ":"+tmpDir+"trace_client"+(i+1)+".html"; 678 p = Runtime.getRuntime().exec(scpCmd); 679 p.waitFor(); 680 scpCmd[1] = (String )client.rubbos.getRemoteClients().get(i) 681 + ":"+tmpDir+"stat_client"+(i+1)+".html"; 682 p = Runtime.getRuntime().exec(scpCmd); 683 p.waitFor(); 684 } 685 } 686 catch (Exception e) 687 { 688 System.out.println("An error occured while scping the files over ("+e.getMessage()+")"); 689 } 690 691 692 try 694 { 695 String cmd; 696 Process p; 697 cmd = "mv "+reportDir+"/"+"web_server "+reportDir+"/"+"web_server.bin"; 699 p = Runtime.getRuntime().exec(cmd); 700 p.waitFor(); 701 702 if(client.rubbos.getCJDBCServerName() != null 704 && !client.rubbos.getCJDBCServerName().equals("")) 705 { 706 cmd = "mv "+reportDir+"/"+"cjdbc_server "+reportDir+"/"+"cjdbc_server.bin"; 707 p = Runtime.getRuntime().exec(cmd); 708 p.waitFor(); 709 } 710 711 cmd = "mv "+reportDir+"/"+"db_server "+reportDir+"/"+"db_server.bin"; 713 p = Runtime.getRuntime().exec(cmd); 714 p.waitFor(); 715 716 cmd = "mv "+reportDir+"/"+"client0 "+reportDir+"/"+"client0.bin"; 718 p = Runtime.getRuntime().exec(cmd); 719 p.waitFor(); 720 721 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 723 { 724 cmd = "mv "+reportDir+"/"+"client"+(i+1)+" "+reportDir+"/"+"client"+(i+1)+".bin"; 725 p = Runtime.getRuntime().exec(cmd); 726 p.waitFor(); 727 } 728 729 String [] convCmd = new String [5]; 731 int fullTimeInSec = (client.rubbos.getUpRampTime()+client.rubbos.getSessionTime()+client.rubbos.getDownRampTime())/1000 + 5; String common = "'LANG=en_GB.UTF-8 "+client.rubbos.getMonitoringProgram()+" "+client.rubbos.getMonitoringOptions()+" "+ 733 client.rubbos.getMonitoringSampling()+" "+fullTimeInSec+" -f "+reportDir; 734 convCmd[0] = client.rubbos.getMonitoringRsh(); 735 convCmd[1] = "localhost"; 736 convCmd[2] = "/bin/bash"; 737 convCmd[3] = "-c"; 738 convCmd[4] = common+"web_server.bin > "+reportDir+""+"web_server'"; 739 System.out.println("    Command is: "+convCmd[0]+" "+convCmd[1]+" "+convCmd[2]+" "+convCmd[3]+" "+convCmd[4]+"<br>\n"); 740 p = Runtime.getRuntime().exec(convCmd); 741 742 if(client.rubbos.getCJDBCServerName() != null 743 && !client.rubbos.getCJDBCServerName().equals("")) 744 { 745 convCmd[4] = common+"cjdbc_server.bin > "+reportDir+""+"cjdbc_server'"; 746 System.out.println("    Command is: "+convCmd[0]+" "+convCmd[1]+" "+convCmd[2]+" "+convCmd[3]+" "+convCmd[4]+"<br>\n"); 747 p = Runtime.getRuntime().exec(convCmd); 748 p.waitFor(); 749 } 750 751 convCmd[4] = common+"db_server.bin > "+reportDir+""+"db_server'"; 752 System.out.println("    Command is: "+convCmd[0]+" "+convCmd[1]+" "+convCmd[2]+" "+convCmd[3]+" "+convCmd[4]+"<br>\n"); 753 p = Runtime.getRuntime().exec(convCmd); 754 p.waitFor(); 755 756 convCmd[4] = common+"client0.bin > "+reportDir+""+"client0'"; 757 System.out.println("    Command is: "+convCmd[0]+" "+convCmd[1]+" "+convCmd[2]+" "+convCmd[3]+" "+convCmd[4]+"<br>\n"); 758 p = Runtime.getRuntime().exec(convCmd); 759 p.waitFor(); 760 761 for (int i = 0 ; i < client.rubbos.getRemoteClients().size() ; i++) 762 { 763 convCmd[2] =common+"client"+(i+1)+".bin > "+reportDir+""+"client"+(i+1)+"'"; 764 System.out.println("    Command is: "+convCmd[0]+" "+convCmd[1]+" "+convCmd[2]+" "+convCmd[3]+" "+convCmd[4]+"<br>\n"); 765 p = Runtime.getRuntime().exec(convCmd); 766 p.waitFor(); 767 } 768 769 770 } 771 catch (Exception e) 772 { 773 System.out.println("An error occured while convering log files ("+e.getMessage()+")"); 774 } 775 776 try 778 { 779 String [] cmd = new String [4]; 780 cmd[0] = "bench/generate_graphs.sh"; 781 cmd[1] = reportDir; 782 cmd[2] = client.rubbos.getGnuPlotTerminal(); 783 cmd[3] = Integer.toString(client.rubbos.getRemoteClients().size()+1); 784 Process graph = Runtime.getRuntime().exec(cmd); 785 BufferedReader read = new BufferedReader (new InputStreamReader (graph.getInputStream())); 787 String msg; 788 while ((msg = read.readLine()) != null) 789 System.out.println(msg+"<br>"); 790 read.close(); 791 graph.waitFor(); 792 } 793 catch (Exception e) 794 { 795 System.out.println("An error occured while generating the graphs ("+e.getMessage()+")"); 796 } 797 } 798 boolean cjdbcFlag = false; 799 if(client.rubbos.getCJDBCServerName() != null 800 && !client.rubbos.getCJDBCServerName().equals("")) { 801 cjdbcFlag = true; 802 } 803 System.out.println("<br><A NAME=\"cpu_graph\"></A>"); 804 System.out.println("<br><h3>CPU Usage graphs</h3><p>"); 805 System.out.println("<TABLE>"); 806 System.out.println("<TR><TD><IMG SRC=\"cpu_busy."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_cpu_busy."+client.rubbos.getGnuPlotTerminal()+"\">"); 807 if(cjdbcFlag) 808 { 809 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_cpu_busy."+client.rubbos.getGnuPlotTerminal()+"\">"); 810 } 811 System.out.println("<TR><TD><IMG SRC=\"cpu_idle."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_cpu_idle."+client.rubbos.getGnuPlotTerminal()+"\">"); 812 if(cjdbcFlag) 813 { 814 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_cpu_idle."+client.rubbos.getGnuPlotTerminal()+"\">"); 815 } 816 System.out.println("<TR><TD><IMG SRC=\"cpu_user_kernel."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_cpu_user_kernel."+client.rubbos.getGnuPlotTerminal()+"\">"); 817 if(cjdbcFlag) 818 { 819 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_cpu_user_kernel."+client.rubbos.getGnuPlotTerminal()+"\">"); 820 } 821 System.out.println("</TABLE><p>"); 822 823 System.out.println("<br><A NAME=\"procs_graph\"></A>"); 824 System.out.println("<TABLE>"); 825 System.out.println("<br><h3>Processes Usage graphs</h3><p>"); 826 System.out.println("<TR><TD><IMG SRC=\"procs."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_procs."+client.rubbos.getGnuPlotTerminal()+"\">"); 827 if(cjdbcFlag) 828 { 829 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_procs."+client.rubbos.getGnuPlotTerminal()+"\">"); 830 } 831 System.out.println("<TR><TD><IMG SRC=\"ctxtsw."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_ctxtsw."+client.rubbos.getGnuPlotTerminal()+"\">"); 832 if(cjdbcFlag) 833 { 834 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_ctxtsw."+client.rubbos.getGnuPlotTerminal()+"\">"); 835 } 836 System.out.println("</TABLE><p>"); 837 838 System.out.println("<br><A NAME=\"mem_graph\"></A>"); 839 System.out.println("<br><h3>Memory Usage graph</h3><p>"); 840 System.out.println("<TABLE>"); 841 System.out.println("<TR><TD><IMG SRC=\"mem_usage."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_mem_usage."+client.rubbos.getGnuPlotTerminal()+"\">"); 842 if(cjdbcFlag) 843 { 844 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_mem_usage."+client.rubbos.getGnuPlotTerminal()+"\">"); 845 } 846 System.out.println("<TR><TD><IMG SRC=\"mem_cache."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_mem_cache."+client.rubbos.getGnuPlotTerminal()+"\">"); 847 if(cjdbcFlag) 848 { 849 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_mem_cache."+client.rubbos.getGnuPlotTerminal()+"\">"); 850 } 851 System.out.println("</TABLE><p>"); 852 853 System.out.println("<br><A NAME=\"disk_graph\"></A>"); 854 System.out.println("<br><h3>Disk Usage graphs</h3><p>"); 855 System.out.println("<TABLE>"); 856 System.out.println("<TR><TD><IMG SRC=\"disk_rw_req."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_disk_rw_req."+client.rubbos.getGnuPlotTerminal()+"\">"); 857 if(cjdbcFlag) 858 { 859 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_disk_rw_req."+client.rubbos.getGnuPlotTerminal()+"\">"); 860 } 861 System.out.println("<TR><TD><IMG SRC=\"disk_tps."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_disk_tps."+client.rubbos.getGnuPlotTerminal()+"\">"); 862 if(cjdbcFlag) 863 { 864 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_disk_tps."+client.rubbos.getGnuPlotTerminal()+"\">"); 865 } 866 System.out.println("</TABLE><p>"); 867 868 System.out.println("<br><A NAME=\"net_graph\"></A>"); 869 System.out.println("<br><h3>Network Usage graphs</h3><p>"); 870 System.out.println("<TABLE>"); 871 System.out.println("<TR><TD><IMG SRC=\"net_rt_byt."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_net_rt_byt."+client.rubbos.getGnuPlotTerminal()+"\">"); 872 if(cjdbcFlag) 873 { 874 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_net_rt_byt."+client.rubbos.getGnuPlotTerminal()+"\">"); 875 } 876 System.out.println("<TR><TD><IMG SRC=\"net_rt_pack."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_net_rt_pack."+client.rubbos.getGnuPlotTerminal()+"\">"); 877 if(cjdbcFlag) 878 { 879 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_net_rt_pack."+client.rubbos.getGnuPlotTerminal()+"\">"); 880 } 881 System.out.println("<TR><TD><IMG SRC=\"socks."+client.rubbos.getGnuPlotTerminal()+"\"><TD><IMG SRC=\"client_socks."+client.rubbos.getGnuPlotTerminal()+"\">"); 882 if(cjdbcFlag) 883 { 884 System.out.println("<TR><TD><IMG SRC=\"cjdbc_server_socks."+client.rubbos.getGnuPlotTerminal()+"\">"); 885 } 886 System.out.println("</TABLE><p>"); 887 888 889 if (isMainClient) 890 { 891 try 893 { 894 String [] cmd = new String [6]; 895 cmd[0] = "bench/compute_global_stats.awk"; 896 cmd[1] = "-v"; 897 cmd[2] = "path="+reportDir; 898 cmd[3] = "-v"; 899 cmd[4] = "nbscript="+Integer.toString(client.rubbos.getRemoteClients().size()+1); 900 cmd[5] = reportDir+"stat_client0.html"; 901 Process computeStats = Runtime.getRuntime().exec(cmd); 902 BufferedReader read = new BufferedReader (new InputStreamReader (computeStats.getInputStream())); 904 String msg; 905 while ((msg = read.readLine()) != null) 906 System.out.println(msg+"<br>"); 907 read.close(); 908 computeStats.waitFor(); 909 } 910 catch (Exception e) 911 { 912 System.out.println("An error occured while generating the graphs ("+e.getMessage()+")"); 913 } 914 } 915 916 Runtime.getRuntime().exit(0); 917 } 918 919 } 920 | Popular Tags |