好像系统只能同时执行几十个http访问,我希望能一秒钟能完成1000次http post访问,代码如下:
[C#] 纯文本查看 复制代码 public void Start(object i)
{
HttpHelper hh = new HttpHelper();
HttpItem hi = new HttpItem();
hi.URL = "http://10086.cn/";
hi.Timeout = 1000;
hi.Connectionlimit = 512;
hi.KeepAlive = true;
hi.Encoding = Encoding.UTF8;
HttpResult hr = hh.GetHtml(hi);
}
static Semaphore semahoro = new Semaphore(40, 3000);//同时运行40个访问设置的太高了反而慢了
static void Main(string[] args)
{
Program p = new Program();
int index1 = 0;
DateTime st = DateTime.Now;
while (st.AddMinutes(3) > DateTime.Now)
{
index1++;
semahoro.WaitOne();
Thread thread = new Thread(new ParameterizedThreadStart(p.Start));
thread.Start();
Console.SetCursorPosition(0, 8);
Console.Write((double)(DateTime.Now - st).TotalSeconds / (double)180 * 100 + "% ");
}
TimeSpan us = DateTime.Now - st;
Console.SetCursorPosition(0, 6);
Console.Write("用时:" + us.ToString() + "共执行:" + index1);
}
|