Docsity

Jamon Introduction-Electrical Engineering and Programming-Report, Study Guides, Projects, Research of Electrical Engineering

Toggle sidebar
bg1
1
JAMON INTRODUCTION
The Java Application Monitor (JAMon) is a free, simple, high performance, thread safe,
Java API that allows developers to easily monitor production applications. JAMon can be
used to determine application performance bottlenecks, user/application interactions, and
application scalability. JAMon gathers summary statistics such as hits, execution times
(total, average, minimum, maximum, standard deviation), and simultaneous application
requests. JAMon statistics are displayed in the sortable JAMon report. Click JAMon
repotto see a live demo of JAMon. 2.
Advantages of JAMon
Using JAMon is easy. Place JAMon.jar (90K) in your classpath, and surround the code that you
wish to monitor with the JAMon API's start() and stop() methods. See the code sample below:
import com.jamonapi.*;
Monitor mon=MonitorFactory.start("myFirstMonitor");
Code Being Timed...
mon.stop();
For example, to collect statistics for all JSP pages in a Web Application, a developer would place
a call to the start() method at the top of every JSP, and a call to the stop() method at the bottom.
With a few minutes work the developer will have statistics for all application pages. The
statistics will include number of page hits, average page execution times, and the number of
users simultaneously accessing each page. The statistics can be displayed as an HTML table by
calling the getReport() method, or using JAMonAdmin.jsp.
JAMon requires no special administration accounts. Many monitoring tools require
administrative accounts to install monitoring software, and to view statistics. Due to the
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Jamon Introduction-Electrical Engineering and Programming-Report and more Study Guides, Projects, Research Electrical Engineering in PDF only on Docsity!

JAMON INTRODUCTION

 The Java Application Monitor (JAMon) is a free, simple, high performance, thread safe, Java API that allows developers to easily monitor production applications. JAMon can be used to determine application performance bottlenecks, user/application interactions, and application scalability. JAMon gathers summary statistics such as hits, execution times (total, average, minimum, maximum, standard deviation), and simultaneous application requests. JAMon statistics are displayed in the sortable JAMon report. Click JAMon repotto see a live demo of JAMon. 2. Advantages of JAMon Using JAMon is easy. Place JAMon.jar (90K) in your classpath, and surround the code that you wish to monitor with the JAMon API's start() and stop() methods. See the code sample below: import com.jamonapi.*; Monitor mon=MonitorFactory.start("myFirstMonitor"); Code Being Timed... mon.stop(); For example, to collect statistics for all JSP pages in a Web Application, a developer would place a call to the start() method at the top of every JSP, and a call to the stop() method at the bottom. With a few minutes work the developer will have statistics for all application pages. The statistics will include number of page hits, average page execution times, and the number of users simultaneously accessing each page. The statistics can be displayed as an HTML table by calling the getReport() method, or using JAMonAdmin.jsp. JAMon requires no special administration accounts. Many monitoring tools require administrative accounts to install monitoring software, and to view statistics. Due to the

complexity of these tools, developers typically go through specially trained administrators to access monitoring statistics. Also, because strings are passed to the start() method, a developer can decide what to monitor based on runtime data. Using this technique we can monitor trends as well as performance bottlenecks. Some examples of JAMon's flexibility: Keep statistics for a JSP home page Monitor mon=Monitor Factory. start("HomePage"); Keep statistics for a DataAccess class's openConnection() method (which opens a database connection) Monitor mon=MonitorFactory.start("DataAccess.openConnection()"); Keep statistics for each user that logs into our system Monitor mon=MonitorFactory.start(getUserName()); Keep statistics for all page accesses by date. For example, "pageAccesses.05/10/02" Monitor mon=MonitorFactory.start("pageAccesses."+getTodaysDate());

