Archive for December, 2007

368 CHAPTER 14 SOLVING COMMON JAVA EE (Apache web server tutorial)

Tuesday, December 4th, 2007

368 CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS this complication is that if you have 100 statements that you want to cache, but you have 50 database connections in your connection pool, then you need enough memory to hold 5,000 prepared statements. Through performance monitoring, determine how many unique SQL statements your application is running, and from those unique statements, consider how many of them are executed very frequently. Entity Bean and Stateful Session Bean Caches While stateless objects can be pooled, stateful objects like entity beans and stateful session beans need to be cached, because each bean instance is unique. When you need a stateful object, you need a specific instance of that object, and a generic instance will not suffice. As an analogy, consider that when you check out of a supermarket which cashier you use doesn t matter; any cashier will do. In this example, cashiers can be pooled, because your only requirement is a cashier, not Steve the cashier. But when you leave the supermarket, you want to bring your children with you; other peoples children will not suffice: you need your own. In this example, children need to be cached. The benefit to using a cache is that you can serve requests from memory rather than going across the network to load an object from a database. Figure 14-10 illustrates this benefit. Because caches hold stateful information, they need to be configured at a finite size. If they were able to grow without bound, then your entire database would eventually be in memory! The size of the cache and the number of unique, frequently accessed objects dictate the performance of the cache. Figure 14-10. The application requests an object from the cache that is in the cache, so a reference to that object is returned without making a network trip to the database.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

CHAPTER 14 SOLVING (Web hosting faq) COMMON JAVA EE PERFORMANCE

Monday, December 3rd, 2007

CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS to find the most appropriate place for a request to wait to minimize its impact on saturated resources; having a request waiting outside the database is best if the database is under duress. An application server with an inadequately sized connection is characterized by the following: Slow-running application Low CPU utilization High database connection pool utilization Threads waiting for a database connection High execution thread utilization Pending requests in the request queue (potentially) Database CPU utilization that is medium to low (because enough requests cannot be sent to it to make it work hard) If you observe these characteristics, increase the size of the connection pool until database connection pool utilization is running at 70 to 80 percent utilization during average load and threads are rarely observed waiting for a connection. Be cognizant of the load on the database, however, because you do not want to force enough load to the database to saturate its resources. JDBC Prepared Statements Another important tuning aspect related to JDBC is the correct sizing of JDBC connection prepared statement caches. When your application executes an SQL statement against the database, it does so by passing through three phases: Preparation Execution Retrieval During the preparation phase, the database driver may ask the database to compute an execute plan for the query. During the execution phase, the database executes the query and returns a reference to a result set. During the retrieval phase, the application iterates over the result set and obtains the requested information. The database driver optimizes this process: the first time you prepare a statement, it asks the database to prepare an execution plan and caches the result. On subsequent preparations, it loads the already prepared statement from the cache without having to go back to the database. When the prepared statement cache is sized too small, the database driver is forced to prepare noncached statements again, which incurs additional processing time as well as network time if the database connection goes back to the database. The primary symptom of an inadequately sized prepared statement cache is a significant amount of JDBC processing time spent repeatedly preparing the same statement. The breakdown of time that you would expect is for the preparation time to be high initially and then begin to diminish on subsequent calls. To complicate things ever so slightly, prepared statements are cached on a per-connection basis, meaning that a cached statement can be prepared for each connection. The impact of
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

366 CHAPTER 14 SOLVING COMMON JAVA EE (Professional web hosting)

Sunday, December 2nd, 2007

