Skip to content

Comments

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

Open
maverick123123 wants to merge 1 commit intoProject-HAMi:mainfrom
maverick123123:optimize/init_and_shrlock
Open

optimize:Faster init and Atomic mechanism adapts to high-concurrency …#156
maverick123123 wants to merge 1 commit intoProject-HAMi:mainfrom
maverick123123:optimize/init_and_shrlock

Conversation

@maverick123123
Copy link

📌 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
Contributor

hami-robot bot commented Feb 12, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: maverick123123
Once this PR has been reviewed and has the lgtm label, please assign archlitchi for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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
Copy link
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
Member

please sign-off your commit

…scenarios

Signed-off-by: maverick123123 <yuming.wu@dynamia.ai>
@maverick123123 maverick123123 force-pushed the optimize/init_and_shrlock branch from 3cc61fe to 0e65fc0 Compare February 13, 2026 08:05
@archlitchi
Copy link
Member

/ok-to-test

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