使用java获取客户端连接速度的最佳方法
我想知道使用 Java 计算客户端下载速度的最佳方法是什么。 我在互联网上搜索过,发现我必须从服务器下载一个文件并计算下载完成之前和之后的时间,并使其更具体 - 重复此操作 3 次,以便我可以得到平均时间。 对我来说,上面的问题效果不好,对于本地主机,我得到的结果可以说接近现实,但从服务器来看,结果要低得多。我制作了一个充满js,css(我想测试的大小)的页面,在输入从扩展Action类(使用struts)计算startDate之前,在“onLoad()”事件上我做了一个ajax提交,其中我得到了 endDate.StartDate-EndDate 给了我时间...我忘了提及,我还设置了我的 jsp 页面不被缓存。 您知道其他解决方案吗?
谢谢,
路易莎
I want to know what is the best way to calculate the download speed of the clients using Java.
I have searched on the internet and found that I have to download a file from the server and calculate the time before and after the download completes and to make it more specific - repeat this action for 3 times so I can have an average time.
For me, the problem above doesn't work well, for localhost I got the results let's say close to reality but from server the results are a lot lower. I made a page filled with js,css(the size that I want to test), before enters calculate the startDate from the extended Action class(using struts) and on the 'onLoad()' event I made an ajax submit in which I got the endDate.StartDate-EndDate gave me the time...I forgot to mention, I set also that my jsp page isn't cached.
Do you know other solutions?
Thanks,
Luisa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Linux 上,您只需从命令行运行以下命令即可。
这将为您提供 GET 请求的“实际”时间。当然,这只是为您提供获取页面内容所需的时间。它不会告诉您加载页面引入的任何图像、样式表、脚本等的时间,或者渲染页面或执行任何嵌入的 javascript 所需的时间。
您以前的方法实际上可能给您带来了真实的结果。通过“localhost”进行访问比远程访问更快的情况并不罕见,尤其是在从客户端到服务器的路径中存在缓慢的网络链接、Web 代理等的情况下。
On Linux you could just run the following from the command line.
This will give you the elapsed time for the GET request as the "real" time. Of course, this gives you just the time taken to fetch the page contents. It won't tell give you the time for loading any images, stylesheets, scripts, etc that the page pulls in, or the time taken to render the page or execute any embedded javascript.
Your previous method may actually have been giving you true results. It is not unusual for access via "localhost" to work faster than remote access, especially if there are slow network links, web proxies, etc in the route from the client to the server.