 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ben Hochstrasser [FF] Guest
|
Posted: Wed Dec 24, 2003 11:38 am Post subject: Re: How many sockets per thread |
|
|
Vince wrote:
| Quote: | First I wanted one thread per client, but with over 150 users, I think
it's not a good idea.
|
Why? Seems by far the easiest thing to do - especially you can
"FreeOnTerminate" the thread - saves you a lot of cleanup.
I have apps running with >1000 threads (not 1000 connections, though)
without problems.
What you might want to do is to impose some connection limit, just like
some FTP servers do, so that too many connections won't hog the entire
machine.
--
Ben
|
|
| Back to top |
|
 |
Charles Stack Guest
|
Posted: Wed Dec 24, 2003 3:41 pm Post subject: Re: How many sockets per thread |
|
|
Probably a bigger issue is your network bandwidth. Unless this is running
on a high speed lan, each connection will have a noticable effect on your
available bandwidth. Determine the minimum transfer speed you want for you
clients to experience and then base your maximum number of connections on
that limit.
Charles
"Ben Hochstrasser [FF]" <bhoc@tiscali123^H^H^H.ch> wrote
| Quote: | Vince wrote:
First I wanted one thread per client, but with over 150 users, I think
it's not a good idea.
Why? Seems by far the easiest thing to do - especially you can
"FreeOnTerminate" the thread - saves you a lot of cleanup.
I have apps running with >1000 threads (not 1000 connections, though)
without problems.
What you might want to do is to impose some connection limit, just like
some FTP servers do, so that too many connections won't hog the entire
machine.
--
Ben
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Dec 24, 2003 9:35 pm Post subject: Re: How many sockets per thread |
|
|
"Ben Hochstrasser [FF]" <bhoc@tiscali123^H^H^H.ch> wrote
Because system performance starts to degrade if you have too many threads
running at a time. 150 is not so bad, but what if you had 300 clients
instead? 500? Then you start having problems.
| Quote: | Seems by far the easiest thing to do - especially you can
"FreeOnTerminate" the thread - saves you a lot of cleanup.
|
All that does is frees the threads when they terminate. That has nothing to
do with the system's ability to run the threads in the first place.
| Quote: | I have apps running with >1000 threads (not 1000 connections, though)
without problems.
|
That depends on what the threads are actually doing at the time.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Dec 24, 2003 9:36 pm Post subject: Re: How many sockets per thread |
|
|
"Vince" <niakNOFUCKINGSPAM (AT) bp2k (DOT) net> wrote
| Quote: | May be 8 client socket per thread is a good value
|
You have two ways of supporting that kind of design
1) use asynchronous sockets, and give each thread its own message queue
(since asynchronous sockets use window messages internally)
2) use fibers, where each client is assigned to a fiber, and you have
multiple fibers running inside of a thread.
Gambit
|
|
| Back to top |
|
 |
Colonel Tony Guest
|
Posted: Fri Dec 26, 2003 3:25 am Post subject: Re: How many sockets per thread |
|
|
This is not true, I have client server systems for IM built with synapse and
it runs just fine with 300+ threads on a PIII 500mzh.
Before I ported it from Indy to Synapse, Indy would also run fine with that
many threads.
You will probably run into a wall at 2000 threads depending on hardware.
Of course 300 threads may be a issue for a 200mzh Pentium Pro with 128mb of
ram, but on a modern server with a P4 or Opteron 300 threads is nothing.
| Quote: | Because system performance starts to degrade if you have too many threads
running at a time. 150 is not so bad, but what if you had 300 clients
instead? 500? Then you start having problems.
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Dec 26, 2003 10:37 am Post subject: Re: How many sockets per thread |
|
|
"Colonel Tony" <tcaduto (AT) amsoftwaredesign (DOT) com> wrote
| Quote: | This is not true, I have client server systems for IM built with synapse
and it runs just fine with 300+ threads on a PIII 500mzh. Before I
ported it from Indy to Synapse, Indy would also run fine with that
many threads.
|
That depends on what the threads are actually doing. If most of them are
idle at any given time, then yes, what you describe is feasible. But they
are all actual active doing things at the same time, then that may not be
the case afterall. Also keep in mind that thread instances use up memory
like anything else, so sooner or later with 500+ threads, you will
eventually start to hit on memory limitations, if not performance
limitations.
Gambit
|
|
| Back to top |
|
 |
Damien Honeyford Guest
|
Posted: Sat Dec 27, 2003 1:33 pm Post subject: Re: How many sockets per thread |
|
|
Hi,
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote
| Quote: | Also keep in mind that thread instances use up memory
like anything else, so sooner or later with 500+ threads, you will
eventually start to hit on memory limitations, if not performance
limitations.
|
Exactly, it's not all about processing power -- since TThread creates a new
thread with the same stack size as the primary thread (by default, 1MB), 500
threads would chew 500MB of virtual memory. Even if most of these threads
were sleeping, and hence taking no processing power you would still be using
a lot of memory for nothing.
Damien
|
|
| Back to top |
|
 |
Ben Hochstrasser [FF] Guest
|
Posted: Sat Dec 27, 2003 1:45 pm Post subject: Re: How many sockets per thread |
|
|
Damien Honeyford wrote:
| Quote: | Exactly, it's not all about processing power -- since TThread creates
a new thread with the same stack size as the primary thread (by
default, 1MB), 500 threads would chew 500MB of virtual memory.
|
Is there anything one could tweak so a new thread would create a smaller
stack?
--
Ben
|
|
| Back to top |
|
 |
