Response Time Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • only1jake
    Junior Member
    • Nov 2016
    • 29

    #1

    Response Time Query

    Hey everyone,
    I'm currently developing a program/bot for the Betfair API and have a question. I am still currently on the Delayed app key, however I was wondering about response times.

    This is my code in VB.NET:
    (Mostly taken from an example)

    Code:
    Function CreateRequest(AppKey As String, SessToken As String, postData As String)
    
    
            Dim Url As String = "https://api.betfair.com/exchange/betting/json-rpc/v1/"
            Dim request As WebRequest = Nothing
            Dim dataStream As Stream = Nothing
            Dim response As WebResponse = Nothing
            Dim strResponseStatus As String = ""
            Dim reader As StreamReader = Nothing
            Dim responseFromServer As String = ""
            Try
                Dim TimerStart As DateTime
                TimerStart = Now
                request = WebRequest.Create(New Uri(Url))
                request.Method = "POST"
                request.ContentType = "application/json-rpc"
                request.Headers.Add(HttpRequestHeader.AcceptCharset, "utf-8")
                request.Headers.Add("X-Application", AppKey)
                request.Headers.Add("X-Authentication", SessToken)
                
                Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
                
                request.ContentLength = byteArray.Length
                
                dataStream = request.GetRequestStream()
                
                dataStream.Write(byteArray, 0, byteArray.Length)
                
                dataStream.Close()
               
                response = request.GetResponse()
                
                strResponseStatus = CType(response, HttpWebResponse).StatusDescription
                
                dataStream = response.GetResponseStream()
                
                reader = New StreamReader(dataStream)
                
    
                responseFromServer = reader.ReadToEnd()
                Dim TimeSpent As System.TimeSpan
                TimeSpent = Now.Subtract(TimerStart)
                BetBotMainForm.oddschanging.Add("DL TIME: " + TimeSpent.TotalSeconds.ToString)
                
            Catch ex As Exception
                
                MsgBox("CreateRequest Error" & ex.Message)
            End Try
            Return responseFromServer   '~~> Function Output
            
            reader.Close()
            dataStream.Close()
            response.Close()
        End Function
    I'm finding using the timer its taking around 1.9 seconds to get a response from the server. I need this to be faster. Is it because I am using the delayed app key or because this is a slow method?

    Is there a way to speed things up?

    Thanks for your help!
  • gr33d
    Junior Member
    • May 2012
    • 12

    #2
    You aren't measuring the server response time in that code, you're actually measuring the time to construct the message, encode it, send it to betfair, get the response and read the response fully.

    Comment

    • only1jake
      Junior Member
      • Nov 2016
      • 29

      #3
      Reason I did it like that is because all the other actions take a relatively low time in comparison to the request.GetRequestStream(). I just get a varying response time between 0.8 and 2.0 seconds. Just seems odd and I'm wondering if its the delay key or if there is a faster way to request/receive.

      Is there a faster way to request listmarketbook for example?

      Comment

      • Mr Magoo
        Junior Member
        • Jan 2011
        • 86

        #4
        The response time might be very high if this is a new connection. Establishing a SSL connection to the server can be very time-consuming, however once this is done, you can send many API requests on the same underlying HTTPS connection.

        I don't know VB, so I've no idea how its web libraries share and pool connections, but try sending one request out and then timing the next one - it should take much less time. Or try timing ten requests in a row - there will still be the 1-2 second set up time but the ten requests should then complete very quickly.

        Comment

        • gr33d
          Junior Member
          • May 2012
          • 12

          #5
          Originally posted by Mr Magoo View Post
          The response time might be very high if this is a new connection. Establishing a SSL connection to the server can be very time-consuming, however once this is done, you can send many API requests on the same underlying HTTPS connection.

          I don't know VB, so I've no idea how its web libraries share and pool connections, but try sending one request out and then timing the next one - it should take much less time. Or try timing ten requests in a row - there will still be the 1-2 second set up time but the ten requests should then complete very quickly.
          Good point.

          Jake, you'll probably need to add something like the following, but I am also not a VB expert, but this is how I'd expect to do it:

          request.Headers.Add("Connection", "Keep-Alive");

          Comment

          • only1jake
            Junior Member
            • Nov 2016
            • 29

            #6
            Thanks for the help guys. All makes sense.
            I've done some more research and played around a little and found that's the case.
            Cheers

            Comment

            Working...
            X