Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SocketServer: how would YOU do it ?

0 views
Skip to first unread message

Cult

unread,
Nov 25, 2003, 10:26:26 AM11/25/03
to
I have a project, i need to write a serverapplication (which in the end
should end up as a Service application).

It should run on Win2K / Server.

The application has to open port 4500 for incoming socketconnections - and
there is approximately 10<2000 simultanously connections.

The process for each socketconnection (thread) is reading small chunks of
data, and save theese in a global structure - for use for the mainprogram.
Some of the connections needs to have a reply sent back to it from time to
time - but it differs from the input.

I have made several small serverapplications, but never any with up to 2000
connections, so i browsed the internet...

And its a jungle ?

Found alot of links to examples, but im afraid of choosing wrong here - i
can see there is talk about blocking/non-blocking/IO-Completion ports and on
and on.

I want to write everything in Win32 - dont want to use any 3rd part
products.

But what is the right way to do what i want here ? What do you recommend of
approach ? - and do any of you have a link to an example layout i can base
my code on - which is stable ?

2000 connections - it isnt very much i am to do for each, but is it really
possible to run 2000 threads without problems ?

really hope you can help, thanks.


SenderX

unread,
Nov 25, 2003, 11:05:46 AM11/25/03
to
> Found alot of links to examples, but im afraid of choosing wrong here - i
> can see there is talk about blocking/non-blocking/IO-Completion ports and
on
> and on.

Use IOCP.


> But what is the right way to do what i want here ? What do you recommend
of
> approach ? - and do any of you have a link to an example layout i can base
> my code on - which is stable ?

This a good, simple and straight forward tutorial IOCP server in C++:

http://www.jetbyte.com/portfolio-showarticle.asp?articleId=37&catId=1&subcatId=2


> 2000 connections - it isnt very much i am to do for each, but is it really
> possible to run 2000 threads without problems ?

You can handle 2000 connections with 2 threads per. processor.

Piece of cake!


> really hope you can help, thanks.

I am an expert in IOCP. I specialize in servers that handle
tens-of-thousands of concurrent connections, and can help you write
super-scaleable code. But, I use "VERY ADVANCED Lock-Free Algorithms" and
advanced multi-processor/hyperthread methods mixed with specialized
lock-free Garbage Collectors to get all that needed performance.

2000 connections will probably not need screaming high-performance
garbage-collected shared collections, but I can help you if you think you
need them... Like if you think 2000 clients, could jump to 35,000+ clients!

;)

Post questions to alt.winsock.programming for further discussion.


> The process for each socketconnection (thread) is reading small chunks of
> data, and save theese in a global structure - for use for the mainprogram.

Well now, this is where a High-Performance Collection would come into
play...

I can help you make this shared central collection scale beyond you wildest
dreams if you can understand very advanced scalability methods...

=P

P.S.

More links:

http://msdn.microsoft.com/msdnmag/issues/1000/winsock/default.aspx

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/i_o_completion_ports.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndllpro/html/msdn_servrapp.asp

http://support.microsoft.com/default.aspx?scid=kb;EN-US;192800

http://www.jetbyte.com/portfolio-showarticle.asp?articleId=37&catId=1&subcatId=2

http://www.jetbyte.com/portfolio-showarticle.asp?articleId=38&catId=1&subcatId=2

http://www.jetbyte.com/portfolio-showarticle.asp?articleId=39&catId=1&subcatId=2

http://www.jetbyte.com/portfolio-showarticle.asp?articleId=44&catId=1&subcatId=2

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsaeventselect_2.asp

http://www.codeproject.com/internet/networkevents.asp


--
The designer of the experimental, SMP and HyperThread friendly, AppCore
library.

http://AppCore.home.comcast.net


Sin

unread,
Nov 25, 2003, 11:12:09 AM11/25/03
to
> But what is the right way to do what i want here ? What do you recommend
of
> approach ? - and do any of you have a link to an example layout i can base
> my code on - which is stable ?
>
> 2000 connections - it isnt very much i am to do for each, but is it really
> possible to run 2000 threads without problems ?

2000 threads is definitly not a good approach. A single thread would work
but you would not have good response time or throughut. You need to design a
model in which there is a configurable amount of worker threads (I would
guess 10 to 20 threads should suffice to obtain good performance). Have your
main accept connections and also check which connected sockets have pending
requests. Distribute those sockets evenly between the worker threads, and
repeat...

Alex.


Cult

unread,
Nov 25, 2003, 1:55:44 PM11/25/03
to
wow, thanx alot !

