File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Servlet or Jsp Performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet or Jsp Performance" Watch "Servlet or Jsp Performance" New topic
Author

Servlet or Jsp Performance

Deepa Balasubramanayam
Ranch Hand

Joined: Mar 29, 2001
Posts: 39
Hi,
I coded programs in both servlets and jsp. I want to know which one is performance wise good.
Deepa.
------------------
Ganapathi Srinivasan
Ranch Hand

Joined: Apr 18, 2001
Posts: 41
Hi...
Basically what u r asking is a classic trade off and is solely dependant on how u design ur page.
If there are lots of HTML markup code it is advisable for using JSPs while having the fact that there are not much of complicated JAVA code in the same. But in case if ur program has more of complicated JAVA logic in place, it is advisable to go for servlets. Whereas if it is like a loop around the HTML tags to generate output in a loop, you can always go for a simple JSP that does the job.
But performance wise I do not see any difference in servlets and JSPs. The reason being that any JSP engine ultimately generates a servlet code for the JSP and then only executes requests. So inherently JSPs are servlets whose code are generated by the JSP engine.
Regards,
Ganp.
Deepa Balasubramanayam
Ranch Hand

Joined: Mar 29, 2001
Posts: 39
Thanks Ganapathi,
I have one more question. In servlet we are compiling and creating the class file and each time when the servlet is called the class file runs.But in the case of jsp We are not compiling. I have a doubt that each time when we call jsp whether the jsp code will compile and run,if so the performance will be low right?
Thanks
Deepa

Originally posted by Ganapathi Raman:
Hi...
Basically what u r asking is a classic trade off and is solely dependant on how u design ur page.
If there are lots of HTML markup code it is advisable for using JSPs while having the fact that there are not much of complicated JAVA code in the same. But in case if ur program has more of complicated JAVA logic in place, it is advisable to go for servlets. Whereas if it is like a loop around the HTML tags to generate output in a loop, you can always go for a simple JSP that does the job.
But performance wise I do not see any difference in servlets and JSPs. The reason being that any JSP engine ultimately generates a servlet code for the JSP and then only executes requests. So inherently JSPs are servlets whose code are generated by the JSP engine.
Regards,
Ganp.


------------------
bob walker
Greenhorn

Joined: Feb 20, 2001
Posts: 14
IMHO, you have no tradeoff.
JSP allows the developer to separate the UI from the logic where
generating the UI in a servlet is tedious and error prone.
You can have a JSP and a servlet generate identical pages and you
will have no noticeable difference in execute time EXCEPT the
first time a JSP is referenced.
The first time a JSP is referenced, it is compiled into a
servlet. Subsequent executions of the JSP hit the servlet
UNLESS a new version of the JSP has been deployed in which
case it is recompiled.
Basically, no difference unless the JSP is being compiled.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
If we dig deep into details, there is a difference in performance with respect to servlets and jsps. Jsps use the implicit object "out" which is of type JSPWriter designed to accomodate unicode chars.
Using servlets, if you choose to use respose.getInputStream() and write all htmls, then there will be significant performance difference.
Even I also was thinking both servlets and jsps performance are same. But recently, when I bought this book "Performance techniques-Servler side programming" by Bulka and read, the author benchmarked the difference. I don't remember exactly how much difference in %wise. But it is significant for a huge page.
So if your page is VERY HUGE in size, and has lots of hits, and the presentation foramt doesn't change very often, and perforamance is big problem, then you may want to re-write that particular jsp alone as servlets. (remember to use response.getInputStream() instead of getWriter() )

regds
maha anna
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Originally posted by maha anna:
(remember to use response.getInputStream() instead of getWriter() )

may be typo error..response.getInputStream()is supposed to be response.getOutputStream() right...

SCJP 1.5, SCEA, ICED (287,484,486)
Ganapathi Srinivasan
Ranch Hand

Joined: Apr 18, 2001
Posts: 41
Hi deepa
I agree with bob...
The first time a JSP is called, it is compiled and sometime it takes an awful amount of time esp when ur JSP is bulky. But subsequent calls to JSPs do not compile it unless u have a changed JSP in the server.
Thanks and Regards,
Ganp.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
And also remember that some servlet containers will also compile your servlets for you if you want. I use Resin, and I can just deploy my servlet source files to the server and they will be compiled and run the first time they are called, just like a JSP.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Anil,
Yes. Yes. You are right. That is a typo indeed.
regds
maha anna
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet or Jsp Performance