Jack Mays Guest
|
Posted: Sat Dec 27, 2003 3:49 pm Post subject: Re: How many sockets per thread |
|
|
"Ben Hochstrasser [FF]" <bhoc@tiscali123^H^H^H.ch> wrote
| Quote: | Damien Honeyford wrote:
Exactly, it's not all about processing power -- since TThread creates
a new thread with the same stack size as the primary thread (by
default, 1MB), 500 threads would chew 500MB of virtual memory.
Is there anything one could tweak so a new thread would create a smaller
stack?
|
In the project options on the linker tab there is a place where you can
specify the min and max stack size. Below are some values it can be :)
----
Changed the MAX stasck size from (hex) $00100000
(1048576 bytes) to (hex) $00080000 (524288 bytes)
$00100000 = 1,048,576 bytes
$00080000 = 524,288 bytes
$00040000 = 262,144 bytes
$00020000 = 131,072 bytes
$00010000 = 65,536 bytes
$00008000 = 32,768 bytes
$00004000 = 16,348 bytes
----
HTH
--
Jack Mays
|
|
| Back to top |
|
 |
Ben Hochstrasser [FF] Guest
|
Posted: Sat Dec 27, 2003 4:02 pm Post subject: Re: How many sockets per thread |
|
|
Jack Mays wrote:
| Quote: | In the project options on the linker tab there is a place where you can
specify the min and max stack size. Below are some values it can be
|
Thanks Jack, but that wasn't quite what I was after; is there a way of
setting the stack size *per thread* ?
--
Ben
|
|
| Back to top |
|
 |
Jack Mays Guest
|
Posted: Sat Dec 27, 2003 5:10 pm Post subject: Re: How many sockets per thread |
|
|
"Ben Hochstrasser [FF]" <bhoc@tiscali123^H^H^H.ch> wrote
| Quote: | Jack Mays wrote:
In the project options on the linker tab there is a place where you can
specify the min and max stack size. Below are some values it can be :)
Thanks Jack, but that wasn't quite what I was after; is there a way of
setting the stack size *per thread* ?
|
No problem, but honestly i dont know the answer to that question.. It would
be nice to be able to create threads with different stack sizes than the min
thread, but i dunno if that even possible.
--
Jack Mays
|
|
| Back to top |
|
 |
Tony Caduto Guest
|
Posted: Sat Dec 27, 2003 8:16 pm Post subject: Re: How many sockets per thread |
|
|
Ok, here is the deal, you set your maxstack size to 16k with a compiler
directive like this:
{$MAXSTACKSIZE $00004000}
Put the above line in your DPR file at the top.
I have not had a problem with setting it this low and it seems to grow as
needed.
You might want to avoid massivly recursive routines though, just to be safe.
With a maxstacksize of 16k you can create thousands of threads with no
problem.
So if you have a fast server with 2gb+ of ram you will be able to have lots
of threads that do real work.
Of course IOCP and or overlapped IO are a better solution,but they are alot
more work to implement, unless you wait for a stable INDY 10 which has this
feature.
In the meantime if you set your maxstacksize to 16k and you will not have
problems.
Also do not use a FORM for your server, set it up in a non interactive
service.
Colin Wilson has a real nice non bloated service framework that you can
debug easily through the IDE
http://www.wilsonc.demon.co.uk/Delphi3Components/NTService/NTService.ZIP
For newer version of Delphi you have to change a couple of varible types,
but it works great even on XP.
I also recomend you use Synapse for custom protocol servers, it is great and
super fast, I would say unofficially that it is faster than INDY and DXSOCK.
http://www.ararat.cz/synapse/
See the echo server on how to do multithreaded servers. Using the echo
server as a base it is a piece of cake.
Tony
|
|
| Back to top |
|
 |
Ben Hochstrasser [FF] Guest
|
Posted: Sat Dec 27, 2003 9:10 pm Post subject: Re: How many sockets per thread |
|
|
Tony Caduto wrote:
| Quote: | Ok, here is the deal, you set your maxstack size to 16k with a
compiler directive like this:
{$MAXSTACKSIZE $00004000}
Put the above line in your DPR file at the top.
I have not had a problem with setting it this low and it seems to grow
as needed.
You might want to avoid massivly recursive routines though, just to be
safe.
|
Thanks, I'll try my best to remember that.
| Quote: | Also do not use a FORM for your server, set it up in a non interactive
service. Colin Wilson has a real nice non bloated service framework
(...)
|
I wholeheartedly second this advice. Never had any problems with Colin's
NTService. Besides, it nearly seemlessly integrates with synapse's echo
server (using its main thread as the service thread).
| Quote: | I also recomend you use Synapse for custom protocol servers, it is
great and super fast, I would say unofficially that it is faster than
INDY and DXSOCK. http://www.ararat.cz/synapse/
|
Heresy! <giggle>
| Quote: | See the echo server on how to do multithreaded servers. Using the
echo server as a base it is a piece of cake.
|
Hey! This the advice I give others when they're about to write their
first TCP server! :)
--
Ben
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Dec 27, 2003 10:11 pm Post subject: Re: How many sockets per thread |
|
|
"Ben Hochstrasser [FF]" <bhoc@tiscali123^H^H^H.ch> wrote
| Quote: | Is there anything one could tweak so a new thread
would create a smaller stack?
|
Not with TThread. You would have to create and manage the thread object
manually by calling the Win32 API CreateThread() function directly. It has
a dwStackSize parameter.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Dec 27, 2003 10:14 pm Post subject: Re: How many sockets per thread |
|
|
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote
| Quote: | by calling the Win32 API CreateThread() function directly
|
Alternatively, you can also use the VCL's BeginThread() function, which also
has a StackSize parameter (and calls CreateThread() internally).
BeginThread() is the function that TThread uses, specifying 0 for the stack
size, which is the same as using the stack size of the main process.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|