Skip to content

Early session release: close TM1 sessions when instance has no remaining tasks #135

@nicolasbisurgi

Description

@nicolasbisurgi

Problem Description

When running workflows in --exclusive mode, RushTI holds connections to all TM1 instances for the entire duration of the workflow, even if an instance's tasks finish early.

Example: A workflow with 100 tasks connects to TM1_Instance_A for the first 5 tasks (~10 seconds) and TM1_Instance_B for the remaining 95 tasks (~30 minutes). The current implementation holds the exclusive session on TM1_Instance_A for 30 minutes and 10 seconds, blocking other RushTI instances from using TM1_Instance_A — even though its work completed in 10 seconds.

This applies to both exclusive and non-exclusive modes: idle sessions consume server resources unnecessarily.

Proposed Solution

Implement early session release in the DAG execution loop (work_through_tasks_dag). After each task completes, check whether there are any remaining tasks (pending or running) for the same TM1 instance. If none remain, immediately logout from that instance.

Implementation approach:

  1. Build a per-instance task counter at workflow start from all tasks in the DAG
  2. Decrement the counter when a task completes
  3. When an instance's counter reaches 0, call logout() on that instance's TM1Service, log the early release, and remove it from the active services dict
  4. Respect tm1_preserve_connections and force logic (exclusive mode force-closes preserved connections)
  5. Skip early release for instances that still have pending/running tasks

Benefits:

  • Reduces exclusive mode blocking time significantly for multi-instance workflows
  • Frees TM1 server resources (session slots, memory) as early as possible
  • No behavior change for single-instance workflows

Alternatives Considered

  • No change (status quo): Sessions remain open until workflow ends. Simple but wasteful.
  • Periodic session cleanup sweep: Check all instances periodically (e.g., every N tasks) instead of on every completion. Adds complexity without meaningful benefit since the per-completion check is O(1) with a counter.

Additional Context

The change is localized to execution.py (work_through_tasks_dag and logout) and the DAG class (adding a method to query remaining tasks per instance). The logout function already supports selective logout via tm1_preserve_connections and force parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions