This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Time Measurment for a servlet's performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Time Measurment for a servlet Watch "Time Measurment for a servlet New topic
Author

Time Measurment for a servlet's performance

Pourang Emami
Ranch Hand

Joined: Sep 21, 2002
Posts: 127
Hi
How can we get the time a servlet get a request, and the time when servlet finishes (so that by subtracting them we get the elapsed time for what was've done inside the servlet)?
is there any method like onStart and onEnd so that we can capture these times inside them?
Thank's.
Pourang


Best Regards,<br />Pourang Emami
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 860
Check out JAMon. With code like the following in your servlet you can have a nice HTML report that gives you what you are after. It tracks page hits, average time, max time, min time and more.

steve - http://www.jamonapi.com - a fast, free performance monitoring API.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Pourang Emami
Ranch Hand

Joined: Sep 21, 2002
Posts: 127
Dear Steve
In advanced, I'd like to appreciate you for replying to my question. After considering your technical bio I should tell it was an absolute honor for me to get my answer from a real pro like you.
Best Regards,
Pourang Emami
Ravi Kumar Ravuru
Ranch Hand

Joined: Apr 18, 2002
Posts: 176
Hello Pourang Emami,
At the start of your servlet,use System.currentTimeMillis() which returns long and at the end of it,use the same method and subtract the both,u will get the time taken by the servlet to serve the request.Hope it will help u.
Regards,
Ravi
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 860
JAMon and System.currentTimeMillis() are similar, but JAMon offers many advantages over the latter. First of all the timings using currentTimeMillis() are stuck in your application. Of course you can write them to a log or display them, but what about average, min and max times. Also, what if you want to measure many things such as every one of your pages, database connections, session times, and more. After a while looking through a log to collect these various times becomes a burden, if you are lucky enough to have access to your applications logs.
One surprising advantage of JAMon is that it is easier to use than currentTimeMillis().
Remembering start() and stop() is easier than creating a start time and end time and subtracting them. With JAMon just get the 90K Jar in your classpath and start making calls. Within minutes you will have your numbers.
Good luck. Let me know how it works out.
steve - http://www.jamonapi.com
Pourang Emami
Ranch Hand

Joined: Sep 21, 2002
Posts: 127
Hi my friends
Actually at first I tried
GregorianCalendar Cal1 = new GregorianCalendar();
long t1 = Cal1.getTime().getTime();
instead of
System.currentTimeMillis()
in a very simple typical servlet that just generated a html page containig some simple text like "Hello World" .
I put "long t1 = Cal1.getTime().getTime();"
before the codes generating the html and another one after it(had both them printed on the console for checking purpose), but I got "t1 - t2 = 0". The servlet first generated the html and after that I would get t1 , t2 printed on the console at the same time so the subtraction was 0?
But with System.currentTimeMillis() and JAMon I got the desired result. I am so interested to know why?
(Any way, I introduced JAMon to my co-workers because I think Steve has done a very good job on it.)
Best Regards,
Pourang
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Time Measurment for a servlet's performance
 
Similar Threads
load-on-startup
agents as servlets
final with static
necessity to provide servlet name and url-pattern for each servlet in web.xml
use of init() in servlet life cycle