Archive for November, 2007

CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE (Web site construction)

Friday, November 30th, 2007

CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS creating an instance in the heap. Their environment was running out of permanent space, but because of the noclassgc tuning option on the heap, the JVM was unable to unload classes to make room for new ones. To correct this out-of-memory error, I configured their heap with a huge permanent space (512MB) and disabled the noclassgc JVM option. As Figure 14-7 illustrates, when the permanent space becomes full, it triggers a full garbage collection that cleans up Eden and the survivor spaces, but does not reclaim any memory from the permanent space. Figure 14-7. Garbage collection behavior when the permanent space becomes full Note When sizing the permanent space, consider using 128MB, unless your applications have a large number of classes, in which case you can consider using 256MB. If you have to configure the permanent space to use anything more, then you are only masking the symptoms of a significant architectural issue. Configuring the permanent space to 512MB is OK while you address your architectural issues, but just realize that it is only a temporary solution to buy you time while you address the real problems. Creating a 512MB permanent space is analogous to getting painkillers from your doctor for a broken foot. True, the painkillers make you feel better, but eventually they will wear off, and your foot will still be broken. The real solution is to have the doctor set your foot and put a cast on it to let it heal. The painkillers can help while the doctor sets your foot, but they are used to mask the symptoms of the problem while the core problem is resolved. As a general recommendation, when configuring the permanent space, make it large enough to hold all of your classes, but allow the JVM to unload classes when it needs to. Size it large enough so that hopefully it will not unload classes, but a minor slowdown to load classes from the file system is far more preferable than a JVM OutOfMemoryError crash!
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Web hosting packages - 362 CHAPTER 14 SOLVING COMMON JAVA EE

Wednesday, November 28th, 2007

362 CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS Figure 14-6. The relationship between the permanent space and the heap In general you want the permanent space to be large enough to hold all classes in your application, because reading classes from the file system is obviously more expensive than reading them from memory. To help you ensure that classes are not unloaded from the permanent space, the JVM has a tuning option: noclassgc This option tells the JVM not to perform garbage collection on (and unload) the class files in the permanent space. This tuning option is very intelligent, but it raises a question: what does the JVM do if the permanent space is full when it needs to load a new class? In my observation, the JVM examines the permanent space and sees that it needs memory, so it triggers a major garbage collection. The garbage collection cleans up the heap, but cannot touch the permanent space, so its efforts are fruitless. The JVM then looks at the permanent space again, sees that it is full, and repeats the process again, and again, and again. When I first encountered this problem, the customer was complaining of very poor performance and an eventual OutOfMemoryError after a certain amount of time. After examining verbose garbage collection logs in conjunction with heap utilization and process memory utilization charts, I soon discovered that the heap was running well, but the process was running out of memory. This customer maintained literally thousands of JSPs, and as such each one was translated to Java code, compiled to bytecode, and loaded in the permanent space before
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE (Free web host)

Tuesday, November 27th, 2007

CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS When page- or request-scoped variables maintain references to objects, they are automatically cleaned up before the request completes. Likewise, if session-scoped variables maintain references to objects, they are automatically cleaned up when your application explicitly invalidates the session or when the session time-out is exceeded. Probably the greatest number of false positives in memory leak detection that I see are leaky sessions. A leaky session does not leak anything at all; it consumes memory, resembling a memory leak, but its memory is eventually reclaimed. If the application server is about to run out of memory, the best strategy to determine whether you have a memory leak or a poorly managed session is to stop all input to this application server instance, wait for the sessions to time out, and then see if memory is reclaimed. Obviously, this procedure is not possible in production, but it offers a surefire way to test in production staging, with your load tester, if you suspect that you may have large sessions rather than a memory leak. In general, if you have excessively large sessions, the true resolution is to refactor your application to reduce session memory overhead. The following two workaround solutions can minimize the impact of excessively large sessions: Increase the heap size to support your sessions. Decrease the session time-out to invalidate sessions more quickly. A larger heap will spend more time in garbage collection, which is not an ideal situation, but a better one than an OutOfMemoryError. Increase the size of your heap to be able to support your sessions for the duration of your time-out value; this means that you need enough memory to hold all active user sessions as well as all sessions for users who abandon your Web site within the session time-out interval. If the business rules permit, decreasing the session time-out will cause session data to time out earlier and lessen the impact on the heap memory it is occupying. In summary, here are the steps to perform, prioritized from most desirable to least desirable: Refactor your application to store the minimum about of information that is necessary in session-scoped variables. Encourage your users to log out of your application and explicitly invalidate sessions when users log out. Decrease your session time-out to force memory to be reclaimed sooner. Increase your heap size. However, unwanted object references maintained from application-scoped variables, static variables, and long-lived classes are, in fact, memory leaks that need to be analyzed in a memory profiler. Permanent Space Anomalies The purpose of the permanent space in the JVM process memory is typically misunderstood. The heap itself only contains class instances, but before the JVM can create an instance of a class on the heap, it must load the class bytecode (.class file) into the process memory. It can then use that class bytecode to create an instance of the object in the heap. The space in the process memory that the JVM uses to store the bytecode versions of classes is the permanent space. Figure 14-6 illustrates the relationship between the permanent space and the heap: it exists inside the JVM process memory but is not part of the heap itself.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Web hosting plans - 360 CHAPTER 14 SOLVING COMMON JAVA EE

