Solved

Writing a very scalable and specialized server

Posted on 2004-09-30
5
292 Views
Last Modified: 2006-11-17
I've got the task of creating a server that simply recieves a connection and ~500 bytes of data immediately, then sends a few bytes of data and closes the connection. So I'm dealing with very short-lived connections, but I need to handle as many as possible.

I'm using winsock, and the server is a XP Pro machine with 2GB of memory and dual CPUs.

There seems several strategies for writing such a server, blocking, asynchronous, multi-threaded, single threaded, 2 threads per CPU, overlapped IO, and using IO completion ports.

AcceptEx() seems like a handy function (works with overlapped IO using either windows events or completion ports), in that it accepts a connection and recieves the first bit of data (which is all the data in my case) I then only need to send the response (simply a minimal http 404 response) and then close the connection. The processing on the data simply involves a hash table lookup and appending the buffer as is to a linked list. A seperate worker thread traverses the hash table at intervals looking for stale data and saving it to a database.

What kind of server model would suit me best?

Thanks for any information on the subject,
-Sandra
0
Comment
Question by:Sandra-24
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 350 total points
ID: 12194073
I'd suggest the completion port approach - simply because this technology is (even since VMS) *the* base technology in the NT architecture and therefor *probably* scales best. A great sample can be found here: http://win32.mvps.org/network/sockhim.html (code at http://win32.mvps.org/network/sockhim.zip - plain C :o)
0
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 75 total points
ID: 12194445
Yep, that  AcceptEx() thing is one thing Microsoft did well, putting a whole lot of your basic connection startup code right into the TCP kernel.  Can't beat that with a stick.

0
 
LVL 1

Assisted Solution

by:drush_koders
drush_koders earned 75 total points
ID: 12196177
AcceptEx is the API apache uses.  You can see the actual Apache implementation here:
http://www.koders.com/c/fid0BD8A00D9DD136B078A793D719E26E389C0E8F95.aspx?s=AcceptEx

Hopefully this can help you get started a bit quicker.
0
 
LVL 1

Expert Comment

by:drush_koders
ID: 12196205
I would also suggest that you leverage an existing server like Apache or IIS to do the legwork for handling connections etc. for you.  If possible, you should build your app on a higher layer, possibly using modules for apache or ISAPI filters on IIS.  

At least for the first round, this will be the fastest way to get a functional application, and you can build your own server later if needed - but I wouldn't expect you really want to get into that business if you can avoid it.  The Apache team has spent a lot of optimizing and making custom extensions fast.  

0
 
LVL 3

Author Comment

by:Sandra-24
ID: 12196650
Well that makes things simpler, AcceptEx with completion ports it is.

You've got a good idea about Apache drush, but I'm going to do things the hard way. I value the experience at least as much as the end result. The way I figure it, it should only be about 1500-2000 lines for the network oriented code. How long could that take? I'll guess 2 weeks, which means it'll probably be done at the end of October, but I'll be able to put winsock programming with completion ports on my resume :)

Thanks guys,
-Sandra
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question