{"id":6868,"date":"2016-07-22T13:21:27","date_gmt":"2016-07-22T05:21:27","guid":{"rendered":"http:\/\/onthe8spot.com\/?p=6868"},"modified":"2016-07-22T13:21:27","modified_gmt":"2016-07-22T05:21:27","slug":"top-10-reasons-why-your-enterprise-java-application-is-slow","status":"publish","type":"post","link":"http:\/\/onthe8spot.com\/index.php\/2016\/07\/22\/top-10-reasons-why-your-enterprise-java-application-is-slow\/","title":{"rendered":"Top 10 reasons why your Enterprise Java Application is slow"},"content":{"rendered":"<p>This is a gem of a blog post. Very instructive and useful.<br \/>\nMost of what is says can be considered common knowledge but by being concisely written and with relevant examples it turns something superfluous to useful.<\/p>\n<blockquote><p>Top 10 reasons why your Enterprise Java Application is slowby KARUN SUBRAMANIAN on JULY 27, 2014Let\u2019s face it. Nobody likes a slow application. It is our job to make sure our applications\u00a0 fulfill the functionality need completely, but at the same time delivers\u00a0good user experience.In\u00a016 years of my experience in technical support primarily in the world of JEE, while I cannot honestly say \u2018I have seen it all\u2019, I can say \u201cI have seen a\u00a0lot\u201c. Here are the top\u00a010 reasons why your Java application may slow.Note that this list is NOT ordered in anyway, meaning reason 1 is not always the most popular reason for the slowness. These are all equally critical issues that can cause your application to crawl.<\/p><\/blockquote>\n<p>Source: <em><a href=\"http:\/\/karunsubramanian.com\/websphere\/top-10-reasons-why-your-enterprise-java-application-is-slow\/\">Top 10 reasons why your Enterprise Java Application is slow<\/a><\/em><br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n<span style=\"color: #ffffff;\"><strong>1. There is a sudden spike in the\u00a0\u2018Load\u2019 that you did not notice<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">This is especially true when your application processes requests from external entities (for example, a financial institution processing batch updates from a data provider). Since you cannot really control (for the most part) what others might send, you can suffer a surge in incoming requests and hence your application can slow down.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>How can\u00a0you monitor?<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">You must monitor the <strong>\u2018throughput\u2019<\/strong> of the application (specifically, number of requests\/minute). You will most probably need a commercial <strong>APM (Application Performance Management)<\/strong> tool to monitor this reliably. If you don\u2019t have an APM solution implemented (why ?), try to come up with some home grown script\/program that can monitor this. <strong>For one or my clients<\/strong>, I had to write a program that performed a \u2018row count\u2019 of a Database table that stored the \u2018processed orders\u2019. I had to run this program through a scheduler (cron) periodically and send an alert email if the number of processed records crossed a threshold.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>2. There is a poorly responding backend system<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">Your application may talk to one or\u00a0more backend systems other than a Database. Perhaps<strong> it talks to an external system using a Web Service call<\/strong>. Perhaps it sends a WebSphere MQ message to a<strong>remote Queue Manager<\/strong> (that in turn routes the message to an external system to get a response). If any of these external systems respond poorly (or even stop completely), your application will suffer.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>How can\u00a0you monitor?<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">You must monitor the <strong>response <\/strong><strong>time of the external systems experienced by your application.<\/strong> <strong>A periodic synthetic transaction might help<\/strong> (if feasible). If you log the response times in a log file, you could monitor the particular entry in the log file. But the best bet would be to use an APM solution and instrument the specific method that makes the external call. Tools such as <strong>AppDynamics and CA Wily Introscope<\/strong> (among many others) can automatically detect the backends and reveal the response times.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>3. Your database calls are taking for ever<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">This is a big one. It is possible that the sql queries (or Stored procedures) that originate from your application run extremely slow at the Database Server. This could be\u00a0due to\u00a0the following reasons:<\/span><br \/>\n<span style=\"color: #ffffff;\">a. Database Server is <strong>running our System resources<\/strong> such as CPU, Memory etc,<\/span><br \/>\n<span style=\"color: #ffffff;\">b.\u00a0A <strong>Block<\/strong> in the Database<\/span><br \/>\n<span style=\"color: #ffffff;\">c.\u00a0<strong>Missing index in the database,\u00a0<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">d. Your query really runs slow (perhaps you are<strong> missing a \u2018where\u2019 clause<\/strong>). In this case, work with a DBA to tune the query\/SP.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>How can you monitor ?<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">To some extent, monitoring from the DB side should help i.e the DBAs should have monitoring for things like long running queries, blocks, deadlocks etc. From application\u2019s perspective, you must monitor the <strong>JDBC response times experienced by your application<\/strong>. You can either log this information in log file (expensive and not recommended) or use an APM tool. New generation APM tools like <strong>Dynatrace<\/strong> (among many others) can reveal slow running JDBC calls including the <strong>actual SQL query or stored procedure<\/strong>.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>4. You are running out Database connections<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">This is another big one. Typically 50 JDBC connections per JVM should be more than enough. But it greatly depends on the Application. They key is to make sure you are not maxing out of DB connections. When you <strong>max out the DB Connection Pool,<\/strong> your requests are going to <strong>wait<\/strong> for an available connection which results in painful slow response time. The reason why you are maxing out of the DB connections should be found out. It could be that you are NOT closing the DB connections properly.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>How\u00a0can you\u00a0monitor?<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">If your application server has <strong>JMX console<\/strong>, Connection pools can be monitored via the MBeans, but it can be a painful process. You can also write your own Java program (<strong>JMX client<\/strong>) to connect and retrieve values from the Mbeans. Easy way is to install a commercial APM tool<\/span><br \/>\n<span style=\"color: #ffffff;\"><a style=\"color: #ffffff;\" href=\"https:\/\/i0.wp.com\/karunsubramanian.com\/wp-content\/uploads\/2014\/07\/jmx.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-351\" src=\"https:\/\/i0.wp.com\/karunsubramanian.com\/wp-content\/uploads\/2014\/07\/jmx-300x120.jpg?resize=300%2C120\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" srcset=\"http:\/\/karunsubramanian.com\/wp-content\/uploads\/2014\/07\/jmx-300x120.jpg 300w, http:\/\/karunsubramanian.com\/wp-content\/uploads\/2014\/07\/jmx-1024x412.jpg 1024w, http:\/\/karunsubramanian.com\/wp-content\/uploads\/2014\/07\/jmx-500x201.jpg 500w, http:\/\/karunsubramanian.com\/wp-content\/uploads\/2014\/07\/jmx.jpg 1226w\" alt=\"jmx\" width=\"300\" height=\"120\" \/><\/a><\/span><br \/>\n<span style=\"color: #ffffff;\"><em>Image from wiki<\/em><\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>5. You are running out of Threads<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">Work enters to your application via a Thread. You only have limited number of Threads to process incoming requests (limited by the <strong>Thread Pool<\/strong>). When you exhaust all the available threads in the Thread pool, subsequent requests go into \u2018wait\u2019 state, waiting for an available thread \u2013 <strong>painful wait time<\/strong>. The reason why you are running of out thread should be investigated. It could be because of a poorly performing backend or a slow DB response time.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>How can\u00a0you monitor?<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">If your application server has <strong>JMX console<\/strong>,\u00a0Thread pools can be monitored via the MBeans, but it can be a painful process. You can also write your own Java program (JMX client) to connect and retrieve values from the Mbeans. Easy way is to install a commercial APM tool. Some Application Server consoles (such <strong>as IBM Websphere application server<\/strong>) have built in monitoring dashboards as part of the Admin console. But it can be extremely slow and not very flexible.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>6. The Server hosting your application is running slow or running out of resources<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">Yes, even with Cloud and dynamically expandable hardware, the fact is hardware is not unlimited. When the CPU hits 100% in your host Server, your application is going to suffer. With shared hardware in most enterprises, it is possible that some other application is chewing up all the CPU and your application just becomes a victim.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>How can\u00a0you Monitor?<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">Operating system level monitoring tools will help. Tools like <strong>Nagios<\/strong> can help monitor the infrastructure effectively.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>7. Super excessive logging in your Application<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">Logging is expensive, in terms of resource usage. While debug logging will help in certain situations, in production environments, keep the logging to a minimum level (perhaps \u2018INFO\u2019 or \u2018WARN\u2019 log4j levels). An additional side effect of excessive logging is Disk drives filling up (which can have its own consequences). One of my clients was logging every single sql statement generated by the application (Hibernate verbose logging) and the application was generating 500 MB log file every day. While the performance impact was not too bad in this case, it created disk space issue until I disabled the verbose logging.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>How can you monitor ?<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>Periodically check your Application log files<\/strong> (JVM system out and system error). If you notice unnecessary noise, get rid of those logging entries. Checkout <strong>logstash<\/strong>.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>8. Garbage collection overhead<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">This is a critical performance area for any Java application. If you are running of Java Heap, the JVM will initiate GC to keep up with the memory demand. GC tuning is a separate and exhaustive topic by itself. Short story is GC will consume resources and excessive GC overhead will slow down your application. Pay attention to the Minimum (-Xms) and Maximum (-Xmx) Heap size values in the Java command line options.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>How can you monitor?<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">Enable verbose GC logging and watch the log file. You enable verbose GC logging with the options -verbose:gc\u00a0-XX:+PrintGCDetails\u00a0XX:+PrintGCTimeStamps.<\/span><br \/>\n<span style=\"color: #ffffff;\">Once the logs are collected, you can either eyeball it or use a tool like <strong>\u201cIBM Pattern Modeling and Analysis Tool for Java Garbage Collector\u201d<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\"><a style=\"color: #ffffff;\" href=\"https:\/\/i0.wp.com\/karunsubramanian.com\/wp-content\/uploads\/2014\/07\/gc.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-349\" src=\"https:\/\/i0.wp.com\/karunsubramanian.com\/wp-content\/uploads\/2014\/07\/gc-255x300.png?resize=255%2C300\" sizes=\"auto, (max-width: 255px) 100vw, 255px\" srcset=\"http:\/\/karunsubramanian.com\/wp-content\/uploads\/2014\/07\/gc-255x300.png 255w, http:\/\/karunsubramanian.com\/wp-content\/uploads\/2014\/07\/gc.png 791w\" alt=\"gc\" width=\"255\" height=\"300\" \/><\/a><\/span><br \/>\n<span style=\"color: #ffffff;\"><em>Image from ibm.com<\/em><\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>9. Third party jar files that you have included in your application is buggy<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">It is not uncommon to use third party jar files to use certain functionality for your application. However care must be taken to ensure there are no performance implications. Even if the jar is reliable and proven (such as spring.jar), there may be issues when you upgrade the spring version without analyzing the release notes etc. Perhaps you may be using the API in a certain way that changed with the newer release of spring. I have seen third party jars causing severe memory leak. I have also seen a rules engine (that was integrated into my client\u2019s JEE Application) that ran into \u2018infinite loop\u2019 issue causing the entire application to slow down.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>How\u00a0can you\u00a0monitor?<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">This can be trick to monitor. There is no bullet proof way to monitor just one jar file\/plugin unless your application specifically uses the thrid part jar for certain specific transactions, in\u00a0which case you can use an APM tool to instrument montioring for\u00a0just that particular method. Even then, you won\u2019t know if it is your code or the third part jar that is creating the issue. Through analysis is required to troubleshoot such issue.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>10. Poor Application Architecture<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">No matter how much tuning you put in your code, application server and database servers, if the Architecture is flawed, your application will be slow. For example,<\/span><br \/>\n<span style=\"color: #ffffff;\">a. Even when not required, using\u00a0\u2018persistent\u2019 messages with JMS.<\/span><br \/>\n<span style=\"color: #ffffff;\">b.\u00a0Storing more than necessary\u00a0data in a HTTP \u00a0\u2018Session\u2019 increasing its size<\/span><br \/>\n<span style=\"color: #ffffff;\">c. Not using (or using misconfigured) caching solution<\/span><br \/>\n<span style=\"color: #ffffff;\">Application architecture is a vast subject and scores of books have been written on this subject. Study carefully.<\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>How\u00a0can you\u00a0monitor?<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\">There is no specific monitoring to be done to monitor design flaws. Design issues will be revealed when you thoroughly analyze the problem and the available monitoring data.<\/span><br \/>\n<span style=\"color: #ffffff;\">There you have it. Application performance tuning starts from the design stage. There are various reasons your application could be slow. You must be diligent to monitor as much relevant metrics you can about your application and act promptly to avoid customer impact. Investing in a good quality APM solution adds <em>heaps<\/em> (no pun intended) of ammunition to your weapons in the battle of performance monitoring.<\/span><br \/>\n<span style=\"color: #ffffff;\">Good luck.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a gem of a blog post. Very instructive and useful. Most of what is says can be considered common knowledge but by being concisely written and with relevant examples it turns something superfluous to useful. Top 10 reasons why your Enterprise Java Application is slowby KARUN SUBRAMANIAN on JULY 27, 2014Let\u2019s face it. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/onthe8spot.com\/index.php\/2016\/07\/22\/top-10-reasons-why-your-enterprise-java-application-is-slow\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Top 10 reasons why your Enterprise Java Application is slow&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[79],"tags":[],"class_list":["post-6868","post","type-post","status-publish","format-standard","hentry","category-reposts"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/posts\/6868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/comments?post=6868"}],"version-history":[{"count":0,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/posts\/6868\/revisions"}],"wp:attachment":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/media?parent=6868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/categories?post=6868"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/tags?post=6868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}