3. JAMon Examples 3.a Simple Example JAMon gathers statistics for any code that comes between start() and stop() methods. In our first somewhat artificial example we will be timing how long our program sleeps when calling the Java Thread.sleep() method ten times from within a "for" loop. import com.jamonapi.*; public class MonitorTest {

The rest of the line contains summary statistics for the ten monitor calls. Considering our logic timed the sleep method 10 times with values ranging from 101 to 110 ms. the following results seem reasonable. Hits=10 - A hit occurs whenever the start() method is called with an identical label. In this case "myFirstMonitor" is the monitor label. Avg =106 ms. - Average is the total execution time divided by hits (i.e., Total/Hits). Total=1,062 ms. - Total represents the total accumulated time for all 10 monitors that were executed. If we add 101 through 110 we get 1,055 ms., which is close to the total time the monitor calculated. The sleep() method is approximate, so our total is not exactly 1,055 ms. Min=100 ms. - Min is the minimum execution time for the 10 hits. Max =111 ms. - Max is the maximum execution time for the 10 hits. Active=0 - The "Active" statistics have meaning in a multi-threaded environment. It indicates the number of current simultaneously executing monitors with identical monitor labels. This information could be used in a JSP to tell how many users are currently executing a page. In our example all monitors have been stopped prior to calling toString(), so no monitors are active. Avg Active=1 - Average active indicates the average number of simultaneously executing monitors with identical monitor labels. In our single threaded example we would expect this to be one. Max Active=1 - Max active indicates the maximum number of simultaneously executing monitors with identical monitor labels. First Access=5/2/02 10:11:48 AM - Indicates when the monitor with the given monitor label was first executed. Last Access=5/2/02 10:11:49 AM - Indicates when the monitor with the given monitor label was last executed.

3.b Monitoring a Servlet - Gathering page statistics In our second example we will use JAMon to gather page statistics for a servlet. To gather page statistics a developer places a start() at the top of the servlets doGet() or doPost() method, and a stop() in the finally clause. If a method that can throw an exception is being monitored, then the stop() method must be called from the method's finally clause. This ensures that the monitor is stopped when an exception is thrown. The sample servlet doesn't do much. It simply returns a list of musicians from three legendary reggae groups (Sample Output). The servlet sleeps for three seconds which slows down processing enough to get simultaneous servlet instances running. The getMusicians() method sleeps an amount based on the number of servlet instances currently running. This will help in demonstrating how JAMon can be used to measure application scalability. The statistics generated by this example will be discussed in the next section. The code for the example follows: import javax.servlet.; import javax.servlet.http.; import java.io.; import java.util.; import java.text.; import com.jamonapi.; public class JAMonDemo extends javax.servlet.http.HttpServlet { private static int active; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// Returns date as a string in 05/10/02 format. private String getDate() { return DateFormat.getDateInstance(DateFormat.SHORT).format(new Date()); } /* Replace the standard "." separated ip address with one separated by dashes. i.e., 111.222.333.444 becomes 111-222-333-444. This is done because "." has special meaning to the monitor class and will consume more resources. However this is not required. */ private String getFormattedIP(HttpServletRequest request) { String ip=request.getRemoteAddr(); if (ip==null || "".equals(ip)) return ""; else return ip.replace('.', '-'); } private String getMusicians(String group) throws Exception { Monitor mon=MonitorFactory.start("JAMonDemo.getMusicians("+group+")");

final String culture="Joseph Hill, Albert Walker, Kenneth Dayes"; final String maytals="Toots Hibbert, Raleigh Gordon, Jerry Matthias,"+ " Jackie Jackson, Winston Wright, Hux Brown, Rad Bryan, "+ "Paul Douglas, Winston Grennan"; final String wailers="Bob Marley, Peter Tosh, Bunny Wailer, "+ "Junior Braithwaite, Beverly Kelso"; String musicians=null; if ("Culture".equals(group)) musicians=""+group+""+" - "+culture; else if ("Maytals".equals(group)) musicians=""+group+""+" - "+maytals; else if ("Wailers".equals(group)) musicians=""+group+""+" - "+wailers; Thread.sleep(active*50); mon.stop(); return musicians; } }

enough detail in the previous example and won't be covered here: monitor label, hits, average, total, minimum, maximum, first access and last access. We will be referring to the JAMon report in the following text (note sorting will only work when viewing the JAMon report from JAMonAdmin.jsp). Looking at "JAMonDemo.pageHits" JAMon report entry we can see that the servlet had 30 page hits taking on average 3,441 ms. Some other statistics that require further discussion follow: Std Dev ms. - 208 ms. - This is the standard deviation for the execution time of the 30 hits. If the statistical distribution is a normal distribution then we would expect 68% of the our hits to be within one standard deviation of the average, and 95% of our hits to be within two standard deviations. Active - 0 - Indicates the number of monitors with this label that are currently executing (i.e., "Active" indicates concurrency). In the example when the JAMon report was run, no users were waiting for the JAMonDemo servlet to return, so "Active" was 0. However, if five requests were currently being handled by the servlet then the "Active" value would be 5. Avg Active - 2.8 - Indicates the average number of monitors with this label that were simultaneously executing. In this example, of the 30 page hits, there were on average 2. simultaneously executing pages. Max Active - 5 - Indicates the maximum number of monitors with this label that were simultaneously executing. In this example, of the 30 page hits, the most that were executing simultaneously was 5. Note the JAMon report in JAMonAdmin.jsp can be sorted by clicking column headers. Clicking will toggle between ascending and descending sorts, based on column values. An up arrow indicates ascending, and a down arrow indicates descending.

