Solved

Writing a very scalable and specialized server

Posted on 2004-09-30
5
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

623 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