views:

40

answers:

1

I had an argument today with one of my teacher where he was saying CGI was always slower than Servlet. I told him that performance was subjective and in some situation CGI could perform better than Servlet. He insisted on getting example of when CGI could be faster than Servlet. I just want to know what would be the most solid thing I could come up with to counter the "Servlet is always faster than CGI".

A: 

Performance is not subjective. Go look up the word.

Now, to answer your question, a CGI will be faster than a servlet when the time to execute the Java code of the servlet takes long enough that the time to load and execute the CGI program is dominated by the time the Java program runs. So, for example, if you had a CGI program in C that had

 main(){ return; }

and you compared that with a servlet, it might well be faster.

What you want to do is set up a servlet container and a CGI directory and actually monitor and measure some comparitive performance.

Charlie Martin
I doubt that even this would be faster. You need to fork() and exec(). Compare this to processing a request on a thread that is most likely already spawn. Maybe FastCGI could win in some cases but not plain-old CGI.
gawi
It really depends on the setup. As you say, fork/exec might make the difference, but then you might also be running fastCGI so the fork./exec time is eliminated. Going the other direction, if the JVM has to swap anything significant to handle the request, that could be much more time than fork/exec. The point is that **performance is not subjective**. If you want to know which is faster, *measure*.
Charlie Martin