优化关键应用的HTTP请求性能



我正在开发一个重要的c#控制台应用程序,它大量使用网络(HTTP)。由于应用程序的重要性,它必须通过HTTP非常快速地报告一些事件。如何优化和实现快速HTTP连接?

我从这个设置开始:

internal class Program
{
private static void Main(string[] args)
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.UseNagleAlgorithm = false;
ServicePointManager.DefaultConnectionLimit = int.MaxValue;
ServicePointManager.EnableDnsRoundRobin = true;
ServicePointManager.ReusePort = true;
ServicePointManager.SetTcpKeepAlive(true, 0, 0);
ServicePointManager.MaxServicePointIdleTime = 13000;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
}
}

在这里实现更好性能的主要方法是多线程。

在网络中,你通常无法改变你需要等待的时间。因此,让尽可能多的线程开始等待。含义:尽快请求一切。

在实践中,这通常是基于估计和统计的推测加载,甚至是暴力加载。例如:
在点击任何链接之前开始加载页面是常见的浏览器行为。

最新更新