0

We are working in a Tool that measures performance of web sites in a not intrusive way (not modifying the web site source code). We have a small application in Java that fires request over the internet to our customer web sites and save the ResponseCode, LoadTime, Amount Of Bytes Loaded, etc.

One of the main metrics we measure is the TTFB. I wonder if we are doing that the right way.

We do a HttpURLConnection and save the difference of two time stamps as TTFB like bellow.

Calendar before = Calendar.getInstance();

HttpURLConnection connection = (HttpURLConnection)new URL( url ).openConnection();
connection.getResponseCode();

Calendar end = Calendar.getInstance();

//read the content

Calendar endContent = Calendar.GetInstance();

long TTFB = end.getTimeInMillis() - before().getTimeInMillis();
long justLoadTime = endContent.getTimeInMillis() - end.getTimeInMillis();

It is correct? Getting the time till ResponseCode is the TTFB? Or until that some bytes of content already arrived?

Is there more easy way to get these information?

Not in rare times, the difference between TTFB and justLoadTime is so small, in heavy weight pages.

Marcelo Dias
  • 409
  • 2
  • 18
  • 1
    Using `Calender` is non-sense here; it's complicated heavyweight object where `System.currentTimeMillis()` would do. Even much better would be `nanoTime()`. – maaartinus Feb 20 '14 at 16:51

1 Answers1

0

I'm not sure you can get an accurate measure with Http Url connection. This sounds something much lower level and you probably need socket programming. The first byte that arrives will be a single TCP packet. Operating at HTTP level you would have likely received multiple packets already. So maybe clarify what "first byte" means for your metric.

codesalsa
  • 882
  • 5
  • 18
  • I'm actually afraid of having to go down the layers to socket programming. The tool was almost finished when the TTFB feature came to the project. So, a change in the architecture like that would be a nightmare. A high level tool, like Apache Http Client, that comes with this feature would be a better option to us. But I don't know such tool. – Marcelo Dias Feb 20 '14 at 17:38
  • We if you really care about when you got your "first byte" then you have to look lower in the stack. – codesalsa Feb 20 '14 at 21:25