4.b Measuring outliers (JAMon Time Ranges) A problem with the statistics previously mentioned is that they hide extreme data points (i.e., outliers). When application performance degrades we become more interested in outliers. JAMon time ranges contain information about these outliers. Ideally we would like the average time for a monitor to be close to its minimum. However many factors (such as number of simultaneous users) can cause performance degradation. For example, we would expect our servlet to respond faster with two simultaneous requests than with 5,000. There are 13 JAMon time ranges. The ranges are measured on an exponential scale. The first range is from 0 to 10 ms., and subsequent ranges double, until the final range, which includes values greater than 20,480 ms. We will use the JAMon report entry "JAMonDemo.getMusicians(Wailers)" and its "81-160ms." time range to discuss the five time range variables. The time range values are "7/114 (1/2.3/7.9)". Hits - The number of hits within the given time range. All time range hits sum to the total hits for the JAMon report entry. The value for hits in the example is 7. This means that of this report entries 30 hits, 7 of them fell in the "81-160ms." range and averaged 114 ms. Average - The average time in ms. for all hits within the given range. (see Hits for further info). (Avg Active/Primary Active/Global Active) - All three of the time range "Active" statistics provide information about application scalability, by correlating application performance to monitors that are currently running. When a monitor is started the various active values are increased by one (based on the rules specified below) and when a monitor is stopped the active values are decremented by one. In general we expect performance to degrade with increasing activity. The time range "Active" statistics are all averages. Avg Active - Indicates how many monitors with this label were on average "Active" when a hit occurred within the given time range. This allows us to correlate performance of this monitor to itself. This is similar to the "Avg Active" entry that comes earlier in the report. The difference is that this average is only for the hits that occur within this time range. In our example for the 7

Notice how performance is decreasing with an increased number of global active monitors: 41-80ms. - When hits were within this time range there was an average of 4 monitors active. 81-160ms. - When hits were within this time range there was an average of 7.9 monitors active. 161-320ms. - When hits were within this time range there was an average of 13.4 monitors active. Measuring "Primary Active" has an advantage over "Global Active". If we start monitoring more things then "Global Active" will artificially increase. In the above example if we decided to monitor "JAMonDemo.pageHits.UsersIPAddress.Month/Day/Year" then all of the "Global Active" variables discussed above would increase even though there is really no more activity on the server. This is not true of "Primary Active". To summarize the concept of "Active" monitors let's look at another example. If the following code were executed there would be six active global monitors, two active primary monitors, two active monitors for "mon1", and one active monitor for all of the other monitors. MonitorFactory.start("mon1"); // 1 global MonitorFactory.start("mon2"); // 2 global MonitorFactory.start("mon3"); // 3 global MonitorFactory.startPrimary("mon4"); // 4 global, 1 primary MonitorFactory.start("mon1"); // 5 global, 1 primary, and 2 mon1's are active MonitorFactory.startPrimary("mon5"); // 6 global, 2 primary 4.c Controlling JAMon The JAMonAdmin.jsp page also allows a developer to control JAMon at runtime. A description of the function of each of the buttons follows:

Refresh - Redisplays JAMonAdmin.jsp with the JAMon report in the default sort order. Refreshing can also be accomplished by clicking a column header. Reset - Clears all monitors and their statistics. The report will now be empty, and subsequent calls to the start() method will repopulate JAMon statistics. Enable and Disable - JAMon can be enabled and disabled at runtime.

