[英]dot net:threads running too slow in express edition visual studio 2008?
i am running 12 threads .function which these threads are calling is not having any lock on some object.but still these threads are taking too much time.(16 minutes).each thread ially parsing a xml document which is running alright if run indiviually.is this problem because of some reason related max no threads provided by express edition or some blocking dn by express edition. 我正在运行12个线程。这些线程正在调用的函数在某个对象上没有任何锁定。但是仍然这些线程花费了太多时间。(16分钟)。每个线程都会解析一个xml文档,如果单独运行则可以正常运行这个问题是由于某种原因,与快速版提供的最大无线程数或快速版提供的某些阻止dn相关。
code of func whic each thread calls is given below. 下面给出了每个线程调用的函数代码。 each thread is given different rssfeed(urladdress)
每个线程被赋予不同的rssfeed(urladdress)
public static class RssFileReader
{
public static Rss GetRssDocumentData(string rssFeed)
{
Console.WriteLine("thread in RssFileReader: " + Thread.CurrentThread.Name);
IFormatProvider culture = new CultureInfo("fr-FR", true);
Rss rssDocumentObject=new Rss();
XmlDocument documentObj = new XmlDocument();
try
{
documentObj.Load(HttpClient.GetWebResponse(@rssFeed, null, null, 1200000, @"http://www.sahil.com").GetResponseStream());
}
catch(Exception e)
{
e.Source = "RssFileReader:Loading xmldocument object";
throw;
}
try
{
XmlNodeList channelList = documentObj.GetElementsByTagName("channel");
for (int k = 0; k < channelList.Count; k++)
{
rssDocumentObject.ListOfChannel.Add(new Channel());
int noOfItemInChannel = -1;
//XmlNodeList itemList = channelList[k].ChildNodes;
for (int i = 0; i < channelList[k].ChildNodes.Count; i++)
{
switch (channelList[k].ChildNodes[i].Name)
{
case "item":
noOfItemInChannel++;
XmlNodeList xmlChildNodeOfItem = channelList[k].ChildNodes[i].ChildNodes;
//debugging
//Console.WriteLine("Thread Name in item in RssFileReader" + Thread.CurrentThread.Name);
rssDocumentObject.ListOfChannel[k].ListOfItem.Add(new Item());
for (int j = 0; j < xmlChildNodeOfItem.Count; j++)
{
switch (xmlChildNodeOfItem[j].Name)
{
case "title":
rssDocumentObject.ListOfChannel[k].ListOfItem[noOfItemInChannel].ItemTitle.InnerText = xmlChildNodeOfItem[j].InnerText;
break;
case "link":
rssDocumentObject.ListOfChannel[k].ListOfItem[noOfItemInChannel].ItemLink.InnerText = xmlChildNodeOfItem[j].InnerText;
break;
case "description":
rssDocumentObject.ListOfChannel[k].ListOfItem[noOfItemInChannel].ItemDescription.InnerText = xmlChildNodeOfItem[j].InnerText;
break;
case "pubDate":
try
{
string dateTimeTemp = xmlChildNodeOfItem[j].InnerText;
char[] splitCharArray = new char[1];
splitCharArray[0] = ' ';
string[] splitedDateTimeTemp = dateTimeTemp.Split(splitCharArray);
string RFC822 = "ddd,ddMMMyyyyHH:mm:ss";
rssDocumentObject.ListOfChannel[k].ListOfItem[noOfItemInChannel].ItemPubDate.PublicationDate = DateTime.ParseExact(splitedDateTimeTemp[0] + splitedDateTimeTemp[1] + splitedDateTimeTemp[2] + splitedDateTimeTemp[3] + splitedDateTimeTemp[4], RFC822, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
}
//exception not rethrown default date is assigned
catch (Exception e)
{
//Console.WriteLine("Exception while formatting string to datetime in rssFileReader():" + e);
}
break;
case "guid":
rssDocumentObject.ListOfChannel[k].ListOfItem[noOfItemInChannel].ItemGuid.InnerText = xmlChildNodeOfItem[j].InnerText;
break;
}
}
break;
case "title":
rssDocumentObject.ListOfChannel[k].ChannelTitle.InnerText = channelList[k].ChildNodes[i].InnerText;
break;
case "description":
rssDocumentObject.ListOfChannel[k].ChannelDescription.InnerText = channelList[k].ChildNodes[i].InnerText;
break;
case "link":
rssDocumentObject.ListOfChannel[k].ChannelLink.InnerText = channelList[k].ChildNodes[i].InnerText;
break;
case "language":
rssDocumentObject.ListOfChannel[k].ChannelLanguage.InnerText = channelList[k].ChildNodes[i].InnerText;
break;
case "pubDate":
try
{
string dateTimeTempForChannel = channelList[k].ChildNodes[i].InnerText;
char[] splitCharArrayForChannel = new char[1];
splitCharArrayForChannel[0] = ' ';
string[] splitedDateTimeTempForChannel = dateTimeTempForChannel.Split(splitCharArrayForChannel);
string formatStringForChannel = "ddd,ddMMMyyyyHH:mm:ss";
rssDocumentObject.ListOfChannel[k].ChannelPubDate.PublicationDate = DateTime.ParseExact(splitedDateTimeTempForChannel[0] + splitedDateTimeTempForChannel[1] + splitedDateTimeTempForChannel[2] + splitedDateTimeTempForChannel[3] + splitedDateTimeTempForChannel[4], formatStringForChannel, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
}
//exception not rethrown default date is assigned
catch (Exception e)
{
//Console.WriteLine("Exception while formatting string to datetime in rssFileReader():" + e);
}
break;
case "lastBuildDate":
try
{
string dateTimeTempForChannel = channelList[k].ChildNodes[i].InnerText;
char[] splitCharArrayForChannel = new char[1];
splitCharArrayForChannel[0] = ' ';
string formatStringForChannel = "ddd,ddMMMyyyyHH:mm:ss";
string[] splitedDateTimeTempForChannel = dateTimeTempForChannel.Split(splitCharArrayForChannel);
rssDocumentObject.ListOfChannel[k].ChannelLastBuildDate.LastBldDate = DateTime.ParseExact(splitedDateTimeTempForChannel[0] + splitedDateTimeTempForChannel[1] + splitedDateTimeTempForChannel[2] + splitedDateTimeTempForChannel[3] + splitedDateTimeTempForChannel[4], formatStringForChannel, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
}
//exception not rethrown default date is assigned
catch (Exception e)
{
//Console.WriteLine("Exception while formatting string to datetime in rssFileReader():" + e);
}
break;
case "docs":
rssDocumentObject.ListOfChannel[k].ChannelDocs.InnerText = channelList[k].ChildNodes[i].InnerText;
break;
case "generator":
rssDocumentObject.ListOfChannel[k].ChannelGenerator.InnerText = channelList[k].ChildNodes[i].InnerText;
break;
case "managingEditor":
rssDocumentObject.ListOfChannel[k].ChannelManagingEditor.InnerText = channelList[k].ChildNodes[i].InnerText;
break;
case "webMaster":
rssDocumentObject.ListOfChannel[k].ChannelWebMaster.InnerText = channelList[k].ChildNodes[i].InnerText;
break;
case "ttl":
rssDocumentObject.ListOfChannel[k].ChannelTtl.InnerText = channelList[k].ChildNodes[i].InnerText;
break;
}
}
}
}
catch(Exception e)
{
e.Source = "RssFileReader:Reading xml document object data to rss object";
throw;
}
Console.WriteLine(" Thread out RssFilereader :" + Thread.CurrentThread.Name);
return rssDocumentObject;
}
}
note:-while debugging i got to know that its taking time while loading xml document. 注意:-在调试时,我知道加载xml文档时需要花费时间。 is there any limit imposed on system for number of webrequest objects?
系统对Web请求对象的数量有没有限制?
If you're using web requests to the same server, those are throttled by default to two connections at a time. 如果您使用的是对同一服务器的Web请求,则默认情况下会将这些请求一次限制为两个连接。
You're then failing to dispose of the response and response stream, which means it'll wait until it's garbage collected to release the connection for use elsewhere. 然后,您将无法处理响应和响应流,这意味着它将等待直到收集到垃圾后才释放连接以供其他地方使用。 Change your loading code to:
将您的加载代码更改为:
try
{
// Removed unnecessary @ signs
using (WebResponse response = HttpClient.GetWebResponse(
rssFeed, null, null, 1200000, "http://www.sahil.com"))
using (Stream responseStream = response.GetResponseStream())
{
documentObj.Load(responseStream);
}
}
catch(Exception e)
{
e.Source = "RssFileReader:Loading xmldocument object";
throw;
}
It's possible that you only need to close the web response - that the stream will be taken care of by closing the response - but it's better to be sure. 可能只需要关闭Web响应-通过关闭响应即可处理流-但最好确保。
You'll still only get two threads using connections to the same server at the same time (by default, for non-ASP.NET; you can change this yourself using ServicePointManager.DefaultConnectionLimit
or the connectionManagement
config file element ) but at least then you won't need to wait while the connection idles out or waits for garbage collection. 您仍然只能同时使用两个线程连接到同一服务器(默认情况下,对于非ASP.NET;您可以使用
ServicePointManager.DefaultConnectionLimit
或connectionManagement
配置文件元素自己更改此线程),但至少然后连接空闲或等待垃圾回收时,无需等待。
it was taking time when i was running it from console applcation fr testing. 我从控制台应用程序fr测试运行它需要时间。 reason fo much time taken was io blocking because of pint statements fr debugging.
调试之所以用pint语句,是因为io阻塞而花费了很多时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.