views:

163

answers:

3

Hi,

I noticed that my app is very slow sometimes, so I've done some tests. It's a very simple web app. One servlet gets some parameters than stores them. Everything's fine except one thing. It takes too long to get a parameter for the first time. It doesn't matter which parameter I try to get, but for the first time it is very slow. The strange thing is this doesn't happen always. Sometimes getting a parameter for the first time is not slow.

My code looks like this

request.getParameter("paramName");
request.getParameter("paramName2");
request.getParameter("paramName3");

Getting "paramName" is slow. Getting the others is very fast.

By slow I mean : 200-800 millisec By very fast I mean: ~0 millisec (in the code snippet, I didn't write the performance test, but I'm using System.currentTimeMillis())

UPDATE

I've exported my project into a .WAR file, and deployed it to Tomcat. Everything's fine. So I think this problem is related to Eclipse or something.

+1  A: 

I suspect that the parameters may be parsed lazily - when you first ask for a parameter, it may parse everything, storing them for efficient access later.

However, 200ms sounds like an awfully long time... is this when you're running under a debugger?

Of course, this is entirely dependent on your servlet container.

Jon Skeet
No, I'm not debugging. I'm using Tomcat 6 with Eclipse. Just press "run on server" and that's all. It's very strange, and I just don't get it. 200ms sounds awfully long, but usually it is 600 or even 800
Bob
@Bob: If this only happens for the first request, it may be JIT compiling a lot of code. If it happens for *every* request, I suspect there's something wrong with your performance measurements - or that you're running on a 486 :) Seriously, if Tomcat took 600ms (or even just 200ms) to parse request parameters, it would be unusable for any serious deployment.
Jon Skeet
A: 

Do you have enough memory? You need a lot when working with Eclipse and a deployment server, and it Sounds like swapping.

Thorbjørn Ravn Andersen
I've got 4GB in my computer, and I've set the VM params like this: -Xms1024M -Xmx1024M.
Bob
A: 

Sounds like a bug in Eclipse's builtin webbrowser that it doesn't send the Content-Length header correctly. I can't tell from experience as I've never used it seriously. I always deploy the project to the integrated Tomcat or Glassfish, start it and then just open the page in a real webbrowser (Firefox, Chrome, Safari, IE, etc, which you run independently from Eclipse). This has the major benefit that you can use any of the browser's plugins and addons which can greatly ease development such as Firebug and consorts.

If you insist in using the webbrowser inside Eclipse, try changing the webbrowser used by going to Window > Web Browser and choosing other than Internal Web Browser.

BalusC