Archive for April, 2007

142 CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION (Web server certificate)

Monday, April 30th, 2007

142 CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT LIFE CYCLE Note The screen shots in this chapter are from Quest Software s JProbe and PerformaSure products. Figure 5-3. The snapshot difference between the heaps, filtered on my application packages Realize that rarely is a loitering object a single simple object; rather, it is typically a subgraph that maintains its own references. In this case, the SystemSnapShot class is a dummy class that holds a set of primitive type arrays with the names timestamp, memoryInfo, jdbcInfo, and threadDumps, but in a real-world scenario these arrays would be objects that reference other objects and so forth. By opening the second heap snapshot and looking at one of the SystemSnapShot instances, you can see all objects that it references. As shown in Figure 5-4, the SystemSnapShot class references four objects: timestamp, memoryInfo, jdbcInfo, and threadDumps. A loitering object, then, has a far greater impact than the object itself. Next, let s look at the referrer tree. We repeatedly ask the following questions: What class is referencing the SystemSnapShot? What class is referencing that class? Eventually, we finally find one of our classes. Figure 5-5 shows that the SystemSnapShot class is referenced by an Object array that is referenced by an ArrayList that is finally referenced by the AdminLoginAction.
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT (Florida web design)

Sunday, April 29th, 2007

CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT LIFE CYCLE Note A memory leak can be detected with a single execution of a use case or through a plethora of executions of a use case. In the latter case, the memory leak will scream out at you. So, while analyzing individual use cases is worthwhile, when searching for subtle memory leaks, executing your use case multiple times makes finding them easier. In this scenario, I performed steps 1 through 3 with a load tester that executed the MedRec administration login use case almost 500 times. Figure 5-2 shows the difference between the two heap snapshots. Figure 5-2. The snapshot difference between the heaps before and after executing the use case Figure 5-2 shows that my use case yielded 8,679 new objects added to the heap. Most of these objects are collection classes, and I suspect they are part of BEA s infrastructure. I scanned this list looking for my code, which in this case consists of any class in the com.bea.medrec package. Filtering on those classes, I was interested to see a large number of com.bea.medrec.actions. SystemSnapShot instances, as shown in Figure 5-3.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision professional web hosting services

140 CHAPTER 5 PERFORMANCE (Best web hosting) THROUGH THE APPLICATION

Sunday, April 29th, 2007

140 CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT LIFE CYCLE The final step in this example is to execute either an individual test case or a test suite. After downloading JUnit from www.junit.org, add the junit.jar file to your CLASSPATH and then invoke either its command-line interface or GUI interface. The three classes that execute these tests are as follows: junit.textui.TestRunner junit.swingui.TestRunner junit.awtui.TestRunner And as these package names imply, textui is the command-line interface and swinguiis the graphical interface. awtui provides a batch interface to executing unit tests. You can pass an individual test case or an entire test suite as an argument to the TestRunner class. For example, to execute the test suite that we created earlier, you would use this: java junit.swingui.TestRunner com.javasrc.metric.MetricTestSuite Unit Performance Testing Unit performance testing has three aspects: Memory profiling Code profiling Coverage profiling This section explores each facet of performance profiling. I provide examples of what to look for and the step-by-step process to implement each type of testing. Memory Profiling Let s first look at memory profiling. To illustrate how to determine if you do, in fact, have a memory leak, I modified the BEA MedRec application to capture the state of the environment every time an administrator logs in and to store that information in memory. My intent is to demonstrate how a simple tracking change left to its own devices can introduce a memory leak. The steps you need to perform on your code for each use are as follows: 1. Request a garbage collection and take a snapshot of your heap. 2. Perform your use case. 3. Request a garbage collection and take another snapshot of your heap. 4. Compare the two snapshots (the difference between them includes all objects remaining in the heap) and identify any unexpected loitering objects. 5. For each suspect object, open the heap snapshot and track down where the object was created.
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision shared web hosting services

CHAPTER 5 PERFORMANCE (Web hosting bandwidth) THROUGH THE APPLICATION DEVELOPMENT

Sunday, April 29th, 2007

CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT LIFE CYCLE public void testSD() { assertEquals( 3.03, this.sampleHeap.getStandardDeviation(), 0.01 ); } public void testVariance() { assertEquals( 9.17, this.sampleHeap.getVariance(), 0.01 ); } public void testDataPointCount() { assertEquals( 10, this.sampleHeap.getDataPoints().size() ); } } In Listing 5-1, you can see that the DataPoint class, in addition to maintaining the observed value for a point in time, supports minimum and maximum values for the time period, computes the range, and supports scaling and adding data points. The sample test case creates a DataPoint object in the setUp() method and then exercises each piece of functionality. Listing 5-2 shows the test case for the Metric class. The Metric class aggregates the DataPoint objects and provides access to the collective minimum, maximum, average, range, standard deviation, and variance. In the setUp() method, the test creates a set of data points and builds the metric to contain them. Each subsequent test case uses this metric and validates values computed by hand to those computed by the Metric class. Listing 5-3 rolls both of these test cases into a test suite that can be executed as one test. Listing 5-3. MetricTestSuite.java package com.javasrc.metric; import junit.framework.Test; import junit.framework.TestSuite; public class MetricTestSuite { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite( DataPointTest.class ); suite.addTestSuite( MetricTest.class ); return suite; } } A TestSuite exercises all tests in all classes added to it by calling the addTestSuite() method. A TestSuite can contain TestCases or TestSuites, so once you build a suite of test cases for your classes, a master test suite can include your suite and inherit all of your test cases.
Note: If you are looking for cheap webhost to host and run your apache application check Vision jboss web hosting services

