gpt4 book ai didi

c# - 在单声道 3.2.8 Ubuntu Server 14 上使用 HttpWebRequest

转载 作者:行者123 更新时间:2023-12-04 18:47:34 24 4
gpt4 key购买 nike

我有一个控制台应用程序,它创建 500 个线程,每个线程从并发堆栈中提取 url 并创建 HttpWebRequest 对象,获取响应并记录时间。我已经在具有 512 MB RAM 的 Windows Server 2012 R2 机器上运行了这个程序,它运行良好。

我尝试过使用 IO 完成端口(异步方法),但性能变得更差,所以现在这不是我的选择。

在 Ubuntu Server 14 64 位(1 GB RAM)上运行会导致显示以下错误:

Warning: Degraded allocation.  Consider increasing nursery-size if the warning persists.
_wapi_connect: error looking up socket handle 0x1f (error 10038)
_wapi_connect: error looking up socket handle 0x91 (error 10038)
_wapi_connect: error looking up socket handle 0xb (error 10022)
_wapi_connect: error looking up socket handle 0x6c (error 10038)
_wapi_connect: error looking up socket handle 0x6b (error 10038)
_wapi_connect: error looking up socket handle 0x1c (error 10038)
_wapi_connect: error looking up socket handle 0x1b (error 10038)
_wapi_connect: error looking up socket handle 0xbd (error 10038)
_wapi_connect: error looking up socket handle 0x31 (error 10038)
_wapi_connect: error looking up socket handle 0x1a2 (error 10038)
_wapi_connect: error looking up socket handle 0x187 (error 10038)
_wapi_connect: error looking up socket handle 0x18c (error 10038)
Warning: Degraded allocation. Consider increasing nursery-size if the warning persists.
_wapi_connect: error looking up socket handle 0xa5
_wapi_connect: error looking up socket handle 0x141 (error 10038)
_wapi_connect: error looking up socket handle 0x44

以下是创建 Web 请求的代码:
private static HttpWebRequest CreateRequest(string url)
{
HttpWebRequest req = HttpWebRequest.Create(url) as HttpWebRequest;
req.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36";
req.Method = "GET";
req.AllowAutoRedirect = true;
req.KeepAlive = false;
req.MaximumAutomaticRedirections = 1;
req.Timeout = 5000;
req.Proxy = null;

return req;
}

线程创建代码:
Thread thread = new Thread(() =>
{
Stopwatch s = Stopwatch.StartNew();
string url;
while (urlsToPull.TryPop(out url))
{
try
{
Stopwatch indiv = Stopwatch.StartNew();
using (HttpWebResponse res = CreateRequest(url).GetResponse() as HttpWebResponse)
{
if (res.StatusCode != HttpStatusCode.OK)
{
Interlocked.Increment(ref badStatus);
}
}
indiv.Stop();
Add(ref urlSum, indiv.Elapsed.TotalSeconds);
lock (goodFile)
{
goodFile.WriteLine(url);
}
}
catch
{
lock (errorFile)
{
errorFile.WriteLine(url);
}
Interlocked.Increment(ref errors);
}
Interlocked.Increment(ref urlsChecked);
}
Interlocked.Decrement(ref tasks);
s.Stop();
}, 4096);

可以通过单声道命令行更改托儿所大小吗?我不确定查找套接字句柄的错误是什么问题,但可能与托儿所错误有关?

任何帮助表示赞赏。

最佳答案

我建议将您的单声道版本更新到最新版本。 Microsoft 还将 .NET 更新为开源,因此如果/当 mono 团队集成此特定代码时,您可能想尝试一下。

关于c# - 在单声道 3.2.8 Ubuntu Server 14 上使用 HttpWebRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24477882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com