Skip to main content
Skip table of contents

Threads

The Threadpool Swiftlet in the latest update introduces two types of asynchronous components: Event Loops and Ad Hoc Threads. These components can be configured as either virtual threads or platform threads, offering flexibility and efficiency in handling asynchronous tasks.

Event Loops

An Event Loop is allocated a dedicated, continuously operating thread that processes events. Events are submitted individually, but the loop can be set to a bulk mode, where it processes all available events at once. This design ensures there's no thread context switching, leading to efficient event handling. The constant use of the same thread for processing also enables the implementation of lock-free components, maintaining consistency with the Java Memory Model.

Ad Hoc Threads

Ad Hoc Threads are tailored for on-demand tasks from components, such as timers. These components have the option to choose between virtual and platform threads. When virtual threads are selected, a new thread is spawned for each task, ideal for scenarios where task concurrency is key. For platform threads, they are drawn from a fixed-size thread pool. This choice is particularly beneficial for tasks involving libraries where it's unclear if synchronized methods are used, preventing potential issues with thread locking in such cases.

Configuration

Event Loops in SwiftMQ are grouped and have two main attributes: bulk-mode and virtual.

The bulk-mode attribute determines whether events are processed individually or all at once (bulk), with the default set to false, promoting efficiency by allowing virtual threads to release their carrier threads more frequently.

The virtual attribute specifies the thread type, virtual or platform, with the default as virtual (true). Using platform threads (false) is advised only when necessary, as each Event Loop has a fixed thread, and extensive use of platform threads in numerous Event Loops can strain the system.

The Threadpool Swiftlet also includes a new attribute, group-shutdown-order. This attribute takes a space-delimited list of group names and determines the sequence in which groups are shut down when the Threadpool Swiftlet itself shuts down. Additionally, this shutdown order is applied in High Availability (HA) configurations for the process of freezing and unfreezing groups during the synchronization of HA instances.

The configuration of the Threadpool Swiftlet is designed to automatically update from older versions. It's important that this configuration is not manually changed, ensuring the seamless transition and compatibility of the system with the latest enhancements. This automatic update process ensures that your existing settings are preserved and integrated with the new system functionalities without requiring additional intervention.

Example (CE):

XML
<swiftlet name="sys$threadpool"
            group-shutdown-order="default network routing swiftlet processing storeprocessor store">
    <groups>
      <group name="network">
        <eventloops>
          <eventloop name="sys$amqp.connection.service"/>
          <eventloop name="sys$jms.connection.inbound"/>
          <eventloop name="sys$jms.connection.outbound" bulk-mode="true"/>
          <eventloop name="sys$mqtt.connection.inbound"/>
          <eventloop name="sys$mqtt.connection.outbound"/>
        </eventloops>
      </group>
      <group name="swiftlet">
        <eventloops>
          <eventloop name="sys$mgmt.dispatch"/>
          <eventloop name="sys$topicmanager.announce"/>
          <eventloop name="sys$scheduler.scheduler"/>
        </eventloops>
      </group>
      <group name="processing">
        <eventloops>
          <eventloop name="sys$amqp.sasl.service"/>
          <eventloop name="sys$amqp.session.service"/>
          <eventloop name="sys$jms.session"/>
          <eventloop name="sys$streams.processor" virtual="false"/>
        </eventloops>
      </group>
      <group name="routing">
        <eventloops>
          <eventloop name="sys$routing.connection.mgr"/>
          <eventloop name="sys$routing.route.exchanger"/>
          <eventloop name="sys$routing.scheduler"/>
          <eventloop name="sys$routing.connection.service"/>
          <eventloop name="sys$routing.connection.throttle"/>
        </eventloops>
      </group>
      <group name="storeprocessor">
        <eventloops>
          <eventloop name="sys$store.backup"/>
          <eventloop name="sys$store.shrink"/>
          <eventloop name="sys$store.scan"/>
        </eventloops>
      </group>
      <group name="store">
        <eventloops>
          <eventloop name="sys$store.log" bulk-mode="true"/>
        </eventloops>
      </group>
    </groups>
  </swiftlet>

When upgrading to the latest configuration, entries for UR and HA versions are automatically added.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.