Solved

Writing a very scalable and specialized server

Posted on 2004-09-30
5
290 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now