0

We have an application which is using an embedded tomcat version 7.0.32. I am observing a peculiar situation with respect to latency.

I am doing some load tests on the application, what i have observed is the very first request to tomcat takes quite some amount of time, e.g. rate of about 300+ ms. Subsequent requests take about 10-15ms.

I am using a BIO connector. I know that persistent connections are used since i am using HTTP 1.1, which has that support by default. So ideally only 1 TCP connection is created and all request pushed on the same connection, till the keep alive timeout is elapsed.

I get the creating a TCP connection will have some costs involved, but the difference is just large.

Any idea what could be causing this huge difference in latency between the 1st and subsequent request and can we do anything to reduce/eliminate it.

Thanks,

Vikram

Victor
  • 1,207
  • 2
  • 13
  • 21
  • What is the first request. Are trying to load a page or doing any authentication or authorization? – karthick Jun 26 '13 at 12:20
  • 3
    Or could it be that JSPs are being compiled into servlets, and servlets compiled into .class files? You can precompile your JSPs and see if it goes away. – duffymo Jun 26 '13 at 12:25
  • No JSP used, just plain http servlets. No DB call either. Just a simple post with JSON data, the servlet reads the data and responds back with the same request data. – Victor Jun 27 '13 at 03:49

1 Answers1

0

If you are using JSPs, they are compiled.

If you are connecting to databases, the connection pool might be empty before. Generally speaking, if you have singletons which are initialized lazily, the first request has to wait.

On top of this, the JIT plays its role: So after the first request, the JIT might have applied some optimizations.

If it is a load test (or perfomance test), I would just ignore the first requests/runs, because this is still the "warm up" phase.

Update

You might find the information regarding a micro benchmark interesting.

Community
  • 1
  • 1
Beryllium
  • 12,808
  • 10
  • 56
  • 86
  • No JSP used, simple http servlets. It a simple http post with JSON data. For testing purpose, i am just reading the data and sending the same one back as part of the response. – Victor Jun 27 '13 at 03:48