366 CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS Thread Pools That Are Too Large In addition to having thread pools that are sized too small, environments can be configured with too many threads. When load increases in these environments, the CPU is consistently high, and response time is poor, because the CPU spends too much time switching contexts between threads and little time allowing the threads to perform their work. The main indication that a thread pool is too large is a consistently high CPU utilization rate. Many times high CPU utilization is associated with garbage collection, but high CPU utili zation during garbage collection differs in one main way from that of thread pool saturation: garbage collection causes CPU spikes, while saturated thread pools cause consistently high CPU utilization. When this occurs, requests may be pending in the queue, but not always, because pending requests do not affect the CPU as processing requests do. Decreasing the thread pool size may cause requests to wait, but having requests waiting is better than processing them if processing the requests saturates the CPU utilization. A saturated CPU results in abysmal performance across the board, and performance is better if a request arrives, waits in a queue, and then is processed optimally. Consider the following analogy: many highways have metering lights that control the rate that traffic that can enter a crowded highway. In my opinion, the lights are inef fective, but the theory is sound. You arrive, wait in line behind the light for your turn, and then enter the highway. If all of the traffic entered the highway at the same time, we would be in complete gridlock, with no one able to move, but by slowing down the rate that new cars are added to the highway, the traffic is able to move. In practice, most metropolitan areas have so much traffic that the metering lights do not help, and what they really need is a few more lanes (CPUs), but if the lights could actually slow down the rate enough, then the highway traffic would flow better. To fix a saturated thread pool, reduce the thread pool size in steps until the CPU is running between 75 and 85 percent during normal user load. If the size of the queue becomes too unmanageable, then you need to do one of the following two things: Run your application in a code profiler, and tune the application code. Add additional hardware. If your user load has exceeded the capacity of your environment, you need to either change what you are doing (refactor and tune code) to lessen the CPU impact or add CPUs. JDBC Connection Pools Most Java EE applications connect to a back-end data source, and often these applications communicate with that back-end data source through a JDBC connection. Because database connections can be expensive to create, application servers opt to pool a specific number of connections and share them among processes running in the same application server instance. If a request needs a database connection when one is unavailable in the connection pool, and the connection pool is unable to create a new connection, then the request must wait for a connection to become available before it can complete its operation. Conversely, if the database connection pool is too large, then the application server wastes resources, and the application has the potential to force too much load on the database. As with all of our tuning efforts, the goal is
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Web hosting reviews - CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE

Saturday, December 1st, 2007

CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS load tester to ensure your measurements accuracy. Once you observe a dip in the throughput, lower the thread pool size down one step, to the size where throughput was maximized. Figure 14-9 illustrates the behavior of a thread pool that is sized too small. Figure 14-9. When all threads are in use, requests back up in the execution queue. In this scenario, the thread pool utilization is at 100 percent and the queue length (number of requests in the execution queue) is growing. Every time I read performance tuning documents, one thing that bothers me is that they never recommend specific values for the size of your thread pools. Because these values depend so much on what your application is doing, the documents are completely accurate to generalize their recommendations; but it would greatly benefit the reader if they presented best practice starting values or ranges of values. For example, consider the following two applications: One application retrieves a string from memory and forwards it to a JSP for presentation. Another application queries 1,000 metric values from a database and computes the average, variance, and standard deviation against those metrics. The first application responds to requests very rapidly, maybe returning in less than 0.25 seconds, and does not make much use of the CPU. The second application may take 3 seconds to respond and is CPU intensive. Therefore, configuring a thread pool with 100 threads for the first application may be too low, because the application can support 200 simultaneous requests; but 100 threads may be too high for the second application, because it saturates the CPU at 50 threads. However, most applications do not exhibit this extreme dynamic in functionality. Most do similar things, but do them for different domains. Therefore, my recommendation is for you to configure between 50 and 75 threads per CPU. For some applications this number may be too low, and for others it may be too high, but as a best practice I start with 50 to 75 threads per CPU, monitor the CPU performance along with application throughput, and make adjustments.
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Web servers - 364 CHAPTER 14 SOLVING COMMON JAVA EE

Saturday, December 1st, 2007

364 CHAPTER 14 SOLVING COMMON JAVA EE PERFORMANCE PROBLEMS Thread Pools The main entry point into any Web or application server is a process that receives a request and places it into a request queue for an execution thread to process. After tuning memory, the tuning option with the biggest impact in an application server is the size of the execution thread pool. The size of the thread pool controls the number of simultaneous requests that can be processed at one time. If the pool is sized too small, then requests will wait in the queue for processing, and if the pool is sized too large, then the CPU will spend too much time switching contexts between the various threads. Each server has a socket it listens on. A process that receives an incoming request places the request into an execution queue, and the request is subsequently removed from the queue by an execution thread and processed. Figure 14-8 illustrates the components that make up the request processing infrastructure inside a server. Figure 14-8. The request processing infrastructure inside a server Thread Pools That Are Too Small When my clients complain of degraded performance at relatively low load that worsens measurably as the load increases, I first check the thread pools. Specifically, I am looking for the following information: Thread pool utilization Number of pending requests (queue depth) When the thread pool is 100 percent in use and requests are pending, the response time degrades substantially, because requests that otherwise would be serviced quickly spend additional time inside a queue waiting for an execution thread. During this time CPU utilization is usually low, because the application server is not doing enough work to keep the CPU busy. At this point, I increase the size of the thread pool in steps, monitoring the throughput of the application until it begins to decrease. You need consistent load or, even better, an accurate
We recommend high quality webhost to host and run your jsp application: christian web host services.