Monday, November 26th, 2007

360 CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS object. The HttpServletRequest object serves as a communication mechanism for various components in your dynamic Web tier, but as soon as the request is complete and the socket connected to the user is closed, the servlet container frees all variables stored in the HttpServletRequest. These variables exist for the lifetime of a single request. HTTP is a stateless protocol, meaning that a client makes a request of the server, the server responds to the request, the communication is terminated, and the conversation is complete. Because we appreciate being able to log on to a Web page, add items to a shopping cart, and then check out, Web servers have devised a mechanism to define an extended conversation that spans multiple requests the session. Attributes and parameters can be stored on a per user basis inside an HttpSession object, and then accessed by any servlet or JSP in the application when that user accesses them. In this way, the login page can locate your information and add it to the HttpSession, so that the shopping cart can add items to it and the check out page can access your credit card number to bill you. For a stateless protocol, the client always initiates the communication with the server, requiring the server to know how long the maximum break in communications can be before it considers the conversation over and discards the user s data. This length of time is referred to as the session time-out, and it is configurable inside the application server. Unless objects are explicitly removed from the session or the session is programmatically invalidated, objects will stay in the session for at least the duration of the time-out, measured from the last time the user accessed the Web server. While the session manages objects on a per-user basis, the ServletContext object manages objects on an application basis. The ServletContext is sometimes referred to as application scope, because through a servlet s ServletContext or a JSP s application object, you are able to maintain and share objects with all other servlets and JSPs for all users in the same application. The ServletContext is a prime location to place application configuration information and to cache application-wide data, such as database JNDI lookup results. If data is not stored in one of these four predefined areas: page scope, request scope, session scope, or application scope, objects may be stored in the following objects: Static variables Long-lived class variables Static variables are maintained in the JVM on a per-class basis and do not require a class instance to be alive in the heap for the static variable to exist. All class instances share the same static variable values, so changing a static variable in one class instance affects all other instances of the same class type. Therefore, if the application places an object into a static variable for a class and nullifies that variable, the static object is not reclaimed by the JVM. These static objects are prime locations for leaking memory! Finally, objects can be added to internal data structures or member variables inside long- lived classes such as servlets. When a servlet is created and loaded into memory, it has only one instance in memory, and multiple threads are configured to access that servlet instance. If it loads configuration information in its init() method, stores it in class variables, and reads that information while servicing requests, then all instances are assured of seeing the same information. One common problem that I have seen is the use of servlet class variables to store data such as page caches. These caches, in and of themselves, are good to have, but probably the worst place to manage them is from inside a servlet. If you are considering using a cache, then you are best served by integrating a third-party cache, like Tangosol s Coherence, into your application framework for that specific purpose.
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE (Cool web site)

Sunday, November 25th, 2007

CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS what requests you need to look at inside a memory profiler. Finding memory leaks in a production environment without crashing your application server is tricky, but tools with these monitoring capabilities make your job much easier! Artificial Memory Leaks A few issues can appear to be memory leaks that in actuality are not. I refer to these as artificial memory leaks, and they may appear in the following situations: Premature analysis Leaky sessions Permanent space anomalies This section examines each artificial memory leak, describing how to detect it and how to work around it. Premature Analysis To avoid a false positive when searching for memory leaks, you need to ensure that you are observing and analyzing the heap at the appropriate time. The danger is that, because a certain number of long-lived objects need to be in the heap, a trend may look deceiving until the heap reaches a steady state and contains its core objects. Wait until your application reaches this steady state prior to performing any trend analysis on the heap. To detect whether or not you are analyzing the heap prematurely, continue monitoring it after your analysis snapshot for a couple hours to see if the upward heap trend levels off or if it continues upward indefinitely. If the trend levels off, then capture a new memory recording at this point. If the trend continues upward, then analyze the memory session you have. Leaky Sessions Memory leaks tend to occur during Web requests, but during a Web request objects can be stored only in a finite number of places. Those places include the following: Page scope Request scope Session scope Application scope Static variables Long-lived class variables, such as inside a servlet itself When implementing JSPs, any variable created inside the JSP itself will be eligible for garbage collection as soon as the page completes; these variables exist for the lifetime of a single page. Attributes and parameters that are passed from the Web server to the application server, as well as attributes that are passed between servlets and JSPs, live inside an HttpServletRequest
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

358 CHAPTER 14 (Web design course) SOLVING COMMON JAVA EE

Saturday, November 24th, 2007

358 CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS up, and at some point executes a mark-sweep-compact garbage collection to clean up dead objects as well as to compact live objects at the bottom of the heap. As the heap grows, long- lived objects get pushed to the bottom of the heap. So your best bet for identifying potential memory leaks is to observe the behavior of the heap in its entirety: is the heap trending upward? Resolving Memory Leaks Memory leaks are elusive, but if you can identify the request causing the memory leak, then your work is much easier. Take your application to a development environment, and run it inside a memory profiler, as described in Chapter 5, performing the following steps: 1. Start your application inside the memory profiler. 2. Execute your use case (make the request) once to allow the application to load all of the objects that it needs in memory to satisfy the request; this reduces the amount of noise that you have to sift through later. 3. Take a snapshot of the heap to capture all objects in the heap before the use case has been executed. 4. Execute your use case again. 5. Take another snapshot of the heap to capture all objects in the heap after the use case has been executed. 6. Compare the two snapshots, and look for objects that should not remain in the heap after executing the use case. At this point, you will need access to developers involved in coding the request you are testing, so that they can make a determination about whether an object is, in fact, being leaked or if it is supposed to remain in memory for some purpose. If nothing screams out as a leaked object after performing this exercise, one trick I sometimes use is to perform step 4 a distinct number of times. For example, I might configure my load tester to execute the request 17 times, in hopes that my leak analysis might show 17 instances of something (or some multiple of 17). This technique is not always effective, but it has greatly helped me out when each execution of a request leaks objects. If you cannot isolate the memory leak to a specific request, then you have two options: Profile each suspected request until you find the memory leak. Configure a monitoring tool with memory capabilities. The first option is feasible in a small application or if you were lucky enough to partially isolate the problem, but not very feasible for large applications. The second option is more effective if you can gain access to the monitoring tools. These tools track object creation and destruction counts through bytecode instrumentation and typically report the number of objects held in predefined or user-defined classes, such as the Collections classes, as a result of individual requests. For example, a monitoring tool might report that the /action/login.do request left 100 objects in a HashMap after it completed. This report does not tell you where the memory leak is in the code or the specific object that it leaks, but it tells you, with very low overhead,
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Linux web host - CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE

Friday, November 23rd, 2007

CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS Figure 14-5. The shaded objects are those that have survived multiple major collections and are potential memory leaks. Some of this information is available through monitoring APIs, and detailed information is available through verbose garbage collection logs. The level of logging affects the performance of the JVM, and as with almost any monitoring technology, the more detailed (and useful) information you want, the more expensive it is to obtain. For the purposes of determining whether a memory leak exists, I use relatively standard settings that show the overall change in generational memory between garbage collections and draw conclusions from that. Sun reports the overhead for this level of logging at approximately 5 percent, and many of my clients run with these settings enabled all the time to ensure that they can manage and tune garbage collection. The following settings usually give you enough information to analyze: verbose:gc xloggc:gc.log XX:+PrintGCDetails XX:+PrintGCTimeStamps Observable trends in the heap overall can point to a potential memory leak, but looking specifically at the growth rate of the old generation can be more definitive. But remember that none of this investigation is conclusive: in order to conclusively determine that you have a memory leak, you need to run your application off-line in a memory profiler. IBM JVM Memory Management The IBM JVM works a little differently. Rather than starting with a large generational heap, it maintains all objects in a single space and frees memory as the heap grows. It runs different levels of garbage collections, and you can read in Chapter 9 about the various tuning options to optimize those collections. The main behavior of this heap is that it starts relatively small, fills
We recommend high quality webhost to host and run your jsp application: christian web host services.

356 CHAPTER 14 SOLVING COMMON JAVA EE (Web hosting reviews)

Thursday, November 22nd, 2007

356 CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS Figure 14-4. When the tenured space becomes full, the garbage collector suspends all execution threads and performs a full mark and sweep garbage collection. It frees all dead objects and moves all live objects to a newly compacted tenured space, leaving Eden and both survivor spaces empty. From Sun s implementation of garbage collection, you can see that objects in the old generation can be collected only by a major collection. Long-lived objects are expensive to clean up, so you want to ensure that short-lived objects die in a timely manner before they have a chance to be tenured, and hence require a major garbage collection to reclaim their memory. All of this background prepares us to identify memory leaks. Memory is leaked in Java when an object maintains an unwanted reference to another object, hence stopping the garbage collector from reclaiming its memory. In light of the architecture of the Sun JVM, objects that are not dereferenced will make their way through Eden and the survivor spaces, into the old generation. Furthermore, in a multiuser Web-based environment, if multiple requests are being made to leaky code, we will see a pattern of growth in the old generation. Figure 14-5 highlights potential candidates for leaked objects: objects that survive multiple major collections in the tenured space. Not all objects in the tenured space represent memory leaks, but all leaked objects will eventually end up in the tenured space. If a true memory leak exists, the tenured space will begin filling up with leaked objects until it runs out of memory. Therefore, we want to track the effectiveness of garbage collection in the old generation: each time that a major garbage collection runs, how much memory is it able to reclaim? Is the memory use in the old generation growing according to any discernable pattern?
We recommend high quality webhost to host and run your jsp application: christian web host services.

CHAPTER 14 SOLVING COMMON JAVA (Web hosting e commerce) EE PERFORMANCE

Wednesday, November 21st, 2007

CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS Figure 14-3. When Eden becomes full again, the garbage collector copies live objects from both Eden and the first survivor space to the second survivor space until it is full. Remaining live objects are moved to the tenured space. The order of processing is important: the garbage collector first traverses Eden and then the survivor space; this ensures that objects are given ample opportunity to die before being tenured. Figure 14-4 illustrates how a major collection runs.
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

354 CHAPTER 14 SOLVING COMMON JAVA EE (Christian web host)

Tuesday, November 20th, 2007

354 CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS Objects are created in Eden. When Eden is full, the garbage collector iterates over all objects in Eden, copies live objects to the first survivor space, and frees memory for any dead objects. When Eden again becomes full, it repeats the process by copying live objects from Eden to the second survivor space, and then copying live objects from the first survivor space to the second survivor space. If the second survivor space fills and live objects remain in Eden or in the first survivor space, then these objects are tenured (that is, they are copied to the old generation). When the garbage collector cannot reclaim enough memory by executing this type of minor collection, also known as a copy collection, then it performs a major collection, also known as a stop-the-world collection. During the stop-the-world collection, the garbage collector suspends all threads and performs a mark and sweep collection on the entire heap, leaving the entire young generation empty and ready to restart this process. Figures 14-2 and 14-3 illustrate how minor collections run. Figure 14-2. Objects are created in Eden until it is full. Then the garbage collector traverses all objects in Eden, freeing dead objects and copying live objects to the survivor space until it is full. Live items remaining in Eden are moved to the tenured space.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.