Jason Whitehorn

MarshalByRefObject.net
posts - 50, comments - 26, trackbacks - 6

My Links

News

Archives

Post Categories

.NET

Java

Proud Member Of...

XNA

aspNETserve Version 1.0

UPDATE (12/17/2007): My blog has moved. This post is now located at: http://jason.whitehorn.ws/2007/06/14/aspNETserve+Version+10.aspx




Just today version 1.0 of aspNETserve was released. This version fixes all known major bugs, and represents a feature complete version in regards to aspNETserve's original goals. Specifically this means that it can host any ASP.NET 2.0 web application without the need for Internet Information Services (IIS).


Originally intended to be a learning tool for myself, aspNETserve has quickly turned into a viable alternative for the ASP.NET development web server. Additionally, the libraries that compose aspNETserve can be referenced from your own applications to include a full featured ASP.NET web server right into your next project.

To include an ASP.NET web server in your application, you will need to reference aspNETserve.Core, and aspNETserve. You can use the aspNETserve.Server object to control your own in-memory ASP.NET web server. For an example of doing just that, see the SimpleWebServer project that is available as part of the aspNETserve source download.

Print | posted on Thursday, June 14, 2007 9:49 PM | Filed Under [ ASP.NET ]

Feedback

Gravatar

# re: aspNETserve Version 1.0

Hi there,

I was looking through your code briefly and saw some things that might improve performance.

Specifically in this file:
http://www.codeplex.com/aspNETserve/SourceControl/FileView.aspx?itemId=68991&changeSetId=5720

I saw you're storing your data buffer in a List<byte>. This is very inefficient when it comes to memory usage because of the way linked lists operate. A generic List generally is defined along these lines:

public class List<T>
{
Node<T> head, tail;
int count;
private class Node<T>
{
public T Data;
public Node<T> Next, Previous;
}
}

Now, I will say that it's certainly not the case in the .NET System.Collections.Generic.List<T>. Quick disassembly shows that the inner data content is stored as an array of T. Insertions are performed by splitting the array and appends (calling .Add(T)) copy the array if it's full to a new, expanded array.

It'll (generally) cause substantially less heap fragmentation if you can avoid using a List<byte> because you'll avoid the extra allocations internally. One thing that you can do once you know the amount of data that's incoming is use a reading loop (sorry for the line numbers, it's copied from a web app hosting my code, not on this machine):

160 public virtual byte[] Receive(int len)
161 {
162 byte[] incBuffer = new byte[len];
163 int totRecv = 0;
164 if (!m_open)
165 return null;
166
167 NetworkStream localNS = m_client.GetStream();
168 while (m_open
169 && m_client.Connected
170 && totRecv < len)
171 {
172 try
173 {
174 totRecv += localNS.Read(incBuffer, totRecv, (int)len - totRecv);
175 }
176 catch (IOException se)
177 {
178 Close();
179 OnError("A read error occurred on the connection.", se);
180 }
181 }
182
183 return incBuffer;
184 }

Using HTTP, you might also have luck using a NetworkStream with a StreamReader. Utilizing StreamReader's ReadLine() method you can get line-by-line HTTP headers.

In any case, hopefully this gives you some ideas as to how you can improve your server's efficiency. :) Some time, take a look at your app using CLR Profiler.

Cheers :)

(Sorry if this gets posted twice)
6/15/2007 1:31 AM | Rob
Gravatar

# re: aspNETserve Version 1.0

Hey,

Thanks for your feedback. At this point that code is nearly a year old. When I wrote it I had known that it was a bit of a hack, and I had always intended to go back and refactor it. But, as those things tend to go, it slipped my mind.

So I do truly appreciate you pointing that out to me. I am currently looking on how to incorporate your suggestions into aspNETserve.

Thanks again,
Jason Whitehorn
6/16/2007 10:43 AM | Jason Whitehorn
Comments have been closed on this topic.

Powered by: