-
Notifications
You must be signed in to change notification settings - Fork 10
vector-store: Move Usearch operations to a dedicated tasks #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
vector-store: Move Usearch operations to a dedicated tasks #294
Conversation
7878e6a to
4d97b34
Compare
| .take(limit.0.get()) | ||
| .collect(); | ||
|
|
||
| sim.wait_search(start); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should measure time of preparing response also, so wait_search should be after preparing keys vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change reverted.
I was changing simulator because I tokio was handing for some reason - I though it was due to locks.
But in fact to was due to dropped tx channel for config in tests: https://github.com/scylladb/vector-store/pull/294/files#diff-cb2126eb464b326d11b2dcfbd02661e90d1a34a8735bd45a911c0e2bfee2607dL79. This caused that rx side was in the "busy loop".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not reverted. The commit is still there.
| let keys = sim.keys.read().unwrap(); | ||
| let len = keys.len() as u64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to lock sim.keys for all time of finding random keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Now keys are locked temporary only.
4d97b34 to
50ab25b
Compare
The simulator crashes if a search was performed on an empty index (i.e. before any keys were indexed).
50ab25b to
e056901
Compare
Usearch's API uses global locks. Operations like `add` and `remove` can hold these locks for extended periods. When these operations are executed on the Tokio runtime, they can block worker threads. This leads to thread starvation, effectively halting all asynchronous tasks, including handling HTTP requests, processing CDC data, and serving metrics. This commit moves the blocking `add` and `remove` calls to a dedicated Rayon thread pool. By isolating these operations, the Tokio runtime remains unblocked and responsive, ensuring the application's I/O continues to function correctly.
e056901 to
f56877a
Compare
ewienik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a need for limiting rayon background threads to the same number as tokio threads.
| } => { | ||
| add_or_replace(idx, keys, usearch_key, primary_key, embedding); | ||
| rayon::spawn(move || { | ||
| add_or_replace(idx, keys, usearch_key, primary_key, embedding); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently idx is based on RwLock, so there will be still blocking of thread. Better would be to replace the RwLock with a semaphore.
Usearch's API uses global locks. Operations like
addandremovecan hold these locks for extended periods.When these operations are executed on the Tokio runtime, they can block
worker threads. This leads to thread starvation, effectively halting all
asynchronous tasks, including handling HTTP requests, processing CDC
data, and serving metrics.
This commit moves the blocking
addandremovecalls to a dedicatedRayon thread pool. By isolating these operations, the Tokio runtime
remains unblocked and responsive, ensuring
the application's I/O continues to function correctly.
Fixes: VECTOR-339