How does Progress use semaphores?
Semaphores are used as a mechanism to enable a process to
wait for various kinds of events to occur within the database manager when it is running in multi-user mode. When a process is waiting on a semaphore, it is not using any CPU time, except once a minute when a timer interrupts the wait to check for error conditions or record lock wait timeouts.
On single-processor systems:
- OpenEdge uses semaphores to synchronize the activities of server and self-service client processes currently connected to a database.
- By default, each database uses an array of semaphores, which includes one semaphore for each user or remote server process.
- Each process uses its semaphore when it must wait for a shared resource.
- Semaphores are not used for single-user sessions or for client sessions connecting client/server to the database.
- As of OpenEdge 10.1A the default number of semaphore sets (-semsets) is three.
- For further information refer to Article: How to and Why Use Multiple Semaphore Sets (-semsets option)?
On multi-processor shared-memory systems:
- The Enterprise database engine uses a spin lock algorithm to control access to shared-memory structures. Spin locks cover short-term waits, which are latches used by the database storage engine to protect the database during critical activity such as shared memory lookup and updates.
- Semaphores will be used as outline above when a non-Enterprise database license is used.
- Semaphores will be used less when an Enterprise database license is used and the database startup parameter -spin is set, but they will still be used. Semaphores are always used for long-term waits (such as a wait for a record lock), regardless of the setting of -spin.
- Semaphores are not used in single-user mode or on the client side when a database is being accessed client-server over a network.
- For further information refer to Articles: What is the -spin parameter? & How to and Why Use Multiple Semaphore Sets (-semsets option)?
A semaphore-based waiting mechanism is used in the following situations:1. The Broker uses a semaphore to indicate the database is not ready for use during the time it is initializing during startup. This semaphore is checked before allowing connections to the database.
2. When a process connects to a database, the Broker allocates an entry in the user table before it can use any of the other locking mechanisms or use shared data structures. A
login semaphore is used for this purpose to prevent two processes from taking the same slot. This same semaphore is used when freeing a slot during disconnect.
3. When a process encounters a record lock conflict, it uses a semaphore to wait until the lock holder wakes it up. For example: When you want an exclusive lock on a row and someone else already has a share lock. You have to wait until the share lock is released.
4. When a process encounters a condition such that it must wait for another transaction to end before it can proceed, a semaphore is used to wait for the other transaction to end. For example: When a unique index entry has been deleted but the deleting transaction has not committed and you want to insert a new index entry with the same key value. You have to wait for the transaction to commit before you know if the index entry is really deleted.
5. When a process wants an exclusive schema lock and other processes already have share locks, a semaphore is used while waiting.
6. There are a variety of internal database operations on shared memory data structures which can involve holding a lock for several milliseconds, possibly doing disk i/o while holding the lock. Semaphores are used for such
long-term waits7. When -spin is not being used, semaphores are used for controlling access to all shared memory-resident data structures. If the structure is busy, you wait on a semaphore until it is released. The premise of providing -spin is to allow 'retries' when not available, then nap to napmax before trying again.
3, 4 and 5 above may involve waiting for relatively long periods of time, perhaps minutes or hours.
In short, semaphores are still used when -spin is set, and the Progress-relevant kernel parameters on UNIX (SEMMSL, SEMMNS, SEMMNI, SEMMNU) should still be set accordingly. For further information refer to OS specific documentation, man pages or support services. Guidelines are provided in Article:
Calculating SEMMSL, SEMMNS and SEMMNU