SocketServer design

S

Stuart

I need to write a socket server that accepts around 100 connections, but
this could grow to a 1000, or more in time. The data throughput will be
minimal, mostly in short random bursts, but it's important those
connections stay active.

Having googled a bit, I understand there is a limit of 64 socket
connections in .NET? How do you overcome that? Should I be creating a
new Thread for every connection? It seems a bit wasteful, given the
small amounts of data. (as little as 30 bytes in a 2 minute burst).

Stuart.
 
C

Chad Z. Hower aka Kudzu

Stuart said:
Having googled a bit, I understand there is a limit of 64 socket
connections in .NET? How do you overcome that? Should I be creating a

http://www.indyproject.org/ - Free with source.
new Thread for every connection? It seems a bit wasteful, given the
small amounts of data. (as little as 30 bytes in a 2 minute burst).

Depends. Can you use UDP or must it be TCP?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
 
S

Stuart

Having googled a bit, I understand there is a limit of 64 socket

Looks interesting - Thanks. I would like to avoid a 3rd party library
if possible, as I may look at porting this over to Linux/Mono later.
Worth a look though.


Depends. Can you use UDP or must it be TCP?

Has to be TCP. I'm writing a gateway/proxy server for clients that
already exist.

S.
 
C

Chad Z. Hower aka Kudzu

Stuart said:
Looks interesting - Thanks. I would like to avoid a 3rd party library
if possible, as I may look at porting this over to Linux/Mono later.
Worth a look though.

Its free - and has source. The .NET one is usuable, but very limited:
http://www.indyproject.org/Features.iwp
Has to be TCP. I'm writing a gateway/proxy server for clients that
already exist.

Once you are at about 1,000, threads definitely begin to become an issue. 99%
of servers should be threaded, but in your case Id prob place it in the 1%
that shouldnt be if its just doing the small data passing and not much
session logic.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
 
C

Chad Z. Hower aka Kudzu

Laxmikant Rashinkar said:
I wrote a program that has 250 socket connections open simultaneously on
the server side
and it works just fine. I used a thread per connection. Although it was
not the ideal solution,

205 threads is fine, but this user was talking 1,000. 1,000 is fine too, but
in his situation it didnt sound like a good match for threads anways.



--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
 
W

William Stacey [MVP]

