You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "Beihao-Zhou (via GitHub)" <gi...@apache.org> on 2024/08/16 03:32:44 UTC

[PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Beihao-Zhou opened a new pull request, #2491:
URL: https://github.com/apache/kvrocks/pull/2491

   Closes #2489
   
   ### Summary
   This PR fixes the concurrency issue mentioned in #2481, however, this is now pretty slow for uploading operation and bounded by the computational resources from my local laptop. I'll set up the same instance capacity as mentioned in the [post](https://qdrant.tech/benchmarks/) and benchmark. 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #2491:
URL: https://github.com/apache/kvrocks/pull/2491#discussion_r1722593752


##########
src/search/index_info.h:
##########
@@ -52,21 +53,28 @@ struct FieldInfo {
 
 struct IndexInfo {
   using FieldMap = std::map<std::string, FieldInfo>;
+  using MutexMap = std::map<std::string, std::mutex>;

Review Comment:
   I think we can try `map<.., unique_ptr<mutex>>` to avoid such problem.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #2491:
URL: https://github.com/apache/kvrocks/pull/2491#discussion_r1722593752


##########
src/search/index_info.h:
##########
@@ -52,21 +53,28 @@ struct FieldInfo {
 
 struct IndexInfo {
   using FieldMap = std::map<std::string, FieldInfo>;
+  using MutexMap = std::map<std::string, std::mutex>;

Review Comment:
   I think we can try `map<.., unique_ptr<mutex>>` to avoid such problem.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on PR #2491:
URL: https://github.com/apache/kvrocks/pull/2491#issuecomment-2295507651

   @Beihao-Zhou Do you know if theres a place where you can configure your compute for kvrocks?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "Beihao-Zhou (via GitHub)" <gi...@apache.org>.
Beihao-Zhou commented on PR #2491:
URL: https://github.com/apache/kvrocks/pull/2491#issuecomment-2295521370

   > @Beihao-Zhou Do you know if theres a place where you can configure your compute for kvrocks?
   
   Thanks a lot for pointing this out! I thought I was bottlenecked by lock itself so didn't try different config options, will look into them! 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "Beihao-Zhou (via GitHub)" <gi...@apache.org>.
Beihao-Zhou commented on PR #2491:
URL: https://github.com/apache/kvrocks/pull/2491#issuecomment-2295498295

   Tried the benchmark framework today, which took more than one hour to upload, but didn't even finish. I thought there was something wrong and killed the process, but after double-checking the redis benchmark [here](https://qdrant.tech/benchmarks/), seems like it also took redis 1.5 hours. 
   Will try it again these two days, but one call-out is that kvrocks definitely doesn't fully utilize the compute resources. 
   
   <img width="1133" alt="Screen Shot 2024-08-18 at 5 51 38 PM" src="https://github.com/user-attachments/assets/fbd698da-bae5-4532-8f69-ed5fe1261ab7">
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "Beihao-Zhou (via GitHub)" <gi...@apache.org>.
Beihao-Zhou commented on code in PR #2491:
URL: https://github.com/apache/kvrocks/pull/2491#discussion_r1720874892


##########
src/search/index_info.h:
##########
@@ -52,21 +53,28 @@ struct FieldInfo {
 
 struct IndexInfo {
   using FieldMap = std::map<std::string, FieldInfo>;
+  using MutexMap = std::map<std::string, std::mutex>;

Review Comment:
   Sure, this makes more sense <3



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "Beihao-Zhou (via GitHub)" <gi...@apache.org>.
Beihao-Zhou commented on PR #2491:
URL: https://github.com/apache/kvrocks/pull/2491#issuecomment-2325433835

   Apology for the late update! Was busy with relocation for the past two weeks.  
   
   Quick Update:
   I tried to benchmark the default dataset upload operation, but it took around 4.5 hours and didn't even finish...
   I can't quite estimate how long it will take, but notice that only one thread will use 100% CPU during the majority time. I'm not quite sure if this is because we used mutex here. 
   I'll try to tune CPU usage in the config and run the benchmark again these two days; however, let me know if you have any better ideas! @PragmaTwice 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "Beihao-Zhou (via GitHub)" <gi...@apache.org>.
Beihao-Zhou commented on code in PR #2491:
URL: https://github.com/apache/kvrocks/pull/2491#discussion_r1720997437


##########
src/search/index_info.h:
##########
@@ -52,21 +53,28 @@ struct FieldInfo {
 
 struct IndexInfo {
   using FieldMap = std::map<std::string, FieldInfo>;
+  using MutexMap = std::map<std::string, std::mutex>;

Review Comment:
   While trying to move the exact same piece of code into `IndexUpdater`s, I encountered the following errors:
   ```
   ‘constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const std::__cxx11::basic_string<char>; _T2 = std::mutex]’ is implicitly deleted because the default definition would be ill-formed:
     314 |       constexpr pair(const pair&) = default;    ///< Copy constructor
   ```
   I suspect that this is caused by `IndexUpdater`s are usually created on stacks, which causes `std::map` doing some underlying copies and deletions, while `IndexInfo`s are allocated on heap so doesn't have the issue. 
   I tried to wrap `std::mutex` into a `unique_ptr` but the compiler will report the same error. 
   
   I'm not quite sure what I can do at this point, may leave it as it is, and try to benchmark first. But feel free to let me know if you think there is anything I missed, or any workaround you can think of. @PragmaTwice  <3



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice closed pull request #2491: feat(search): Support mutex to guarantee index update thread safety
URL: https://github.com/apache/kvrocks/pull/2491


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #2491:
URL: https://github.com/apache/kvrocks/pull/2491#issuecomment-2461185938

   I'll take this task and submit a patch for it : )


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "Beihao-Zhou (via GitHub)" <gi...@apache.org>.
Beihao-Zhou commented on PR #2491:
URL: https://github.com/apache/kvrocks/pull/2491#issuecomment-2462198288

   > I'll take this task and submit a patch for it : )
   
   Thanks a ton!! Was too distracted by work these days.... My apology 😭 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(search): Support mutex to guarantee index update thread safety [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #2491:
URL: https://github.com/apache/kvrocks/pull/2491#discussion_r1720621124


##########
src/search/index_info.h:
##########
@@ -52,21 +53,28 @@ struct FieldInfo {
 
 struct IndexInfo {
   using FieldMap = std::map<std::string, FieldInfo>;
+  using MutexMap = std::map<std::string, std::mutex>;

Review Comment:
   Maybe we can put mutexes into `IndexUpdater`s instead of `IndexInfo`s?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org