StreamReader性能不佳 [英] StreamReader poor performance

查看:69
本文介绍了StreamReader性能不佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在StreamReader遇到了性能问题,并且想知道我能做些什么来改善它...

以下大约需要3秒钟才能完成!

响应的内容是:


"<?xml version =" 1.0" ?>< ERROR> ORA-01403:未找到数据< / ERROR>"


HttpWebRequest req =(HttpWebRequest)WebRequest.Create(strURIQuery);

req.Method =" GET";

req.Credentials = new NetworkCredential(strUser,strPass);

StreamReader stream = new

StreamReader(req.GetResponse()。GetResponseStream());

StringBuilder sbXMLResponse0 = new StringBuilder();


// ## start timer here

while((strLineXMLResponse = stream.ReadLine())!= null)

{

if(strLineXMLResponse.Length> 0)

{

sbXMLResponse0.Append(strLineXMLResponse);

}

}

/ / ## end timer here

我也尝试过:

strLineXMLResponse = stream.ReadToEnd();

具有类似的处理时间。响应时间在亚秒级以下 - 我

我认为我已经正确地将性能问题隔离到了

StreamReader。


任意非常感谢帮助。

谢谢,

Oafyuf

Hi,
I''m having performanbce issues with StreamReader and was wondering
what I could do to improve it...

The following takes around 3 seconds to process! The content of the
response is:

"<?xml version="1.0" ?><ERROR>ORA-01403: no data found</ERROR>"

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strURIQuery);
req.Method = "GET";
req.Credentials = new NetworkCredential(strUser, strPass);
StreamReader stream = new
StreamReader(req.GetResponse().GetResponseStream() );
StringBuilder sbXMLResponse0 = new StringBuilder();

//## start timer here
while((strLineXMLResponse = stream.ReadLine()) != null)
{
if(strLineXMLResponse.Length > 0 )
{
sbXMLResponse0.Append(strLineXMLResponse);
}
}
//## end timer here
I also tried:
strLineXMLResponse = stream.ReadToEnd();
with similar processing times. The response times are sub-second - I
think I have correctly isolated the performance issue to the
StreamReader.

Any help would be much appreciated.
Thanks,
Oafyuf

推荐答案

oafyuf< oa ****@hotmail.com>写道:
oafyuf <oa****@hotmail.com> wrote:
我遇到了StreamReader的性能问题,并且想知道我能做些什么来改进它...

以下需要3秒左右处理!
响应的内容是:

<?xml version =" 1.0" ?>< ERROR> ORA-01403:未找到数据< / ERROR>"

HttpWebRequest req =(HttpWebRequest)WebRequest.Create(strURIQuery);
req.Method =" ; GET" ;;
req.Credentials = new NetworkCredential(strUser,strPass);
StreamReader stream = new
StreamReader(req.GetResponse()。GetResponseStream());
StringBuilder sbXMLResponse0 = new StringBuilder();

// ## start timer here
while((strLineXMLResponse = stream.ReadLine())!= null)
{
if(strLineXMLResponse.Length> 0)
{
sbXMLResponse0.Append(strLineXMLResponse);
}
}
// ## end timer here

我也尝试过:
strLineXMLResponse = stream.ReadToEnd();
处理时间相似。响应时间低于秒 - 我认为我已经正确地将性能问题隔离到了StreamReader。
I''m having performanbce issues with StreamReader and was wondering
what I could do to improve it...

The following takes around 3 seconds to process! The content of the
response is:

"<?xml version="1.0" ?><ERROR>ORA-01403: no data found</ERROR>"

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strURIQuery);
req.Method = "GET";
req.Credentials = new NetworkCredential(strUser, strPass);
StreamReader stream = new
StreamReader(req.GetResponse().GetResponseStream() );
StringBuilder sbXMLResponse0 = new StringBuilder();

//## start timer here
while((strLineXMLResponse = stream.ReadLine()) != null)
{
if(strLineXMLResponse.Length > 0 )
{
sbXMLResponse0.Append(strLineXMLResponse);
}
}
//## end timer here
I also tried:
strLineXMLResponse = stream.ReadToEnd();
with similar processing times. The response times are sub-second - I
think I have correctly isolated the performance issue to the
StreamReader.




直接从响应流 - 我怀疑在相同的时间长度内需要

。如果它确实是非常令我感到惊讶的话,那么流量调节器很慢。


-

Jon Skeet - < sk***@pobox.com>
http://www.pobox。 com / ~siget

如果回复小组,请不要给我发邮件



Try reading straight from the response stream - I suspect it will take
about the same length of time. I''d be very surprised if it really was
StreamReader being slow.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too





您与服务器的连接如何?处理

请求的时间怎么样?

可能存在瓶颈,而不是响应的长度。

StreamReader应该不添加任何开销。


干杯,


-

Ignacio Machin,

ignacio.machin AT dot.state.fl.us

佛罗里达州交通局


" oafyuf" < OA **** @ hotmail.com>在消息中写道

新闻:ea ************************** @ posting.google.c om ...
Hi,

