Solved

Writing a very scalable and specialized server

Posted on 2004-09-30
5
291 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Would like to move button in a function 3 76
C++ Language error 28 216
Best book to learn C++ 4 79
White board coding practice 3 88
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

770 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