Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASPX Performance - Slow?

Reply
Thread Tools

ASPX Performance - Slow?

 
 
BlueBall
Guest
Posts: n/a
 
      05-13-2004
I am writing some kind of network testing tool and I have wrote the
following code in ASP.NET with C#

int size= 10048576; // around 10 MB data
string buffer = "";
for (int j=1; j<=1024; j++) {
buffer = String.Concat(buffer, "x");
// I tried buffer += "x"; same performance
}

for (int i=1; i<=(size/1024); i++) {
Response.Write(buffer);
// I tried using <asp:literal> same thing
}

From another computer, I downloaded this file by making that as a link in
HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In order
to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote the
same thing in PHP using exactly same algorithm. I got around 25 Mbps!

Anyone knows why ASPX performance is slow? is it configruation problem?
IIS? or is it Response.write not good? I also tried using <asp: literal>
same thing.. help..

Thanks in advance





 
Reply With Quote
 
 
 
 
Chris Torgerson
Guest
Posts: n/a
 
      05-13-2004
Try your test and replace String.Concat with a StringBuilder. Basically in
your current code you are doing string allocations on each pass of the loop.
So what you want is something like:

int size= 10048576; // around 10 MB data
System.Text.StringBuilder sb=new System.Text.StringBuilder()
string buffer = "";
for (int j=1; j<=1024; j++) {
sb.Append("x");
// I tried buffer += "x"; same performance
}
buffer=sb.ToString();

hth
Chris Torgerson

"BlueBall" <> wrote in message
news2Qoc.62265$. cable.rogers.com...
> I am writing some kind of network testing tool and I have wrote the
> following code in ASP.NET with C#
>
> int size= 10048576; // around 10 MB data
> string buffer = "";
> for (int j=1; j<=1024; j++) {
> buffer = String.Concat(buffer, "x");
> // I tried buffer += "x"; same performance
> }
>
> for (int i=1; i<=(size/1024); i++) {
> Response.Write(buffer);
> // I tried using <asp:literal> same thing
> }
>
> From another computer, I downloaded this file by making that as a link in
> HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In order
> to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote the
> same thing in PHP using exactly same algorithm. I got around 25 Mbps!
>
> Anyone knows why ASPX performance is slow? is it configruation problem?
> IIS? or is it Response.write not good? I also tried using <asp: literal>
> same thing.. help..
>
> Thanks in advance
>
>
>
>
>



 
Reply With Quote
 
 
 
 
Jason DeFontes
Guest
Posts: n/a
 
      05-13-2004
String concatenation, whether you user String.Concat or +=, is
incredibly expensive because it makes a new copy of the string every
time. Try this instead:

int size= 10048576; // around 10 MB data
StringBuilder buffer = new StringBuilder(size);
for (int j=1; j<=size; j++)
{
buffer.Append("x");
}
Response.Write(buffer.ToString());

-Jason


BlueBall wrote:

> I am writing some kind of network testing tool and I have wrote the
> following code in ASP.NET with C#
>
> int size= 10048576; // around 10 MB data
> string buffer = "";
> for (int j=1; j<=1024; j++) {
> buffer = String.Concat(buffer, "x");
> // I tried buffer += "x"; same performance
> }
>
> for (int i=1; i<=(size/1024); i++) {
> Response.Write(buffer);
> // I tried using <asp:literal> same thing
> }
>
> From another computer, I downloaded this file by making that as a link in
> HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In order
> to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote the
> same thing in PHP using exactly same algorithm. I got around 25 Mbps!
>
> Anyone knows why ASPX performance is slow? is it configruation problem?
> IIS? or is it Response.write not good? I also tried using <asp: literal>
> same thing.. help..
>
> Thanks in advance
>
>
>
>
>

 
Reply With Quote
 
BlueBall
Guest
Posts: n/a
 
      05-13-2004
StringBuilder doesn't help because in my code, I don't actually repeat the
buffer generating part.

Try to run it on your IIS, you will see what I mean. In order to verify
this is an ASPX performance problem (or possible my coding algorithm or
config problem), I have created an old fashion ASP page:

