我们正在开发一种以非侵入性方式(不修改网站源代码)测量网站性能的工具。我们有一个 Java 小应用程序,它通过 Internet 向我们的客户网站发出请求,并保存 ResponseCode、LoadTime、Amount Of Bytes Loaded 等。
我们衡量的主要指标之一是 TTFB。我想知道我们这样做是否正确。
我们做一个 HttpURLConnection 并将两个时间戳的差异保存为 TTFB,如下所示。
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();
它是正确的?等待 ResponseCode 成为 TTFB 的时间?或者直到一些字节的内容已经到达?
有没有更简单的方法来获取这些信息?
不是在极少数情况下,TTFB 和 justLoadTime 之间的差异很小,在重量级页面中。