The primary difference being the new thread library uses a 1:1 thread model, where as the old library implements a two-level model in which user-level threads are multiplexed over possibly fewer light weight processes. In the 1:1 (or 1x1) model, an user level (application) thread has a corresponding kernel thread. A multi-threaded application with n threads will have n kernel threads. Each user level thread has a light weight process (LWP) connecting it to the kernel thread. Due to the more number of LWPs, the resource consumption will be a little high with 1x1 model, compared to MxN model; but due to the less overhead of multiplexing and scheduling the threads over LWP, 1x1 model performs much better compared to the old MxN model.
Tuning an application with thread environment variables
Within the new thread library (libthread) framework, a bunch of tunables have been provided to tweak the performance of the application. All these tunables have default values, and often the default values are good enough for the application to perform better. For some unknown reasons, these tunables were not documented anywhere except in source code. You can have a look at the source code for the following files at OpenSolaris
Here's a brief description of these environment variables along with their default values:
LIBTHREAD_QUEUE_SPIN
- Controls the spinning for queue locks
- Default value: 1000
- Controls the spinning for queue locks
LIBTHREAD_ADAPTIVE_SPIN
- Specifies the number of iterations (spin count) for adaptive mutex locking before giving up and going to sleep
- Default value: 1000
- Specifies the number of iterations (spin count) for adaptive mutex locking before giving up and going to sleep
LIBTHREAD_RELEASE_SPIN
- Spin LIBTHREAD_RELEASE_SPIN times to see if a spinner grabs the lock; if so, don’t bother to wake up a waiter
- Default value: LIBTHREAD_ADAPTIVE_SPIN/2 ie., 500. However it can be set explicitly to override the default value
- Spin LIBTHREAD_RELEASE_SPIN times to see if a spinner grabs the lock; if so, don’t bother to wake up a waiter
LIBTHREAD_MAX_SPINNERS
- Limits the number of simultaneous spinners attempting to do adaptive locking
- Default value: 100
- Limits the number of simultaneous spinners attempting to do adaptive locking
LIBTHREAD_MUTEX_HANDOFF
- Do direct mutex handoff (no adaptive locking)
- Default value: 0
- Do direct mutex handoff (no adaptive locking)
LIBTHREAD_QUEUE_FIFO
- Specifies the frequency of FIFO queueing vs LIFO queueing (range is 0..8)
- Default value: 4
- LIFO queue ordering is unfair and can lead to starvation, but it gives better performance for heavily contended locks
- 0 - every 256th time (almost always LIFO)
- 1 - every 128th time
- 2 - every 64th time
- 3 - every 32nd time
- 4 - every 16th time (default, mostly LIFO)
- 5 - every 8th time
- 6 - every 4th time
- 7 - every 2nd time
- 8 - every time (never LIFO, always FIFO)
- 0 - every 256th time (almost always LIFO)
- Specifies the frequency of FIFO queueing vs LIFO queueing (range is 0..8)
LIBTHREAD_QUEUE_DUMP
- Causes a dump of user−level sleep queue statistics onto stderr (file descriptor 2) on exit
- Default value: 0
- Causes a dump of user−level sleep queue statistics onto stderr (file descriptor 2) on exit
LIBTHREAD_STACK_CACHE
- Specifies the number of cached stacks the library keeps for re−use when more threads are created
- Default value: 10
- Specifies the number of cached stacks the library keeps for re−use when more threads are created
LIBTHREAD_COND_WAIT_DEFER
- Little bit of history:
The old thread library (Solaris 8's default) forces the thread performingcond_wait()
to block all signals until it reacquires the mutex.
The new thread library on Solaris 9 (default) and later versions, behaves exact opposite. The state of the mutex in the signal handler is undefined and the thread does not block any more signals than it is already blocking on entry tocond_wait()
.
However to accomodate the applications that rely on old behavior, the new thread library implemented the old behavior as well, and it can be controlled with theLIBTHREAD_COND_WAIT_DEFER
env variable. To get the old behavior, this variable has to be set to 1.
- Little bit of history:
LIBTHREAD_ERROR_DETECTION
- Setting it to 1 issues a warning message about illegal locking operations and setting it to 2 issues the warning message and core dump
- Default value: 0
- Setting it to 1 issues a warning message about illegal locking operations and setting it to 2 issues the warning message and core dump
Reference:
Roger Faulkner's New/Improved Threads Library presentation
________________
Technorati tags: Solaris | OpenSolaris
Can you do something to increase the hits on your blog?
ReplyDeleteWho knows where to download XRumer 5.0 Palladium?
ReplyDeleteHelp, please. All recommend this program to effectively advertise on the Internet, this is the best program!