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
dongmi0760
dongmi0760 np,只是一个想法。
大约 6 年之前 回复
dou44364983
dou44364983 嗨,洛兹。它仍然是MySQL_Connect。主机是一个名称,因为主机将所有数据库放在一个集群中。
大约 6 年之前 回复
dongzhong1929
dongzhong1929 您是否将PDO与localhost一起用作主机?如果是这样,将其更改为127.0.0.1
大约 6 年之前 回复

1个回答



一些想法:</ p>


  • 并行运行http请求。 (客户端)</ li>
  • 如果数据响应大小允许它获取一个请求中所需的所有数据(您需要更改服务器实现)。</ li>
  • 缓存数据。 (服务器)</ li>
    </ ul>
    </ div>

展开原文

原文

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)

douge3113
douge3113 第一个听起来很有趣。 单独的线程? 你可以同时做多少? 所有数据都是一次性尝试但不是正确的解决方案。 它只有很小的数据,但有时通过电话 - 互联网连接(3G)。 一下子,他们可能会在500/5000崩溃,什么也没有。 生病的谷歌缓存。 也许这也是一个选择。
大约 6 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