【CUP使用率100% 】关于每隔 100 毫秒 发出的 100 个异步Http请求,如何提高速度和系统性能?
class RequestState
{
public HttpWebRequest request;
public int roomid;
public DateTime sent;
public RequestState(HttpWebRequest r, int id)
{
sent = DateTime.Now;
request = r;
roomid = id;
}
}
void HttpResponseReturned(IAsyncResult ar)
{
RequestState rstate = (RequestState)ar.AsyncState;
HttpWebResponse response = (HttpWebResponse)rstate.request.EndGetResponse(ar);
Console.WriteLine(string.Format( "收到{0}发出的异步Http请求(RoomID={1}) ", rstate.sent, rstate.roomid));
Encoding enc = Encoding.GetEncoding(response.CharacterSet);
using (Stream rstream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(rstream, enc))
{
string html = reader.ReadToEnd();
/*
处理html
*/
}
}