NSAPI CENTRAL

NSAPI & Threads

Back to NSAPI Central home page

Threading is not of the very frequent question, so this page summarize all the common Q&A on that topic. Thanks to Netscape fellow Robin J. Maxwell for its extensive answers on that subject.

All comments are welcomed: philippe_leberre@hp.com.

Threads Q & A

Is there multiple process or single process with multiple threads ?

  • The Enteprise server operates in either a multi-process/multi-threaded or single process/multi-threaded mode. Multi-process has some performance and reliability advantages on certain OSes. NT version does not support multi-process mode. In the multi-process case, the processes are spawned when the server is started and individual processes are respawned should they die.

How are threads spawned by the server ?

  • Threads are created in each process in groups of approximately RqThrottleMinThreadsPerSocket (default is 50) as needed. Threads are reused to avoid the overhead of creating and destroying them.
    All platforms, except Solaris, attempt to keep RqThrottleMinThreadsPerSocket in accept at any given time. On Solaris, better performance (and to avoid an OS limitation for 2.5.1) are attained if Solaris is limited to a few as 1 thread at a time in accept. For Solaris 2.6 multi-processor systems, it is best to limit the accept threads to 1 per processor and the server should be configured to achieve this.

Does Enterprise killed process after n requests ?

  • Enterprise server does not killed a process unless a shutdown is requested. Note this true for ES 3.x.

What is the Native Threads Pool ?

  • ES 3.x server uses an abstractions portability layer that provides access to the host O/S services like threads. Therefore this layer provides threads that are not always the same as the O/S native threads. These non-native threads have lower scheduling overhead so to improves performance. However, these threads are sensitive to blocking calls such as I/O ones. For NSAPI extensions which uses blocking calls, the server keeps a pool of threads which safely support blocking calls. Usually these threads are native OS threads.
    During request processing any NSAPI function which is not marked as being safe for execution on a non-native thread is scheduled for execution on one of the native threads pool. If you have written your own NSAPI plug-ins such as NameTrans, Service, or PathCheck functions, these will execute on a thread pool thread by default. If your extension makes use of the NSAPI functions for I/O exclusively, or none at all, then it should be fine for it to execute on a non-native thread. To achieve this the function must be loaded with a NativeThread=no. For existing code, add the option NativeThread="no" to the "load-modules" Init line in obj.conf like this: Init funcs="pcheck_uri_clean_fixed_init" shlib="C:/Netscape/p186244/P186244.dll" fn="load-modules" NativeThread="no". The flag affects all functions in the funcs list, so if you have more than one function in a library but only some of them should get the flag use two Init lines.

Are NSAPI functions executing in the Native Thread Pool ?

  • NSAPI functions are not required to execute on the thread pool, only functions that perform blocking I/O calls are required to execute in the pool. Most internal functions do not fall into this category and so execute on the original thread servicing the request. To be safe, functions execute there by default.

How do I set the number of native threads ?

  • The maximum number of native threads that may be in the thread pool which is determined by the setting of the NSCP_POOL_THREADMAX environment variable. This should be set as low as possible to sustain the optimal volume of requests. If you are not saturating your CPU but are seeing requests queue up then you should increase this number.
    On NT, CGI requests execute on a native thread so for smaller NT servers a lower number may actually improve throughput substantially. This is because large numbers of processes are not particularly efficient under NT. A suggested value when CGIs are your primary application load would be ~12/cpu

Can global data structures be shared by threads ?

  • The data structure must be available as a global symbol for all threads to be able to see it. If all of your request threads must have access to the same data one must deal with care with contention lock which can limit performance.

Server starts multiple process but my NSAPI init function is only called once ?

  • That is the case if the init function is called in the magnus.conf, not recommended since ES 2.x, or a LateInit="no" option is set (see this tech note). With LateInit="yes" init functions are executed after the process fork


Back to Top of the Page
Copyright (c) 1997-1998-1999, Philippe Le Berre,
All Rights Reserved.
9/99