dpw43061 2014-07-24 08:03
浏览 72

too long

Im working on a project that downloads up to 5000 individual pieces of data from a server. It basically is a PHP page that takes POST variable, gets the data from the DB and sends it back to the .NET client.

It is slow. It takes about 1 second per request. I've googled a lot and tried all sorts of tweaks to the code, like the famous proxy-setting etc. But nothing speeds it up.

Any idea's? All solutions that make this super fast are welcome. Even C-written DLL's or anything you can think of. This just needs to be a lot faster.

Public Function askServer(oCode As String) As String

    oBytesToSend = Encoding.ASCII.GetBytes("cmd=" & System.Web.HttpUtility.UrlEncode(oCode))

    Try
        oRequest = WebRequest.Create(webServiceUrl)
        oRequest.Timeout = 60000
        oRequest.Proxy = WebRequest.DefaultWebProxy
        CType(oRequest, HttpWebRequest).UserAgent = "XXXXX"
        oRequest.Method = "POST"
        oRequest.ContentLength = oBytesToSend.Length
        oRequest.ContentType = "application/x-www-form-urlencoded"

        oStream = oRequest.GetRequestStream()
        oStream.Write(oBytesToSend, 0, oBytesToSend.Length)

        oResponse = oRequest.GetResponse()
        If CType(oResponse, HttpWebResponse).StatusCode = Net.HttpStatusCode.OK Then
            oStream = oResponse.GetResponseStream()
            oReader = New StreamReader(oStream)
            oResponseFromServer = oReader.ReadToEnd()
            oResponseFromServer = System.Web.HttpUtility.UrlDecode(oResponseFromServer)
            Return oResponseFromServer
        Else
            MsgBox("Server error", CType(vbOKOnly + vbCritical, MsgBoxStyle), "")
            Return ""
        End If

    Catch e As Exception

        MsgBox("Oops" & vbCrLf & e.Message, CType(vbOKOnly + vbCritical, MsgBoxStyle), "")
        Return ""

    End Try

End Function
  • 写回答

1条回答

  • duangua5742 2014-07-24 08:16
    关注

    Some ideas :

    • Run the http requests in parallel. (Client)
    • If the data response size allows it get all data needed in one request (you need change your server implementation).
    • Caching data. (Server)
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料