calculating the response time of different sites

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • freddieMaize
    New Member
    • Aug 2008
    • 85

    calculating the response time of different sites

    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,

    Code:
     
    <script>
    function call()
    {   
    	var d = new Date();
        var xmlHttp;
                    try
                    {  // Firefox, Opera 8.0+, Safari 
                        xmlHttp=new XMLHttpRequest();
                    }
                    catch (e)
                    {  // Internet Explorer  
                        try
                        {    
                            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  
                        }
                        catch (e)
                        {   
                            try
                            {     
                                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");   
                            }
                            catch (e)
                            {    
                                alert("Your browser does not support AJAX!");   
                                return false;    
                            } 
                        } 
                    }
                    xmlHttp.onreadystatechange=function()
                    {
                        if(xmlHttp.readyState==4)
                            {       
    							alert(xmlHttp.responseText);
                               /* if(xmlHttp.responseText != undefined);
    							var res_min = d.getMinutes();
    							var res_sec = d.getSeconds();
    							var res_time = res_min*60+res_sec;
    							alert(res_time);
    response_time=res_time-req_time*/                      
                            }
                        }						
    
    						var req_min = d.getMinutes();
    						var req_sec = d.getSeconds();
    						var req_time = req_min*60+req_sec;
    						alert(req_time);
    
                        var url="http://localhost:8080/";
                       // url=url+"?q="+q;
                        xmlHttp.open("GET",url,true);
                        xmlHttp.send(); 
                        
    }
    </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.rea dyState==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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.

    Comment

    • freddieMaize
      New Member
      • Aug 2008
      • 85

      #3
      Hi acoder,

      Originally posted by 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

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        I'm not saying not to use Ajax. What I suggested was that you call the JSP page via Ajax/XmlHttp.

        Comment

        • freddieMaize
          New Member
          • Aug 2008
          • 85

          #5
          Originally posted by acoder
          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.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            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.

            Comment

            • freddieMaize
              New Member
              • Aug 2008
              • 85

              #7
              Yeah the same is what I have planned to do. Something like
              Code:
              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?).

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                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.

                Comment

                • priyalmehta
                  New Member
                  • Oct 2008
                  • 1

                  #9
                  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...

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Hi priyal, welcome to Bytes!

                    I would suggest you start a new thread for your question in the Java forum.

                    Comment

                    • freddieMaize
                      New Member
                      • Aug 2008
                      • 85

                      #11
                      Originally posted by priyalmehta
                      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

                      Comment

                      Working...