Pushing the limit of PHP vs ASP.NET

J

James Macbell

I think I have pushed ASP.NET to the limit, I am not sure if I have done
anything wrong in the code because I am trying to make 2 pieces of code (C#
vs PHP) using the same algorithm. Anyways, here is the my test.

How: Create a HTML page with 2 hyper links to these files (posted below).
Right click, Save target As.
Tested: On my P4 1.6 GHz , 1 GB Ram server, Windows 2000 IIS 5 and Apache
1.3 for win32, 100 Mbps LAN
Sample Size: 150 MB download
Result: IIS stopped responding when I tried to download the link to my local
HDD across the 100 Mbps network, then it poped up window saying "request is
unavailable". PHP worked without problem at all, I verified the saved file
was 150 MB on my local HDD.

Note:
1. In C# buffer += "x"; is a bit expensive but I have tried StringBuffer,
doesn't matter, it only runs for 1024 times anyways.
2. I also tried to set Response.BufferOutput = false in C#, but the download
speed was so slow like back in dial-up ages and the HDD was spinning like
crazy.

- James

ASP.NET code
===============================================

<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script language="C#" runat="server">
void Page_Load() {
int size= 156105356; // 150 MB data
String buffer = "";

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

for (int j=1; j<=size/1024; j++)
Response.Write(buffer);
}
</script>


PHP code
===============================================

<?php

$size= 156105356; // 150 MB data
$buffer = "";

for ($j=1; $j<=1024; $j++)
$buffer .= "x";

for ($i=1; $i<=($size/1024); $i++)
echo $buffer;

?>
 
P

Patrice

The worse I've done today with ASP is creating a 32 Mb file. I still zip the
file though (down to 6 Mb) before letting the user download it. Works fine
for now but this is still brand new.
For now I've not done this yet in ASP.NET but it should IMO work as well
(the main difference with your approach being I'm writing to a file first).

Could it be a script timeout, an architecture problem (repeatidly response
buffer increases) or a response size limit in the web config ? You could try
to write the content to a file and have a link for donwloading the file to
see how it behaves.

Patrice
 
M

Mark Fitzpatrick

String contactenation is also an expensive operation in .Net. There's a
special class that may actually boost the performance. Look at the
StringBuilder class in the System.Text namespace. It may boost performance a
tad over string contactentation.

StringBuilder buffer = new StringBuilder();
for (int i=1; i<=1024; i++)
buffer.Add("x");
// and to get it out
Response.Write(buffer.ToString());

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
J

James Macbell

I tried putting this in, didn't make a difference. I even tried to turn off
"buffering" in App Option in IIS, same thing.

<%@ Page Language="C#" Buffer="false" %>

I think it is not a performance issue, it is the limitation of ASP.NET
(perhaps there is some configuration in IIS or Registry that I need to
set?). Have you tried to run the code on your server and successfully saved
the 150 MB file to your local HDD? I couldn't....

PHP worked it out without problem, even under Apache for Win32, I am very
impressed. I like both ASP.NET and PHP, don't get me wrong, I am NOT trying
to prove which lang is more superior than the other, I just try to find a
solution to my problem encountered.

James
 
J

James Macbell

I think that's not the problem, because that first Loop only runs for 1024
times. If you insist, try to replace my first loop with yours and run it
the code from your server. See what happens? Are you able to save the 150 MB
file to your local HDD? I couldn't... because IIS stop responding!!! (even
with Page Buffer turn off) But PHP can.

I believe this is a limitation of ASP.NET. Prove me wrong and show me a
code that you can generate 150 MB data and successfully let the client
download it without problem. (NOT allowed to read a file from file system,
to be fair to compare with the PHP code I posted).

I like both ASP.NET and PHP, don't get me wrong, I am NOT trying to prove
which lang is more superior than the other, I just try to find a solution to
my problem encountered.

James
 
S

Scott G.

The below works for me; at least the three or four times I tied it (note that IE's cache doesn't like seeing big files like this, but it did manage to get the file and save). In Mozilla it takes about 10ish seconds to after the save dialog box to get the file to disk.

I'm not sure what the point of this is, nor what you are trying to figure out; I suppose I could crank the string allocation up to a couple of gigabytes and eventually asp_net.exe will barf.... are you just trying to see if you can get a 150mb file from memory out to a browser? Are you just interested in comparing speed between PHP and ASP.NET? How fast did PHP feed this back to you?

Scott