5. Ways to use JAMon - More than performance This section discusses the various ways JAMon can be used. JAMon's most obvious use is in determining application performance bottlenecks by gathering timing statistics. However, it can also be used in other ways such as determining how users interact with an application, and determining application scalability. Some ways that JAMon can be used follow. To tune performance - Web applications can be difficult to tune due to the fact that there are many possible bottlenecks including: network IO, database IO, application code, poorly tuned queries, or even an increased amount of site traffic. To help pinpoint problems, performance diagnostics must be built into the application. Without performance measurements, developers will spend their time guessing where performance bottlenecks occur. Performance problems typically occur in a small percentage of overall code. Algorithm guru Donald Knuth estimated that 4% of application code accounts for 50% of the performance. With measurements, developers can quickly locate that 4% of the code and get the biggest bang for their tuning buck. Without measurements developers waste effort tuning code that may have no significant impact on performance. To improve code design - "More computing sins are committed in the name of efficiency than for any other single reason-including blind stupidity" - W.A. Wulf "...premature optimization is the root of all evil." - Donald Knuth Often, when discussing code designs, developers say they don't want to implement certain elegant designs, because of perceived performance problems. JAMon supports the following

Monitoring PowerBuilder Code - The sample code contains a Monitor EJB that acts as a thin wrapper for JAMon. The PowerBuilder client takes a monitor label as input and has a start and stop button. The start button passes the monitor label to the EJB and the stop button stops the Monitor. JAMon.jar must be accessible to the EJB at runtime. ColdFusion sample BroadVision sample I will continue to add sample code to this document.

8. Downloading JAMon Click here to download JAMon jar, which contains the JAMon API (approximately 90K). Click here to download all of JAMon (approximately 225K). This download contains: JAMon.jar - Contains the JAMon binary (same as download above) JAMon.war - A sample Java Web Application that uses JAMon. The WAR can be installed in any J2EE compliant application server. The WAR contains a servlet that generates monitoring statistics (/JAMon/JAMonDemo), and a JSP that allows us to look at the statistics (/JAMon/JAMonAdmin.jsp). 9. JAMon License Agreement JAMon has a very liberal license agreement. JAMon binaries can be used free of charge, and JAMon source code may be modified. The JAMon License was adapted from the BSD license. It is requested that any modifications developers make to JAMon be sent to [email protected] , so that all JAMon users may benefit. 10. About the Author Steve Souza is a senior consultant working for Sybase Professional Services in support of the General Services Administration (GSA) in Arlington, VA. He has 20 years of software and

database development experience. Please send any questions or comments concerning JAMon to [email protected]. I'd like to thank Ed Desrosiers for his help in designing JAMon, and Eric Laufer for his help in designing the JAMon report and converting this article to HTML.

Once installed, the module adds the Profile menu item to the menu bar. The Profile menu allows you to start profiling and work with the results. The module also adds two toolbar buttons that are shortcuts to the Profile command ( ) and the Attach and Profile command ( ). Related Products The NetBeans IDE is the base product on which Sun Java Studio Enterprise (JSE) is built. JSE also offers profiling features. Getting Started The NetBeans Profiler provides a number of internal settings that let you tune profiling to your needs. For example, you may decrease the profiling overhead at the cost of some reduction in the amount of generated information. However, it may take some time to understand the meaning and use of the numerous settings available in the NetBeans Profiler. For most applications, certain default settings are sufficient. For this reason, the NetBeans Profiler offers two major profiling options. You can start profiling by choosing a simple predefined profiling task, which has most of the settings preset to optimal values and therefore requires little or no tuning. Alternatively, you can create your own custom profiling configuration, where you are free to modify any of the available settings. To start profiling an application: Open your project in the NetBeans IDE. Right-click your project's entry in the Projects window and then select Set Main Project. Choose Profile > Profile Main Project from the main menu. Choose a profiling command from the list in the Select Profiling Task dialog box. Click Run. When you click Run, the target application launches and the selected profiling command starts. The NetBeans Profiler control panel opens in the IDE.

To see the results of the profiling command, click the Live Results button ( ) in the Profiler control panel to open the Profiling Results tab. To stop the profiling command, choose Profile > Stop from the Profile menu or click the Stop button ( ). If you start the application with the NetBeans Profiler, when you stop the profiling command the application also stops.

Profiling Tasks

The Select Profiling Task dialog box is the main interface for selecting and running profiles. The dialog box gives you five different ways of profiling the target application. The first four are predefined profiling commands. The last command, Run Custom Profiling, allows you to create your own custom profiling configuration.