Multi-threaded execution
- Last Updated: November 23, 2022
- 3 minute read
- Corticon
- Documentation
Multiple Decision Services place their requests in a queue for processing. Server-level thread pooling is implemented by default, using built-in Java concurrent pooling mechanisms to control the number of concurrent executions. This design allows the server to determine how many concurrent requests are to be processed at any one time.
Execution queue
Each thread coming into the Server gets an available Reactor from the Decision Service, and then the thread is added to the Server's Execution Thread Pooling Queue, or, simply put, the Execution Queue. The Execution Queue guarantees that threads do not overload the cores of the machine by allowing a specified number of threads in the Execution Queue to start executing, while holding back the other threads. Once an executing thread completes, the next thread in the Execution Queue starts executing.
The Server will discover the number of cores on a machine and, by default, limit the number of concurrent executions to that many cores, but a property can be set to specify the number of concurrent executions. Most use cases will not need to set this property. However, if you have multiple applications running on the same machine as Corticon Server, you might want to set this property lower to limit the system resources Corticon uses. While this tactic might slow down Corticon processing when there is a heavy load of incoming threads, it will help ensure Corticon does not monopolize the system. Conversely, if you have Decision Services which make calls to external services (such as connection to a Datasource) you may want to set this property higher so that a core is not idle while a thread is waiting for a response.
Memory management
Allocation means that you could allocate hundreds of execution threads for one Decision Service. The way Reactors are maintained in each Decision Service, the Server can re-use cached processing data (not including payload data) across all Reactors for the Decision Service. Runtime performance should reveal only modest differences in memory utilization between a Decision Service that contains just one Reactor and another that contains hundreds of Reactors. Because each Reactor reuses cached processing data, the Server can dynamically create a new Reactor per execution thread (rather than creating Reactors and holding them in memory.) Even when an allocation is set to 100, the Server only creates a new Reactor (with cached data) for every incoming execution thread, up to 100. If there are only 25 execution threads against Decision Service 1, then there are just 25 Reactors in memory. Large request payloads are more of a concern than the number of concurrent executions or the number of Reactors.
Related Server properties
The following Server properties let you adjust Server executions:
- Determines how many concurrent executions can occur across the
Server. Ideally, this value is set to the number of Cores on the machine. By default,
this value is set to
0, which means the Server will auto-detect the number of Cores on the server.com.corticon.server.execution.processors.available=0 - This is the timeout setting for how long an execution thread can be
inside the Execution Queue. The time starts when the execution thread enters the
Execution Queue and ends when it completes executing against a Decision Service. A
CcServerTimeoutExceptionwill be thrown if the execution thread fails to complete in the allotted time. The value is in milliseconds. Default value is180000(180000ms = 3 minutes)com.corticon.server.execution.queue.timeout=180000
com.corticon.server.execution.queue.timeout sets how long
Corticon will allow the execution thread to execute before killing it, thus preventing a
reactor from being permanently locked by the execution. Examples where this is
appropriate are: (1) when your rules access a data source that blocks but does not
return in a reasonable amount of time, or (2) when calling into a custom extension that
goes into an infinite loop or blocked state.