like many ServiceNow pros, Semaphore comes to mind when there is a performance issue, however, Semaphore is much bigger than that. here I am trying to learn more about Semaphore.
What is Semaphore?
according to ServiceNow docs and JVM docs, Semaphore manages and protects ServiceNow resources and limits the number of activities for a specific resource. Semaphore does that by controlling transaction queues in a first-in-first-out fashion(FIFO).
Let’s take an example so we can understand this more.
Imagine that ServiceNow allows 2 threads and 10 semaphores. what is this actually means?
It means ServiceNow allows 2 transactions to run simultaneously on a specific resource – so what if we have 6 transactions at the same time?
If we are to have 6 transactions at the same time ServiceNow will run 2 transactions, then semaphore will put the rest in a queue in First in first out (FIFO)fashion. obviously, slow performance can be a result of transactions waiting in queue to be processed, however, this is necessary to protect your resources and ensure that the system is not overloaded with tasks.
but what if we have 15 transactions at the same time?
In this case, ServiceNow will run 2 transactions, then the semaphore will put 10 transactions in a queue, and 3 transactions will be rejected.
Semaphore is our gatekeeper, it controls and organizes our transaction queue.