<%
dim i, j, size, buffer
size= 10048576
for i = 1 to 1024
buffer = buffer & "x"
next
for j = 1 to (size / 1024)
response.write(buffer)
next
%>

Create a hyper link in a new HTML page and link to this ASP page, and then
create another link that links to ASPX page you wrote (or the one I posted
earlier). You can see the BIG difference in performance. ASP page is
faster than ASPX page at least 3 times... I am frustrated!!!

B.B.



"Jason DeFontes" <> wrote in message
news:%...
> String concatenation, whether you user String.Concat or +=, is
> incredibly expensive because it makes a new copy of the string every
> time. Try this instead:
>
> int size= 10048576; // around 10 MB data
> StringBuilder buffer = new StringBuilder(size);
> for (int j=1; j<=size; j++)
> {
> buffer.Append("x");
> }
> Response.Write(buffer.ToString());
>
> -Jason
>
>
> BlueBall wrote:
>
> > I am writing some kind of network testing tool and I have wrote the
> > following code in ASP.NET with C#
> >
> > int size= 10048576; // around 10 MB data
> > string buffer = "";
> > for (int j=1; j<=1024; j++) {
> > buffer = String.Concat(buffer, "x");
> > // I tried buffer += "x"; same performance
> > }
> >
> > for (int i=1; i<=(size/1024); i++) {
> > Response.Write(buffer);
> > // I tried using <asp:literal> same thing
> > }
> >
> > From another computer, I downloaded this file by making that as a link

in
> > HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In

order
> > to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote

the
> > same thing in PHP using exactly same algorithm. I got around 25 Mbps!
> >
> > Anyone knows why ASPX performance is slow? is it configruation problem?
> > IIS? or is it Response.write not good? I also tried using <asp:

literal>
> > same thing.. help..
> >
> > Thanks in advance
> >
> >
> >
> >
> >



 
Reply With Quote
 
Ed Courtenay
Guest
Posts: n/a
 
      05-13-2004
BlueBall wrote:
> StringBuilder doesn't help because in my code, I don't actually repeat the
> buffer generating part.
>
> Try to run it on your IIS, you will see what I mean. In order to verify
> this is an ASPX performance problem (or possible my coding algorithm or
> config problem), I have created an old fashion ASP page:
>
> <%
> dim i, j, size, buffer
> size= 10048576
> for i = 1 to 1024
> buffer = buffer & "x"
> next
> for j = 1 to (size / 1024)
> response.write(buffer)
> next
> %>
>
> Create a hyper link in a new HTML page and link to this ASP page, and then
> create another link that links to ASPX page you wrote (or the one I posted
> earlier). You can see the BIG difference in performance. ASP page is
> faster than ASPX page at least 3 times... I am frustrated!!!
>
> B.B.
>


I think I can see where your problem is.

By default, ASP does not buffer output whereas ASP.NET does. Therefore,
your ASP code is sending the response directly to the client, whereas
ASP.Net is building the entire output before sending.

Try setting Response.BufferOuput to false in your Page.Load event
handler and then try your test again.






--

Ed Courtenay
[MCP, MCSD]
http://www.edcourtenay.co.uk
 
Reply With Quote
 
BlueBall
Guest
Posts: n/a
 
      05-13-2004
I tried adding it but that makes the performance even worse...it's like
crawling. I am posting my 2 pieces of codes, so that anyone can try it on
your server. Thanks in advance!

Create a HTML page and make 2 hyper links pointing to these 2 files, then
Right-click -> save target as -> You will see the BIG difference between the
performance between the two.

-------------------------------------------------------
test.aspx
-------------------------------------------------------

<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script language="C#" runat="server">
void Page_Load() {

// Response.BufferOutput = false;
int size= 10485760; // around 10 MB data
StringBuilder buffer = new StringBuilder(size);
String str = "";

for (int i=1; i<=1024; i++)
buffer.Append("x");

str = buffer.ToString();

for (int j=1; j<=size/1024; j++)
Response.Write(str);


} // load
</script>

-------------------------------------------------------
test.asp
-------------------------------------------------------

