From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7344,3ca4240a4c402bae X-Google-Attributes: gidf7344,public X-Google-Thread: fc89c,3ca4240a4c402bae X-Google-Attributes: gidfc89c,public X-Google-Thread: fee84,3ca4240a4c402bae X-Google-Attributes: gidfee84,public X-Google-Thread: 11035d,3ca4240a4c402bae X-Google-Attributes: gid11035d,public X-Google-Thread: ffc1e,3ca4240a4c402bae X-Google-Attributes: gidffc1e,public From: Bart Smaalders Subject: Re: pthreads and sockets Date: 1996/12/06 Message-ID: <32A8A6A8.C1@eng.sun.com>#1/1 X-Deja-AN: 202758484 distribution: inet references: <589ceq$g76$1@asgard.sprintlink.co.za> content-type: text/plain; charset=us-ascii organization: Sun Microsystems, Inc mime-version: 1.0 newsgroups: comp.programming.threads,comp.unix.osf.osf1,comp.unix.solaris,comp.unix.programmer,comp.os.vms x-mailer: Mozilla 2.0 (X11; I; SunOS 5.6 sun4u) Take a look at name_cache.c for an alternative approach in our book, "Programming with Threads". The examples may be downloaded from: http://www.Sun.COM:80/smi/ssoftpress/threads/index.html Spawning 1000 threads may make sense if you have a really big MP and the duty cycle (%active time) of each thread is really high. For most systems where clients are idle most of the time (due to think time, etc), dispatching each actual request to a thread will result in less resource consumption, better cache behavior, etc. For example, supppose in the limiting case only one client request was active at a time. Using separate threads would force each thread stack to be brought into the cache (or worse, into memory), while simply using a LIFO queue of service threads would produce much better performance. In general, controlling the amount of concurrency using a workpile style technique results in more easily tuned applications, and ones that behave more reasonably under unreasonable loads. - Bart philip Shearer wrote: > > I am assessing the possibility of replacing a network communications > subsystem with a TCP/IP implementation using pthreads. It is the > first pthreaded application I have attempted , but I have a lot > of experience of this type of application on various UNIX systems > using sockets and fork(ing). > > At the moment the sub-system runs as a server on VMS and a client > on MS-Windows using UDP on one PORT. Built into the comms layer is > an in-house reliable connection mechanism between the VMS server > MS-Windows clients. > > The current sub-system works for about 550 connections but it is > starting to become flaky as more clients are added. > > The development (of the server software) will be done on Solaris > x86 V 2.5.0 and Digital UNIX 4.0. > > Ideally the server code should be portable to a VMS platform. > > Is is there anything that we need to do to the kernels of the > 3 systems to allow for 1000 TCP connections? > > Is there any software on the Net which does this task or > something similar. > > If not then at the moment I envisage having : > > One thread accepting connections and creating one new thread > per connection. (Accepter) > > One thread read-blocking on the each socket connection. Each > thread will write to an internal IPC that is connected to the > main application.(Reader) > > One thread will read from an internal IPC to receive processed > messages from the main application. (Dispatcher) > > One thread per-connection which will block waiting for the > Dispatcher to send it a message with it will send out onto > the network. (Writer) > > Is there a simple method by which the Dispatcher can multiplex > to the correct Writer (assuming that any info needed to do this > can be prefixed to the outgoing message by the main application) > Or will I be forced to implement some sort of structure/lookup table > containing a mutex lock for each Writer? > > Is there a better way to write this sort of code? > > -- > Regards Philip Shearer > > eMail: philips@asiatech.co.za > Tel +27 (0)11 784 8925 > Fax +27 (0)11 784 8919 -- Bart Smaalders Solaris Clustering SunSoft barts@cyber.eng.sun.com (415) 786-5335 MS UMPK17-301 http://playground.sun.com/~barts 2550 Garcia Ave Mt View, CA 94043-1100