Web Hosting Java, JSP, Tomcat 6, J2EE, Servlets, Struts, Jboss
Page 166
October 31, 2006 on 1:23 pm | In Java | No CommentsPage 167
Hint: If you are looking for very good and affordable webspace to host and run your j2ee hosting application check Virtualwebstudio j2ee web hosting services
Page 166
October 31, 2006 on 1:23 pm | In Java | No CommentsPage 166
Hint: If you are looking for very good and affordable webspace to host and run your j2ee hosting application check Virtualwebstudio j2ee web hosting services
Page 164
October 31, 2006 on 11:38 am | In Java | No Comments Page 164
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services
Page 164
October 31, 2006 on 11:38 am | In Java | No Comments Optimization 41: Lock Fusion In the previous optimization we lobbied in favor of splitting two unrelated updates under the protection of two independent lock objects. On the other extreme, if two shared resources are related to one another and their updates seem to happen in tandem, it does make sense to fuse those two updates under the protection of a single object lock. Let’s continue along the lines of a Web-server implementation. Suppose that the server not only records the number of HTTP and SSL requests, but also the number of bytes served for each protocol. The class keeping track of those statistics is HTStats: class HTStats { private static int httpReqs; // Number of requests. private static Object lockHttpReqs = new Object(); private static int httpBytes; // Number of bytes served. private static Object lockHttpBytes = new Object(); … public static void updateHttpStats(int bytes) { addHttpReq(); addHttpBytes(bytes); } public static void addHttpReq() { synchronized (lockHttpReqs) { httpReqs++; // Increment the counter for HTTP requests. } } public static void addHttpBytes(int bytes) { synchronized (lockHttpBytes) { httpBytes += bytes; // Increment the counter for HTTP bytes. } } }; As is stands, the methods for updating the HTTP requests and byte counters are using distinct objects to provide synchronization. The updateHttpStats(), however, always updates those two counters together. It seems to make more sense to fuse those two counters under the same synchronized block. That’s the theoretical solution. Let’s see what happens in practice. We develop a test case that closely mimics the above scenario. The scaffolding of the test is pretty much the same as previous tests: We launch a few threads, give them something to do and measure it: class MtFusion { public static void main(String args[]) { try { if(args.length != 2) { System.out.println(”Usage java MtFusion
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services
Page 162
October 31, 2006 on 9:44 am | In Java | No Comments Page 162
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services
Page 162
October 31, 2006 on 9:44 am | In Java | No Comments Page 163
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services
Page 160
October 31, 2006 on 8:25 am | In Java | No Comments Page 160
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services
Page 160
October 31, 2006 on 8:25 am | In Java | No Comments Optimization 40: Synchronization False Sharing Every Java object and class has a single lock associated with it. If you synchronize on an object via a synchronized method or block, you are locking up the object. If two synchronized methods in the same object try to access completely unrelated resources, they will lock each other out. This is a case of false sharing, where two logically unrelated operations are forced to physically share the object’s lock. The same point applies to the class lock in the case of static shared resources. Take, for instance, a multithreaded Web server listening on both HTTP and HTTPS (otherwise known as SSL) ports. Most reasonable implementations of a Web server will make some rudimentary statistics available to the Webmaster. At the very least, they will keep track of the number of HTTP and HTTPS requests: class HTStats { private static int httpReqs; private static int sslReqs; … }; Since multiple threads may try to manipulate the statistics concurrently, such manipulations must be synchronized: public synchronized static void addHttpReq() { httpReqs++; // Increment the counter for HTTP requests. } public synchronized static void addSslReq() { sslReqs++; // incement the counter for HTTPS requests. } The HTStats class uses a single lock to protect the manipulation of all of its static counters. Fusing multiple unrelated shared resources under the umbrella of a single lock is normally a bad idea. It widens the scope of the synchronized regions and creates friction among otherwise independent threads. The only possible exception to this rule is when both of the following two conditions are satisfied: . All of the shared resources are always manipulated together. . None of the manipulations of the shared resources consume significant CPU cycles. In the case of counting HTTP and SSL requests, the second condition was satisfied (shared counters; updates are fast) but the first condition was broken: A thread that updated one counter did not access the other. An SSL thread might update the SSL counter but have no interest in the state of the HTTP counter. The preferred solution is to have two distinct locks protecting two unrelated counters so that the contention for each lock is reduced by half: class HTStats { private static int httpReqs; private static Object lockHttp = new Object(); private static int sslReqs; private static Object lockSsl = new Object(); … public static void addHttpReq() { synchronized (lockHttp) { httpReqs++; // Increment the counter for HTTP requests. Page 161
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services
Page 158
October 31, 2006 on 6:32 am | In Java | No CommentsPage 158
Hint: If you are looking for very good and affordable webspace to host and run your tomcat hosting application check Virtualwebstudio tomcat web hosting provider
Page 158
October 31, 2006 on 6:32 am | In Java | No CommentsOptimization 39: Parallel Subtasks In order to unleash potential scalability, your application must divide its computational task into multiple subtasks that could be executed in parallel. A Web server is a good example. The computational task is to service multiple client requests as they arrive on a designated HTTP port. If your Web server is single-threaded, it can perform only one request at a time. All other requests have to queue up. To enable scalability we must break up the service task. The task of servicing all the requests on the queue is split into smaller subtasks of serving a single request. By unleashing multiple threads on the smaller subtasks, we can achieve true parallelism and scalability. Breaking up the Web service into parallel subtasks improves several performance indicators: . Response time of an individual request . Server throughput in requests per second . Server CPU utilization A Web server performs frequent blocking I/O operations. If the server consists of a single thread, no work is performed while waiting on I/O completion. A multithreaded server would just switch over to perform other tasks and keep the processors humming. The result is better throughput and higher CPU utilization. One thing that could certainly make customers unhappy is seeing their 12-way SMP server at 25 percent CPU utilization. Starting from a single-threaded application, you are likely to see throughput rise significantly as you move into multithreaded territory and increase the number of concurrent threads. As you increase the level of concurreny, you will eventually reach a point of peak throughput. If you continue to increase the number of threads beyond this “sweet spot,” you are not going to see any more gains in performance. If you keep on going, eventually throughput and other performance measures are going to plummet. Multithreading is like sugar. It could get to the point where it is just too much. Too many threads create higher contention for resources, and they eat up cache and memory space. Shortage of cache and memory space lead to costly cache misses and page faults. This could degrade performance by an order of magnitude. In Chapter 11 we develop a scalable multithreaded Java Web server. We control the number of server threads via a configuration property. We experimented with various levels of multithreading to exhibit the interaction between concurrency and throughput. We ran the Java Web server on a four-way SMP (Pentium-II, 4X200 MHz) running NT. Figure 7.8 charts the mapping from number of concurrent threads to server throughput measured by requests per second. Figure 7.8. The relationship between concurrency and throughput Page 159
Hint: If you are looking for very good and affordable webspace to host and run your tomcat hosting application check Virtualwebstudio tomcat web hosting provider
...I
just wanted to take the time to say "Thank you!" for our new webmail
system. It's great! Thanks for taking such good care of us.
Thanks
for helping me out. Just for the record, Webhostingjava.net has been a great
web host! So far your support and handling of questions has far
exceeded that of a "larger web hosting company".
I
would like to thank you for helping me with my domain...You have
shown me great patience and professionalism. I would not hesitate to
recommend you to my clients.