I have been looking at both the jetbyte and the codeproject pages for some
time, and now i guess you are really going to call me lame, but im using
Borland C++ Bulder 6.0 as development envoirment :( - i would really love to
avoid any MFC or VC specialities ? my dream was a console-based example of a
very simple server.

I found an example of a simple threaded server on codeproject:

http://www.codeproject.com/internet/ChessServer.asp#xx200568xx

A simple telnetbased chessgame server, which im able to compile and run
under the Borland Envoirment - but apparently this has a few bugs especially
about cleanup.

As i understand the sources from JetByte, it cannot run without .NET - and
is not easily modifed so i can use it in Borland ?

I know this is "offtopic" - but hoped you might tell me that the JetByte
sources was easily used in Borland envoirment ;) i will though ask specific
Winsock questions in the other newsgroup - which were new to me.

Thanks again !

"SenderX" <x...@xxx.xxx> skrev i en meddelelse
news:u5Lwb.228159$9E1.1249418@attbi_s52...

Boris Dynin

unread,
Nov 26, 2003, 1:45:46 AM11/26/03
to
I would use IO Completion Ports. It's MS-recommended way for developing
scalable applications.
Look in "Programming Server-Side Applications for Windows 2000" by J.
Richter and J. Clark (ISBN 0-7356-0753-2). The book explains how IO
Completion Ports work. The examples in the book cover file i/o. However,
'socket' is just a file handle in Windows. So, examples in the book are
applicable.
Windows supports Unix style socket programming: using 'select' function.
However, MSDN doesn't recommend using 'select' for high-performance
applications.

Boris

"Cult" <cu...@nospamuunospam.aa> wrote in message
news:3fc374a1$0$29406$edfa...@dread15.news.tele.dk...

Bob Moore

unread,
Nov 26, 2003, 9:15:13 AM11/26/03
to
On Tue, 25 Nov 2003 16:26:26 +0100, "Cult" <cu...@nospamuunospam.aa>
wrote:

>I have a project, i need to write a serverapplication (which in the end
>should end up as a Service application).
>
>It should run on Win2K / Server.
>
>The application has to open port 4500 for incoming socketconnections - and
>there is approximately 10<2000 simultanously connections.

You need to look at IO Completion Ports and probably also thread
pooling. There is example IOCP code available here :

www.mvps.org/win32/network/sockhim.html

SenderX

unread,
Nov 26, 2003, 2:18:33 PM11/26/03
to
> my dream was a console-based example of a
> very simple server.

Blocking Server:

http://tangentsoft.net/wskfaq/examples/basics/basic-server.html


Non-Blocking Server:

http://tangentsoft.net/wskfaq/examples/basics/select-server.html


JetByte will show off IOCP.


> As i understand the sources from JetByte, it cannot run without .NET - and
> is not easily modifed so i can use it in Borland ?

Wrong.

JetByte will build with VC++ 6, and you don't even have to have the Platform
SDK.


> I know this is "offtopic" - but hoped you might tell me that the JetByte
> sources was easily used in Borland envoirment ;)

Probably.

I use GCC and VC++.

P.S.

I sounds like your a newbie?

If you are, you WILL NEED to become familiar with the more advanced methods
of server design to handle 2000 connections.

Study up!

:)

Cult

unread,
Nov 26, 2003, 3:41:15 PM11/26/03
to
Thanx alot, bob ! ;)

"Bob Moore" <bo...@mvps.org> skrev i en meddelelse
news:45d9svohm41ktmrnq...@4ax.com...

Cult

unread,
Nov 26, 2003, 4:28:51 PM11/26/03
to
There has been a change in demand - its more likely that the server should
handle max. 100-200 simultanious connections (not 2000 as first stated).

The difference now, is that approximatly 100 of theese connections are
static - the client connects, and stays connect for a possible long time;
sometimes the client will report to the server - but it can vary in time.

IO/Completion ports - as i understand it, will kill idle connections
otherwise it can stall the concept with idle threads/connections if there
isnt any data streaming through.

This raises some more questions, that i will ask in
alt.winsock.programming - since im probably way off-topic already in here
:( sad since you are all here !! - but guess thats the right way to do it,
since i will keep asking for a long time i think.

Thanks alot for your help all !


SenderX

unread,
Nov 26, 2003, 4:39:00 PM11/26/03
to
> IO/Completion ports - as i understand it, will kill idle connections
> otherwise it can stall the concept with idle threads/connections if there
> isnt any data streaming through.

Huh?

No way!

IOCP will not kill idle connections!

Your confusing the fact that you have to kill stale "buffered" AcceptEx's.

IOCP will not magically kill pending WSARecv's at all, unless you
closesocket or the remote end closes.

If IOCP operated the way you think it does, it would be hopelessly broken
beyond repair.

Cult

unread,
Nov 27, 2003, 3:14:46 PM11/27/03
to
http://www.mvps.org/win32/network/sockhim.html

This example i have downloaded, and it works very well - a nice example. But
it kick off 64 threads as i understand it ? is that smart ?

0 new messages