Web server - 138 CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION

Saturday, April 28th, 2007

138 CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT LIFE CYCLE for( int i=0; i<10; i++ ) { DataPoint dp = new DataPoint( new Date(), heapValue, heapMin, heapMax ); this.sampleHeap.addDataPoint( dp ); try { Thread.sleep( 50 ); } catch( Exception e ) { } // Update the heap values heapMin -= 1.0; heapMax += 1.0; heapValue += 1.0; } } public void testMin() { assertEquals( 41.0, this.sampleHeap.getMin(), 0.001 ); } public void testMax() { assertEquals( 159.0, this.sampleHeap.getMax(), 0.001 ); } public void testAve() { assertEquals( 104.5, this.sampleHeap.getAve(), 0.001 ); } public void testMaxRange() { assertEquals( 118.0, this.sampleHeap.getMaxRange(), 0.001 ); } public void testRange() { assertEquals( 118.0, this.sampleHeap.getRange(), 0.001 ); }
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision make web site services

CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT (Web design service)

Saturday, April 28th, 2007

CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT LIFE CYCLE // Sleep for 100ms so we can be sure that the time of // the new data point is later than the first Thread.sleep( 100 ); } catch( Exception e ) { } // Construct a new DataPoint DataPoint other = new DataPoint( new Date(), 4.0, 0.5, 20.0 ); // Should return -1 because other occurs after dp int result = dp.compareTo( other ); assertEquals( -1, result ); // Should return 1 because dp occurs before other result = other.compareTo( dp ); assertEquals( 1, result ); // Should return 0 because dp == dp result = dp.compareTo( dp ); assertEquals( 0, result ); } } Listing 5-2. MetricTest.java package com.javasrc.metric; import junit.framework.TestCase; import java.util.*; public class MetricTest extends TestCase { private Metric sampleHeap; protected void setUp() { this.sampleHeap = new Metric( “Test Metric”, “Value/Min/Max”, “megabytes” ); double heapValue = 100.0; double heapMin = 50.0; double heapMax = 150.0;
Note: In case you are looking for affordable webhost to host and run your web application check Vision http web server services

136 CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION (Apache web server tutorial)

Friday, April 27th, 2007

136 CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT LIFE CYCLE /** * Clean up: do nothing for now */ protected void tearDown() { } /** * Test the range of the DataPoint */ public void testRange() { assertEquals( 9.0, dp.getRange(), 0.001 ); } /** * See if the DataPoint scales properly */ public void testScale() { dp.scale( 10.0 ); assertEquals( 50.0, dp.getValue(), 0.001 ); assertEquals( 10.0, dp.getMin(), 0.001 ); assertEquals( 100.0, dp.getMax(), 0.001 ); } /** * Try to add a new DataPoint to our existing one */ public void testAdd() { DataPoint other = new DataPoint( new Date(), 4.0, 0.5, 20.0 ); dp.add( other ); assertEquals( 9.0, dp.getValue(), 0.001 ); assertEquals( 0.5, dp.getMin(), 0.001 ); assertEquals( 20.0, dp.getMax(), 0.001 ); } /** * Test the compare functionality of our DataPoint to ensure that * when we construct Sets of DataPoints they are properly ordered */ public void testCompareTo() { try {
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web design programs services

Web site template - CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT

Friday, April 27th, 2007

CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT LIFE CYCLE In addition, JUnit offers a fail() method that you can call anywhere in your test case to immediately mark a test as failing. JUnit tests are executed by one of the TestRunner instances (there is one for command-line execution and one for a GUI execution), and each version implements the following steps: 1. It opens your TestCase class instance. 2. It uses reflection to discover all methods that start with test . 3. It repeatedly calls setUp(), executes the test method, and calls teardown(). As an example, I have a set of classes that model data metrics. A metric contains a set of data points, where each data point represents an individual sample, such as the size of the heap at a given time. I purposely do not list the code for the metric or data point classes; rather, I list the JUnit tests. Recall that according to one of the tenets of Extreme Programming, we write test cases before writing code. Listing 5-1 shows the test case for the Metric class, and Listing 5-2 shows the test case for the DataPoint class. Listing 5-1. DataPointTest.java package com.javasrc.metric; import junit.framework.TestCase; import java.util.*; /** * Tests the core functionality of a DataPoint */ public class DataPointTest extends TestCase { /** * Maintains our reference DataPoint */ private DataPoint dp; /** * Create a DataPoint for use in this test */ protected void setUp() { dp = new DataPoint( new Date(), 5.0, 1.0, 10.0 ); }
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web and email hosting services

Web hosting asp - 134 CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION

Thursday, April 26th, 2007

134 CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT LIFE CYCLE JUnit offers the following benefits to your unit testing: Faster coding: How many times have you written debug code inside your classes to verify values or test functionality? JUnit eliminates this by allowing you to write test cases in closely related, but centralized and external, classes. Simplicity: If you have to spend too much time implementing your test cases, then you won t do it. Therefore, the creators of JUnit made it as simple as possible. Single result reports: Rather than generating loads of reports, JUnit will give you a single pass/fail result, and, for any failure, show you the exact point where the application failed. Hierarchical testing structure: Test cases exercise specific functionality, and test suites execute multiple test cases. JUnit supports test suites of test suites, so when developers build test cases for their classes, they can easily assemble them into a test suite at the package level, and then incorporate that into parent packages and so forth. The result is that a single, top-level test execution can exercise hundreds of unit test cases. Developer-written tests: These tests are written by the same person who wrote the code, so the tests accurately target the intricacies of the code that the developer knows can be problematic. This test differs from a QA-written one, which exercises the external functionality of the component or use case instead, this test exercises the internal functionality. Seamless integration: Tests are written in Java, which makes the integration of test cases and code seamless. Free: JUnit is open source and licensed under the Common Public License Version 1.0, so you are free to use it in your applications. From an architectural perspective, JUnit can be described by looking at two primary components: TestCaseand TestSuite. All code that tests the functionality of your class or classes must extend junit.framework.TestCase. The test class can implement one or more tests by defining public void methods that start with test and accept no parameters, for example: public void testMyFunctionality() { … } For multiple tests, you have the option of initializing and cleaning up the environment before and between tests by implementing the following two methods: setUp() and tearDown(). In setUp() you initialize the environment, and in teardown() you clean up the environment. Note that these methods are called between each test to eliminate side effects between test cases; this makes each test case truly independent. Inside each TestCase test method, you can create objects, execute functionality, and then test the return values of those functional elements against expected results. If the return values are not as expected, then the test fails; otherwise, it passes. The mechanism that JUnit provides to validate actual values against expected values is a set of assert methods: assertEquals() methods test primitive types. assertTrue() and assertFalse() test Boolean values. assertNull() and assertNotNull() test whether or not an object is null. assertSame() and assertNotSame() test object equality.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services

CHAPTER 5 (Free web space) PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT

Thursday, April 26th, 2007

CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT LIFE CYCLE executed sections of your code and those that account for the majority of the components execution times. The resulting relative weighting of hot spots in the code allows for intelligent tuning and code refactoring. You should run code profiling on your components while executing your unit tests, because your unit tests attempt to mimic end-user actions and alternate user scenarios. Code profiling your unit tests should give you a good idea about how your component will react to real user interactions. Coverage profiling reports the percentage of classes, methods, and lines of code that were executed during a test or use case. Coverage profiling is important in assessing the efficacy of unit tests. If both the code and memory profiling of your code are good, but you are exercising only 20 percent of your code, then your confidence in your tests should be minimal. Not only do you need to receive favorable results from your functional unit tests and your code and memory performance unit tests, but you also need to ensure that you are effectively testing your components. This level of testing can be further extended to any code that you outsource. You should require your outsourcing company to provide you with unit tests for all components it develops, and then execute a performance test against those unit tests to measure the quality of the components you are receiving. By combining code and memory profiling with coverage profiling, you can quickly determine whether the unit tests are written properly and have acceptable results. Once the criteria for tests are met, the final key step to effectively implementing this level of testing is automation. You need to integrate functional and performance unit testing into your build process only by doing so can you establish a repeatable and trackable procedure. Because running performance unit tests can burden memory resources, you might try executing functional tests during nightly builds and executing performance unit tests on Friday-night builds, so that you can come in on Monday to test result reports without impacting developer productivity. This suggestion s success depends a great deal on the size and complexity of your environment, so, as always, adapt this plan to serve your application s needs. When performance unit tests are written prior to, or at least concurrently with, component development, then component performance can be assessed at each build. If such extensive assessment is not realistic, then the reports need to be evaluated at each major development milestone. For the developer, milestones are probably at the completion of the component or a major piece of functionality for the component. But at minimum, performance unit tests need to be performed prior to the integration of components. Again, building a high-performance car from tested and proven high-performance parts is far more effective than from scraps gathered from the junkyard. Unit Testing I thought this section would be a good opportunity to talk a little about unit testing tools and methods, though this discussion is not meant to be exhaustive. JUnit is, again, the tool of choice for unit testing. JUnit is a simple regression-testing framework that enables you to write repeatable tests. Originally written by Erich Gamma and Kent Beck, JUnit has been embraced by thousands of developers and has grown into a collection of unit testing frameworks for a plethora of technologies. The JUnit Web site (www.junit.org) hosts support information and links to the other JUnit derivations.
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision shared web hosting services