Skip to content

optimize:Faster init and Atomic mechanism adapts to high-concurrency …#156

Merged
hami-robot[bot] merged 1 commit intoProject-HAMi:mainfrom
maverick123123:optimize/init_and_shrlock
Feb 25, 2026
Merged

optimize:Faster init and Atomic mechanism adapts to high-concurrency …#156
hami-robot[bot] merged 1 commit intoProject-HAMi:mainfrom
maverick123123:optimize/init_and_shrlock

Conversation

@maverick123123
Copy link
Copy Markdown
Contributor

📌 Summary

This PR introduces two major performance optimizations:

1. Faster Initialization

  • Issue: The previous initialization logic had excessive retries (20 times) and long sleep intervals (1-5 seconds), causing ~16s startup time for 8 concurrent processes.
  • Fix: Reduced retry_count from 20 → 10, and replaced sleep(1-5s) with usleep(0.1-0.5s).
  • Result: Initialization time dropped from 16s → 5s (3× improvement).

2. Lock-Free Runtime with Atomic Operations

  • Issue: Shared counters (memory usage, SM utilization, etc.) were protected by heavy pthread_mutex locks, causing severe contention under high-concurrency read/write workloads.
  • Fix: Replaced all mutex-protected counters with C11 _Atomic types and used:
    • atomic_fetch_add/sub for lock-free add/release
    • atomic_load for lock-free query
    • Proper memory order semantics:
      • acquire/release for process count and initialization
      • relaxed for per-process counters
  • Result:
    • Zero contention for all runtime memory tracking operations
    • Runtime overhead reduced from 33% → <1% (48× improvement)
    • Scales linearly to unlimited concurrent processes

The only remaining semaphore is used for process slot add/remove (extremely rare), everything else is completely lock-free.

@hami-robot
Copy link
Copy Markdown
Contributor

hami-robot Bot commented Feb 12, 2026

Welcome @maverick123123! It looks like this is your first PR to Project-HAMi/HAMi-core 🎉

@hami-robot hami-robot Bot added the size/L label Feb 12, 2026
@archlitchi
Copy link
Copy Markdown
Member

please sign-off your commit

@archlitchi
Copy link
Copy Markdown
Member

/ok-to-test

@maverick123123 maverick123123 force-pushed the optimize/init_and_shrlock branch 5 times, most recently from a22fbdd to b1ebb9d Compare February 25, 2026 03:20
…scenarios

Signed-off-by: maverick123123 <yuming.wu@dynamia.ai>

Co-authored-by: nishitnshah <nish511@gmail.com>
@maverick123123 maverick123123 force-pushed the optimize/init_and_shrlock branch from b1ebb9d to 24a0f49 Compare February 25, 2026 03:28
Copy link
Copy Markdown
Member

@archlitchi archlitchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@hami-robot
Copy link
Copy Markdown
Contributor

hami-robot Bot commented Feb 25, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: archlitchi, maverick123123

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hami-robot hami-robot Bot added the approved label Feb 25, 2026
@hami-robot hami-robot Bot merged commit 3d9ffc1 into Project-HAMi:main Feb 25, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants