Manage and Synchronize Threads in Engine
- Last UpdatedJun 10, 2024
- 2 minute read
Overview
This section provides information on how to manage and synchronize threads in AVEVA Work Tasks Engine.
Thread
A Thread is a small set of executable instructions, which can be used to isolate a task from a process. Multiple threads are efficient way to obtain parallelism of hardware and give interactive user interaction to your applications. Threading enables your C# program to perform concurrent processing so you can do more than one operation at a time. For example, you can use threading to monitor input from the user, perform background tasks, and handle simultaneous streams of input.
ThreadPool Class
Provides a pool of threads that can be used to post work items, process asynchronous I/O, wait on behalf of other threads, and process timers. Thread pooling enables you to use threads more efficiently by providing your application with a pool of worker threads that are managed by the system. One thread monitors the status of several wait operations queued to the thread pool. When a wait operation completes, a worker thread from the thread pool executes the corresponding callback function.
The threads in the managed thread pool are background threads. This means that a ThreadPool thread will not keep an application running after all foreground threads have exited.
Engine and Threads
The engine is run as a Windows Service on AVEVA Work Tasks server installed machines. Once the service is started the engine listens on a particular port waiting for requests from clients to be processed. The communication between the engine and client (Example: w3wp process) is achieved using TCP/IP communication protocol. On a request from client the engine verifies the requests and places it on to a thread pool and then gives a notification back to client on successful delivery. From then on the engine processes the request in an asynchronous fashion. This is a bit different for synchronous execution which is detailed below.
The engine adopts two modes of execution for workflow steps or activities.
-
Asynchronous mode
-
Synchronous mode
For Asynchronous mode, the engine uses predefined set of threads (Custom thread pool) which will run/execute the workflow steps in parallell. Based on the number of threads available the number of workflow steps which can execute will vary. The number of threads for the custom thread pool is configurable and the performance on higher thread count will vary based on the operating system and hardware configuration.
For Synchronous mode, the TCP/IP connection between the client and engine is placed on hold and the client gets a reply only when a logical end point is reached within the engine. So the wait period for client to get a reply from engine on successful delivery will happen only after logical end is reached.
Note: On heavy load environment, it is always advisable to use asynchronous mode of execution.