473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

calculating the response time of different sites

freddieMaize
Hi there,

I need to hit few list of sites from my application and find the response time of those site and sort them (which ever is opening first will sit at the top). I have done the same using java (server side). Now my requirement is do in the client side (AJAX possibly). I’m having two challenges. Below is what I have done so far,

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script>
  3. function call()
  4. {   
  5.     var d = new Date();
  6.     var xmlHttp;
  7.                 try
  8.                 {  // Firefox, Opera 8.0+, Safari 
  9.                     xmlHttp=new XMLHttpRequest();
  10.                 }
  11.                 catch (e)
  12.                 {  // Internet Explorer  
  13.                     try
  14.                     {    
  15.                         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  
  16.                     }
  17.                     catch (e)
  18.                     {   
  19.                         try
  20.                         {     
  21.                             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");   
  22.                         }
  23.                         catch (e)
  24.                         {    
  25.                             alert("Your browser does not support AJAX!");   
  26.                             return false;    
  27.                         } 
  28.                     } 
  29.                 }
  30.                 xmlHttp.onreadystatechange=function()
  31.                 {
  32.                     if(xmlHttp.readyState==4)
  33.                         {       
  34.                             alert(xmlHttp.responseText);
  35.                            /* if(xmlHttp.responseText != undefined);
  36.                             var res_min = d.getMinutes();
  37.                             var res_sec = d.getSeconds();
  38.                             var res_time = res_min*60+res_sec;
  39.                             alert(res_time);
  40. response_time=res_time-req_time*/                      
  41.                         }
  42.                     }                        
  43.  
  44.                         var req_min = d.getMinutes();
  45.                         var req_sec = d.getSeconds();
  46.                         var req_time = req_min*60+req_sec;
  47.                         alert(req_time);
  48.  
  49.                     var url="http://localhost:8080/";
  50.                    // url=url+"?q="+q;
  51.                     xmlHttp.open("GET",url,true);
  52.                     xmlHttp.send(); 
  53.  
  54. }
  55. </script> 
Challenge 1: I’m using “var url="http://localhost:8080/";” because I’m unable to use urls of google, yahoo or bytes here. Getting “Access Denied” error. Cross domain scripting is not possible here.

So, any clues on cross domain scripting/proxy??

Challenge 2: “if(xmlHttp.readyState==4)”. Inside this function I get the responseText. Now all I want is, a way to find whether the url is responding or not (getting opened or not).
Reason: only if I know whether the site is accessible, (and if yes, how long?) I can proceed (since I’m calculating the response time here… like I have mentioned on the top).

I believe I have briefed my issue as much as possible. If it’s still not complete, kindly tell me on which part should I further explain. Thank you.

fREDDIE
Sep 18 '08 #1
10 5206
acoder
16,027 Expert Mod 8TB
If you've already solved this with Java on the server-side, call that script instead passing the URL and the response should be the response time. From that, you can sort the list.
Sep 18 '08 #2
Hi acoder,

If you've already solved this with Java on the server-side, call that script instead passing the URL and the response should be the response time. From that, you can sort the list.
:)... The thing is, I want to finish off everthing in the client side in this regards. This must no way be a concern/workof for a java class. So no java and servlet stuffs are allowed...

The reason is, calling a java/servlet class will take time which must be avoided.
I mean, the time between the jsp->java->jsp cycle can be avoided if we use Ajax. This could be effective i believe (i mean, doing on the client side).

fREDDIE
Sep 18 '08 #3
acoder
16,027 Expert Mod 8TB
I'm not saying not to use Ajax. What I suggested was that you call the JSP page via Ajax/XmlHttp.
Sep 18 '08 #4
I'm not saying not to use Ajax. What I suggested was that you call the JSP page via Ajax/XmlHttp.
Yeah. That is also one way of doing it. But at the end of the day when a jsp page gets compiled it is going to be a java/servlet class only right, which is want I wanted to avoid.
All I’m trying is to do is to finish of the whole stuff in a single jsp/html page. The control must not go to else where.
Sep 19 '08 #5
acoder
16,027 Expert Mod 8TB
In that case, create a new Date object - this will default to the current date/time to the millisecond. When finished, create another one and compare the two.
Sep 19 '08 #6
Yeah the same is what I have planned to do. Something like
Expand|Select|Wrap|Line Numbers
  1. result= response time-request time.
Okay, I ll brief it out again.

I request to open a site (using, “xmlHttp.open("GET",url,true);”) and I find the request time mean while. (The challenge here in this step is, I’m unable to call url’s like http://freddiemaize.wordpress.com which is a external domain. JavaScript doesn’t support cross domain scripting right?).
Sep 20 '08 #7
acoder
16,027 Expert Mod 8TB
For that you will have to use a proxy which is basically some server-side code which makes the request and passes back the response to the client. In effect, we're back to my earlier suggestion. It is possible to make cross-domain requests if you give privileges in a specific browser, but that would only work in one browser.
Sep 20 '08 #8
Hi fREDDIE,
you mentioned that u calculated server's response time in java... cud u tell me how to do so? i'm relatively new to java n need this urgently for my college project submission...
Oct 14 '08 #9
acoder
16,027 Expert Mod 8TB
Hi priyal, welcome to Bytes!

I would suggest you start a new thread for your question in the Java forum.
Oct 14 '08 #10
Hi fREDDIE,
you mentioned that u calculated server's response time in java... cud u tell me how to do so? i'm relatively new to java n need this urgently for my college project submission...
Hi Priyal,
Kindly let me know what you have done so far so as to help you out.

What I did was, I noted the system time, then established a connection to a site (say, http://google.com), got its contentType, checked if its not null, if yes then once again noted the system time, found the difference between the two system times which would apparently be the response time.

Hope this helps
Post back for any further questions

fREDDIE
Oct 15 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ron Adam | last post by:
Hi, I'm having fun learning Python and want to say thanks to everyone here for a great programming language. Below is my first Python program (not my first program) and I'd apreciate any...
9
by: Rick Cook | last post by:
I would like to do a response form on one of my sites instead of posting an e-mail address for spammers. I've taken a couple of examples from sites, but the code looks clunky and non-conformant to...
3
by: Miller | last post by:
Hi, Can someone tell me how to calculate MFLOPS for the following C# code (on a Pentium 4 2.0 Ghz)? for (i=0; i<n; i++) { for (j=0; j<n; j++) { for (k=0; k<n; k++)
4
by: Vito DeCarlo | last post by:
Over the past week, I've been noticing that any websites (on this one particular web server) built with ASP.NET have unusually slow (5 second) response times when moving through the site. There...
20
by: Jean Johnson | last post by:
Hello - I have a start and end time that is written using the following: time.strftime("%b %d %Y %H:%M:%S") How do I calculate the elapsed time? JJ
2
by: deisner | last post by:
All- I have a Framework 2.0 application running under Windows 2003 Server and IIS utilizing the default application pool. On my development machine (XP w/ IIS 5.1) the code runs perfectly. But...
1
by: badger_nz | last post by:
Hi all, I recently opened an account with a USA-based hosting company. I'm new to the world of hosting providers, and I have a question regarding performance that I'm hoping somebody here can...
23
by: mosesdinakaran | last post by:
Hi All, I need a small clarification in submitting the forms, Ur suggestions please. In a page I have two form and also two submit butons. (ie)
3
by: mfaisalwarraich | last post by:
Hi everybody. I have some problem while calculating time. i have employees who are working on hourly basis. i want to calculate the time. for example if an employee start working at 11:00pm...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.