<%
dim i, j, size, buffer
size = 10485760

for i = 1 to 1024
buffer = buffer & "x"
next

for j = 1 to (size / 1024)
response.write(buffer)
next

%>

-------------------------------------------------------





"Ed Courtenay" <replace-this-with-my-first-> wrote in
message news:%...
> BlueBall wrote:
> > StringBuilder doesn't help because in my code, I don't actually repeat

the
> > buffer generating part.
> >
> > Try to run it on your IIS, you will see what I mean. In order to verify
> > this is an ASPX performance problem (or possible my coding algorithm or
> > config problem), I have created an old fashion ASP page:
> >
> > <%
> > dim i, j, size, buffer
> > size= 10048576
> > for i = 1 to 1024
> > buffer = buffer & "x"
> > next
> > for j = 1 to (size / 1024)
> > response.write(buffer)
> > next
> > %>
> >
> > Create a hyper link in a new HTML page and link to this ASP page, and

then
> > create another link that links to ASPX page you wrote (or the one I

posted
> > earlier). You can see the BIG difference in performance. ASP page is
> > faster than ASPX page at least 3 times... I am frustrated!!!
> >
> > B.B.
> >

>
> I think I can see where your problem is.
>
> By default, ASP does not buffer output whereas ASP.NET does. Therefore,
> your ASP code is sending the response directly to the client, whereas
> ASP.Net is building the entire output before sending.
>
> Try setting Response.BufferOuput to false in your Page.Load event
> handler and then try your test again.
>
>
>
>
>
>
> --
>
> Ed Courtenay
> [MCP, MCSD]
> http://www.edcourtenay.co.uk



 
Reply With Quote
 
Jason DeFontes
Guest
Posts: n/a
 
      05-13-2004
Well, I tried it, and your ASP was about 3x *slower* than your ASPX, and
my ASPX with the StringBuilder and only 1 call to Response.Write,
instead of your ~10000 calls, was about 1/3 faster than your ASPX. So
who knows... I imagine there are many, many factors that could affect
this, and our two samples hardly make a conclusive data set.

-Jason

BlueBall wrote:

> StringBuilder doesn't help because in my code, I don't actually repeat the
> buffer generating part.
>
> Try to run it on your IIS, you will see what I mean. In order to verify
> this is an ASPX performance problem (or possible my coding algorithm or
> config problem), I have created an old fashion ASP page:
>
> <%
> dim i, j, size, buffer
> size= 10048576
> for i = 1 to 1024
> buffer = buffer & "x"
> next
> for j = 1 to (size / 1024)
> response.write(buffer)
> next
> %>
>
> Create a hyper link in a new HTML page and link to this ASP page, and then
> create another link that links to ASPX page you wrote (or the one I posted
> earlier). You can see the BIG difference in performance. ASP page is
> faster than ASPX page at least 3 times... I am frustrated!!!
>
> B.B.
>
>
>
> "Jason DeFontes" <> wrote in message
> news:%...
>
>>String concatenation, whether you user String.Concat or +=, is
>>incredibly expensive because it makes a new copy of the string every
>>time. Try this instead:
>>
>> int size= 10048576; // around 10 MB data
>> StringBuilder buffer = new StringBuilder(size);
>> for (int j=1; j<=size; j++)
>> {
>> buffer.Append("x");
>> }
>> Response.Write(buffer.ToString());
>>
>>-Jason
>>
>>
>>BlueBall wrote:
>>
>>
>>>I am writing some kind of network testing tool and I have wrote the
>>>following code in ASP.NET with C#
>>>
>>> int size= 10048576; // around 10 MB data
>>> string buffer = "";
>>> for (int j=1; j<=1024; j++) {
>>> buffer = String.Concat(buffer, "x");
>>> // I tried buffer += "x"; same performance
>>> }
>>>
>>> for (int i=1; i<=(size/1024); i++) {
>>> Response.Write(buffer);
>>> // I tried using <asp:literal> same thing
>>> }
>>>
>>>From another computer, I downloaded this file by making that as a link

>
> in
>
>>>HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In

>
> order
>
>>>to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote

>
> the
>
>>>same thing in PHP using exactly same algorithm. I got around 25 Mbps!
>>>
>>>Anyone knows why ASPX performance is slow? is it configruation problem?
>>>IIS? or is it Response.write not good? I also tried using <asp:

>
> literal>
>
>>>same thing.. help..
>>>
>>>Thanks in advance
>>>
>>>
>>>
>>>
>>>

>
>
>

 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      05-14-2004

"BlueBall" <> wrote in message news2Qoc.62265$. cable.rogers.com...
> I am writing some kind of network testing tool and I have wrote the
> following code in ASP.NET with C#
>
> int size= 10048576; // around 10 MB data
> string buffer = "";
> for (int j=1; j<=1024; j++) {
> buffer = String.Concat(buffer, "x");
> // I tried buffer += "x"; same performance
> }
>
> for (int i=1; i<=(size/1024); i++) {
> Response.Write(buffer);
> // I tried using <asp:literal> same thing
> }
>
> From another computer, I downloaded this file by making that as a link in
> HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In order
> to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote the
> same thing in PHP using exactly same algorithm. I got around 25 Mbps!
>
> Anyone knows why ASPX performance is slow? is it configruation problem?
> IIS? or is it Response.write not good? I also tried using <asp: literal>
> same thing.. help..
>
> Thanks in advance
>
>
>
>
>


In addition to the other replies:

When did you time the performance? The first time an aspx page
is accessed, it gets compiled to native code. This will have a performance
hit, but only the first time this page is accessed (in the lifetime
of the application).
Neither php or asp have this automatic compile feature so there
you get no speed dirrerence between the first and second time.


Hans Kesting


 
Reply With Quote
 
George Ter-Saakov
Guest
Posts: n/a
 
      05-17-2004
1. You should try to use StringBuilder for concatenation. This will greatly
improve performance.

2. You are outputting buffer 9813 times. The problem is that ASP.NET saves
the output into temporary buffer and only when you done it outputs the
buffer to browser. The size of the buffer is preset to something big but
much less than 10Mb. And ASP.NET has to constantly expand the buffer as
needed when you are outputting it. Which is a big performance hit.
If you just bluntly set Response.Buffer = false then you going to have
another problem since ASP.NET will have to use IIS APIs every time you do
Response.Write which is another performance hit.


You can minimize it by seting Response.Buffer = true but calling
Response.Flush every 20th time.

George.


"BlueBall" <> wrote in message
news2Qoc.62265$. cable.rogers.com...
> I am writing some kind of network testing tool and I have wrote the
> following code in ASP.NET with C#
>
> int size= 10048576; // around 10 MB data
> string buffer = "";
> for (int j=1; j<=1024; j++) {
> buffer = String.Concat(buffer, "x");
> // I tried buffer += "x"; same performance
> }
>
> for (int i=1; i<=(size/1024); i++) {
> Response.Write(buffer);
> // I tried using <asp:literal> same thing
> }
>
> From another computer, I downloaded this file by making that as a link in
> HTML. It was so slow.. I get around 8 Mbps on a 100 Mbps LAN.. In order
> to compare, I tested with a real JPG file I got 25 Mbps! Also, I wrote the
> same thing in PHP using exactly same algorithm. I got around 25 Mbps!
>
> Anyone knows why ASPX performance is slow? is it configruation problem?
> IIS? or is it Response.write not good? I also tried using <asp: literal>
> same thing.. help..
>
> Thanks in advance
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance Tutorials Services - Boosting Performance by DisablingUnnecessary Services on Windows XP Home Edition Software Engineer Javascript 0 06-10-2011 02:18 AM
adding main.aspx.vb & main.aspx.resx under aspx John M ASP .Net 1 05-29-2005 09:27 PM
Performance of ASPX Page when using Asynchronous Handlers Santa ASP .Net 0 08-02-2004 03:06 AM
12 tables on aspx page: A performance hit? Jason Shohet ASP .Net 1 12-29-2003 04:35 PM
Web Form Performance Versus Single File Performance jm ASP .Net 1 12-12-2003 11:14 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57