HTTP请求的性能大量的请求 [英] HTTP Request performance for large volumes of requests

查看:153
本文介绍了HTTP请求的性能大量的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找如何优化下面的过程中的一些建议:

I'm looking for some advice on how to optimise the following process:

应用程序读取CSV文件。 对于文件中的每一行被创建XML消息 每个XML消息经由HttpWebRequest的

App reads csv file. For each line in the file an XML message is created Each XML message is posted to a URL via a HTTPWebRequest

此过程被设计用来处理低量的消息(高达约200,在一时间),未惊奇自以为已经改变,现在是期望处理高达约3000的时间。

This process was designed to handle low volumes of messages (up to about 200 at a time), un suprisingly thinks have changed and it is now expected to handle up to about 3000 at a time.

用于发布消息的code是在这里:

The code used to post the message is here:

Public Function PostXml(ByVal XML As String) As HttpStatusCode

        Try
            Dim Bytes As Byte() = Me.Encoding.GetBytes(XML)
            Dim HTTPRequest As HttpWebRequest = DirectCast(WebRequest.Create(Me.PostURL), HttpWebRequest)

            With HTTPRequest
                .Method = "POST"
                .ContentLength = Bytes.Length
                .ContentType = "text/xml"
                .Credentials = New NetworkCredential(_Settings.NTSPostUsernameCurrent, _Settings.NTSPostPasswordCurrent)
            End With

            Using RequestStream As Stream = HTTPRequest.GetRequestStream()
                RequestStream.Write(Bytes, 0, Bytes.Length)
                RequestStream.Close()
            End Using

            Using Response As HttpWebResponse = DirectCast(HTTPRequest.GetResponse(), HttpWebResponse)
                Return Response.StatusCode
            End Using

        Catch ex As WebException

            If ex.Message.Contains("(500) Internal Server Error") Then
                Return HttpStatusCode.InternalServerError
            Else
                Throw
            End If
        End Try

这个问题能在缓存中使用的连接方面的优化?目前有一个noticable延迟在该行: 使用响应,HttpWebResponse 而进行连接。 是否有缓存这让相同的连接用于为每个消息被创建的所有3000的消息,而不是一个新的连接的方式是什么?

Can this be optimised in terms of caching the connection used? At the moment there is a noticable delay at the line: Using Response As HttpWebResponse while the connection is made. Is there a way of caching this so the same connection is used for all 3000 messages rather than a new connection being created for each message?

任何建议感激:收到。

**更新。感谢您的答复。为了澄清,我目前仅限于发送多条消息,由于系统其它地方的限制。有一个noticable延迟在应对在另一端(接收器)的要求,但是,这是我的控制之外。我想,以确保发送的过程尽可能高效(外部因素尽管)。

**Update. Thanks for the responses. To clarify, I am currently restricted to sending multiple messages due to restrictions elsewhere in the system. There is a noticable delay in responding to the request at the other end (the receiver) but this is outside my control. I am trying to ensure that the process of sending is as efficient as possible (external factors notwithstanding).

推荐答案

.NET已经拥有连接高速缓存...如果你不处理的反应,你会看到,pretty的快:)(只澄清一下,你正在做正确的事情在这里。我经常看见的一个错误是的没有的有使用语句...这会导致由于连接高速缓存的问题precisely。)

.NET already has connection caching... if you weren't disposing of the response, you'd see that pretty quickly :) (Just to clarify, you're doing the right thing here. A bug I've seen quite often is not to have a Using statement... which causes a problem precisely because of connection caching.)

我怀疑这是不是制作的连接的,但制作的请求的的情况 - 换句话说,时间都用在你的控制范围之外的地区。

I suspect it's not a case of making the connection, but making the request - in other words, the time is spent in areas outside your control.

我建议你使用 Wireshark的或的提琴手工作在哪里的时候实际发生 - 也许它不只是Web服务本身? (或任何你在跟谁说话。)

I suggest you use Wireshark or Fiddler to work out where the time's actually going - might it not just be the web service itself? (Or whatever you're talking to.)

另一种方法是使用多线程加快这 - 但在这一点上,不要忘记增加每个主机的连接数(在 connectionSettings 部分的app.config的,IIRC)。

Another option is to use multiple threads to speed this up - but at that point, don't forget to increase the number of connections per host (in the connectionSettings part of app.config, IIRC).

这篇关于HTTP请求的性能大量的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