How is your connection with the server? what about the time to process the
request?
maybe there is the bottleneck, and not in the length of the response.
StreamReader should not add any overhead.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"oafyuf" <oa****@hotmail.com> wrote in message
news:ea**************************@posting.google.c om...

我在使用StreamReader时遇到了问题,并且想知道我能做些什么来改进它...

以下处理大约需要3秒钟!
响应的内容是:

<?xml version =" 1.0" ?>< ERROR> ORA-01403:未找到数据< / ERROR>"

HttpWebRequest req =(HttpWebRequest)WebRequest.Create(strURIQuery);
req.Method =" ; GET" ;;
req.Credentials = new NetworkCredential(strUser,strPass);
StreamReader stream = new
StreamReader(req.GetResponse()。GetResponseStream());
StringBuilder sbXMLResponse0 = new StringBuilder();

// ## start timer here
while((strLineXMLResponse = stream.ReadLine())!= null)
{
if(strLineXMLResponse.Length> 0)
{
sbXMLResponse0.Append(strLineXMLResponse);
}
}
// ## end timer here

我也尝试过:
strLineXMLResponse = stream.ReadToEnd();
处理时间相似。响应时间在亚秒级以下 - 我认为我已经将性能问题正确地隔离到了StreamReader。

任何帮助都将不胜感激。
谢谢,
Oafyuf
Hi,
I''m having performanbce issues with StreamReader and was wondering
what I could do to improve it...

The following takes around 3 seconds to process! The content of the
response is:

"<?xml version="1.0" ?><ERROR>ORA-01403: no data found</ERROR>"

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strURIQuery);
req.Method = "GET";
req.Credentials = new NetworkCredential(strUser, strPass);
StreamReader stream = new
StreamReader(req.GetResponse().GetResponseStream() );
StringBuilder sbXMLResponse0 = new StringBuilder();

//## start timer here
while((strLineXMLResponse = stream.ReadLine()) != null)
{
if(strLineXMLResponse.Length > 0 )
{
sbXMLResponse0.Append(strLineXMLResponse);
}
}
//## end timer here
I also tried:
strLineXMLResponse = stream.ReadToEnd();
with similar processing times. The response times are sub-second - I
think I have correctly isolated the performance issue to the
StreamReader.

Any help would be much appreciated.
Thanks,
Oafyuf



你确定GetResponseStream不是那么久吗?我的意思是,

函数调用执行到URI中指定的主机的网络旅行,

当然需要相当长的时间。


到目前为止,我对StreamReader的体验没有显示出任何重大的

性能问题。


-

John Wood

电子邮件:名字,点,姓,在priorganize.com

" oafyuf" < OA **** @ hotmail.com>在消息中写道

新闻:ea ************************** @ posting.google.c om ...
Are you sure it''s not the GetResponseStream that''s taking so long? I mean,
that function call performs a network trip to the host specified in the URI,
which of course will take a considerable amount of time.

My experience with StreamReader so far have not shown any significant
performance problems.

--
John Wood
EMail: first name, dot, last name, at priorganize.com
"oafyuf" <oa****@hotmail.com> wrote in message
news:ea**************************@posting.google.c om...

我在使用StreamReader时遇到了问题,并且想知道我能做些什么来改进它...

以下处理大约需要3秒钟!
响应的内容是:

<?xml version =" 1.0" ?>< ERROR> ORA-01403:未找到数据< / ERROR>"

HttpWebRequest req =(HttpWebRequest)WebRequest.Create(strURIQuery);
req.Method =" ; GET" ;;
req.Credentials = new NetworkCredential(strUser,strPass);
StreamReader stream = new
StreamReader(req.GetResponse()。GetResponseStream());
StringBuilder sbXMLResponse0 = new StringBuilder();

// ## start timer here
while((strLineXMLResponse = stream.ReadLine())!= null)
{
if(strLineXMLResponse.Length> 0)
{
sbXMLResponse0.Append(strLineXMLResponse);
}
}
// ## end timer here

我也尝试过:
strLineXMLResponse = stream.ReadToEnd();
处理时间相似。响应时间在亚秒级以下 - 我认为我已经将性能问题正确地隔离到了StreamReader。

任何帮助都将不胜感激。
谢谢,
Oafyuf
Hi,
I''m having performanbce issues with StreamReader and was wondering
what I could do to improve it...

The following takes around 3 seconds to process! The content of the
response is:

"<?xml version="1.0" ?><ERROR>ORA-01403: no data found</ERROR>"

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strURIQuery);
req.Method = "GET";
req.Credentials = new NetworkCredential(strUser, strPass);
StreamReader stream = new
StreamReader(req.GetResponse().GetResponseStream() );
StringBuilder sbXMLResponse0 = new StringBuilder();

//## start timer here
while((strLineXMLResponse = stream.ReadLine()) != null)
{
if(strLineXMLResponse.Length > 0 )
{
sbXMLResponse0.Append(strLineXMLResponse);
}
}
//## end timer here
I also tried:
strLineXMLResponse = stream.ReadToEnd();
with similar processing times. The response times are sub-second - I
think I have correctly isolated the performance issue to the
StreamReader.

Any help would be much appreciated.
Thanks,
Oafyuf



这篇关于StreamReader性能不佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