You can have more then 64 open sockets. That begs a question on how many
you can actually create per process? Anyone know for sure or is limited
only by memory? You probably want to use a thread pool as others have said
if you will have that many connections at same time (or use async sockets
which some really like and others don't like so much). An interesting
server that uses this method is the open source Cassini Web server by MS.
Also used in their WebMatrix tool. IIRC, it uses the std thread pool to
queue connections and handle them via the queue. Worth looking at for tips
on how others approached the issue.

http://www.asp.net/Projects/Cassini/Download/
"Explore and Extend the Cassini Web Server"
http://www.devx.com/dotnet/Article/11711/0/page/1
 
C

Chad Z. Hower aka Kudzu

William Stacey said:
You can have more then 64 open sockets. That begs a question on how many

64 sockets is a Windows limitation on how many sockets can be passed to
wait and other system calls, etc. The .NET socket component *may* have some
calls that are affected by this limit.
you can actually create per process? Anyone know for sure or is limited
only by memory? You probably want to use a thread pool as others have
said

Neither. Its limited by the size of the non-page pools. The size of the non
page pool depends on the OS and somewhat on RAM. But at max its never ever
more than 256 MB in Windows. Each socket varies in size depending on
options and whether its a client or a server socket. Min is 1.5k for
servers, 2k for clients. But typical is 4k.
if you will have that many connections at same time (or use async sockets
which some really like and others don't like so much). An interesting

1,000 is nothing to worry about.
server that uses this method is the open source Cassini Web server by MS.
Also used in their WebMatrix tool. IIRC, it uses the std thread pool to
queue connections and handle them via the queue. Worth looking at for
on how others approached the issue.

Wont work if he needs persistent connections, which based on the little bit
of info he provided probably does.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
 
S

Stuart

William said:
You can have more then 64 open sockets. That begs a question on how many
you can actually create per process?

Well it seems to be 64. Interestingly, if I run the same test program
binary on Linux/Mono, it bombs out at 1011 connections, not 64.

Stuart.
 
W

William Stacey [MVP]

Well it seems to be 64.

Depends. As Chad said, you can only wait on 64 using one of the win32 wait
methods - that is were that number comes up. If the server is a
request/reply (i.e. web), then you can have much more by using a thread pool
or thread per connection. If you use an Async design, then you can also
have many more, as the IOCP thread pool handles the callbacks.
Interestingly, if I run the same test program
binary on Linux/Mono, it bombs out at 1011 connections, not 64.

What kind of server design? Seperate threads, thread pool, async? Sounds
like maybe a thread per connection design as around 1000 you start hitting a
memory issue as shown in prior posts.
 
W

William Stacey [MVP]

Check out the following:
"4.8 - How many simultaneous sockets can I have open with Winsock?"
"4.9 - What are the "64 sockets" limitations?"
http://tangentsoft.net/wskfaq/advanced.html#maxsockets

If you want to keep using Select(), it would seem you need to use multiple
threads and selecting on 64 per thread. That would seem to get messy so I
might instead go with async sockets or a threaded server if your connections
will be <= ~1000.
 
P

peter markson

FROM. FROM.PETER MARKSON
ADDRESS.MOTHER THREASA CAMP ABIDJAN COTE D'IVOIRE
TEL.22507557724
EMAIL ADDRESS. (e-mail address removed)

CONFIDENTIAL

Dear Sir,


I am PETER MARKSON the only son of late former Director of
finance,Chief Vincent Markson Sierra-Leone diamond and mining
corporation. I must confess my agitation is real, and my words is my
bond, in this proposal. My late father diverted this money meant for
purchase of ammunition, for my country, during the peak of disastrous
civil war in my country, now he has deposited the money with BANK in
Abidjan, where I am residing under political asylum with my younger
sister.

Now the war in my country is over with the help of ECOMOG soldiers, the
present government of Sierra Leone has revoked the passport of all
officers who served under the former regime and now ask countries to
expel such person at the same time freeze their account and confiscate
their asset, it is on this note that I am contacting you, all I needed
from you is to furnish me with your bank particulars:
1) Account name
2) Account number
3) Bank address, telephone and fax number
For you to assist me transfer this money in your private bank account,
the said amount is (NINE Million Dollars) $9 Million. I am compensating
you with 15 % of the total money amount, now all my hope is banked on
you and I really wants to invest this money in your country, were their
is stability of Government, political and economic
welfare.
Honestly I want you to believe that this transaction is real and never a
joke. My late father Chief Markson gave me the photocopies of the
certificate of deposit issued to him by BANK on the date of deposit, for
you to be clarify because, I do not expose my self to anybody I see, I
believe that you are able to keep his transaction secret for me because
this money is the hope of my life, it is important.
Please call me immediately after you must have gone through my message
fill free and make it urgent. That is the reason why I offered you 15 %
of the total
money amount, and in case of any other necessary expenses you might
incur during this transaction.
N.B Try and negotiate for me some profitable blue chip investment
opportunities which is risky free which I can invest with this money
when it is transferred to
your account, personally I am interested in estate management and hotel
business, please advise me. Call me back immediately you receive this
message for
more explanation.And promisse me my younger sister to be a father
considering our situation and not to betray us.

Thanks and God bless
Best regards
PETER MARKSON

NB: my late father used me the only son as the beneficiary / next of kin
on the day of deposit and also told me I need a foreign assistance of a
foreigner with a legitimate bank Account abroad who will stand as
co-beneficiary and partner abroad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top