• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet or Jsp Performance

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I coded programs in both servlets and jsp. I want to know which one is performance wise good.
Deepa.
------------------
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



------------------
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Ganapathi Srinivasan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anil,
Yes. Yes. You are right. That is a typo indeed.
regds
maha anna
 
reply
    Bookmark Topic Watch Topic
  • New Topic