我正在构建一个web爬虫,目标站点不允许来自同一个IP的两个以上并发连接。
我的计划是:我将购买一个带有4个额外弹性IP的EC2,以便更快地获取数据(将是10个并发连接,8个来自附加IP,2个来自“主”IP)。
我将使用BindIPEndPointDelegate (从here获取)设置源IP,然后开始下载页面。
因此,我的问题来了: DefaultConnectionLimit将应用于(每个源IP ),还是仅限于2个并发连接的整个应用程序?
发布于 2018-10-27 22:47:03
您需要指定主机,否则它将应用于所有主机:
使用配置:
<!-- By host -->
<configuration>
<system.net>
<connectionManagement>
<add address="myapi.com" maxconnection="12"/>
<add address="yourapi.com" maxconnection="8"/>
<add address="74.125.236.199" maxconnection="4"/>
</connectionManagement>
</system.net>
</configuration>
<!-- All hosts -->
<configuration>
<system.net>
<connectionManagement>
<add address="*" maxconnection="15"/>
</connectionManagement>
</system.net>
</configuration>使用代码:
var apiServicePoint1 = ServicePointManager.FindServicePoint("myapi.com");
apiServicePoint1.ConnectionLimit = 12;
var apiServicePoint2 = ServicePointManager.FindServicePoint("yourapi.com");
apiServicePoint2.ConnectionLimit = 8;参考资料:https://vincentlauzon.com/2015/12/13/beyond-2-concurrent-connections-in-net/
https://stackoverflow.com/questions/47251824
复制相似问题