<%@ Import Namespace="System.IO" %>
<%@ Page Language="C#" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
<title>Download Test</title>
<script language="C#" runat="server">
public void Button1_Click(object sender, EventArgs e)
{
int size= 156105356; // 150 MB data
String buffer = "";

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

Response.Clear();
Response.ClearHeaders();
Response.Charset = "";
Response.ContentType = "application/foobar";
Response.AddHeader("Content-Disposition", "attachment; filename=speed.dat");
for (int j=1; j<=size/1024; j++)
Response.Write(buffer);
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
Hello world.
<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click"></asp:button>
</form>
</body>
</html>


I think that's not the problem, because that first Loop only runs for 1024
times. If you insist, try to replace my first loop with yours and run it
the code from your server. See what happens? Are you able to save the 150 MB
file to your local HDD? I couldn't... because IIS stop responding!!! (even
with Page Buffer turn off) But PHP can.

I believe this is a limitation of ASP.NET. Prove me wrong and show me a
code that you can generate 150 MB data and successfully let the client
download it without problem. (NOT allowed to read a file from file system,
to be fair to compare with the PHP code I posted).

I like both ASP.NET and PHP, don't get me wrong, I am NOT trying to prove
which lang is more superior than the other, I just try to find a solution to
my problem encountered.

James
 
J

Jim Butler

I think the main problem is using response.write (i don't really remember
why), i wrote something recently that basically performs downloads in 16mb
chunks because of the way iis handles downloads if you use a straight link
(ie it loads it all in memory to send it to the browser). What i used was
returning a set number of bytes from a file until i got to the end of the
file. and used these methods in my loop

Do While iStartbyte < file.Length And
context.Response.IsClientConnected
buffer = MyCustomObject.GetPartialFileBits(iStartbyte,
iNumBytes)
context.Response.OutputStream.Write(buffer, 0, iNumBytes)
context.Response.Flush()
iStartbyte += iNumBytes
Loop
context.response.end

just my 2 cents

jim
 
J

James Macbell

I apologize for the confusion. Actually I tested it on another server with the same code I posted as well as yours. They both worked... I think something related to my Windows pagefile and diskspace I think. Sorry about that. Thanks for all your help. You guys rock.



The below works for me; at least the three or four times I tied it (note that IE's cache doesn't like seeing big files like this, but it did manage to get the file and save). In Mozilla it takes about 10ish seconds to after the save dialog box to get the file to disk.

I'm not sure what the point of this is, nor what you are trying to figure out; I suppose I could crank the string allocation up to a couple of gigabytes and eventually asp_net.exe will barf.... are you just trying to see if you can get a 150mb file from memory out to a browser? Are you just interested in comparing speed between PHP and ASP.NET? How fast did PHP feed this back to you?

Scott

<%@ Import Namespace="System.IO" %>
<%@ Page Language="C#" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
<title>Download Test</title>
<script language="C#" runat="server">
public void Button1_Click(object sender, EventArgs e)
{
int size= 156105356; // 150 MB data
String buffer = "";

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

Response.Clear();
Response.ClearHeaders();
Response.Charset = "";
Response.ContentType = "application/foobar";
Response.AddHeader("Content-Disposition", "attachment; filename=speed.dat");
for (int j=1; j<=size/1024; j++)
Response.Write(buffer);
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
Hello world.
<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click"></asp:button>
</form>
</body>
</html>


I think that's not the problem, because that first Loop only runs for 1024
times. If you insist, try to replace my first loop with yours and run it
the code from your server. See what happens? Are you able to save the 150 MB
file to your local HDD? I couldn't... because IIS stop responding!!! (even
with Page Buffer turn off) But PHP can.

I believe this is a limitation of ASP.NET. Prove me wrong and show me a
code that you can generate 150 MB data and successfully let the client
download it without problem. (NOT allowed to read a file from file system,
to be fair to compare with the PHP code I posted).

I like both ASP.NET and PHP, don't get me wrong, I am NOT trying to prove
which lang is more superior than the other, I just try to find a solution to
my problem encountered.

James
 
N

Nikolai Chuvakhin

James Macbell said:
I think I have pushed ASP.NET to the limit, I am not sure if I have done
anything wrong in the code because I am trying to make 2 pieces of code (C#
vs PHP) using the same algorithm. Anyways, here is the my test.

How: Create a HTML page with 2 hyper links to these files (posted below).
Right click, Save target As.
Tested: On my P4 1.6 GHz , 1 GB Ram server, Windows 2000 IIS 5 and Apache
1.3 for win32, 100 Mbps LAN
Sample Size: 150 MB download
Result: IIS stopped responding when I tried to download the link to my local
HDD across the 100 Mbps network, then it poped up window saying "request is
unavailable". PHP worked without problem at all, I verified the saved file
was 150 MB on my local HDD.

It's entirely possible that you tested not ASP.NET vs. PHP, but, rather,
IIS vs. Apache. A good check would be to configue PHP to run under IIS
and try the comparison again. If PHP turns out to work faster again,
you are right and the issue is with the scripting language. If PHP
slows down considerably, it means that IIS is to be blamed.

Cheers,
NC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top