{"id":18847407,"url":"https://github.com/lemonhx/optimistic_lock_coupling_rs","last_synced_at":"2025-06-16T06:04:34.928Z","repository":{"id":47453030,"uuid":"357179807","full_name":"LemonHX/optimistic_lock_coupling_rs","owner":"LemonHX","description":"🍋: A General Lock following paper \"Optimistic Lock Coupling: A Scalable and Efficient General-Purpose Synchronization Method\"","archived":false,"fork":false,"pushed_at":"2021-08-31T06:17:17.000Z","size":1377,"stargazers_count":27,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T08:09:48.849Z","etag":null,"topics":["concurrency","lock","lock-free","readwritelock","rust-lang"],"latest_commit_sha":null,"homepage":"https://docs.rs/optimistic_lock_coupling/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LemonHX.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.MD","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-12T12:10:56.000Z","updated_at":"2025-02-27T03:40:52.000Z","dependencies_parsed_at":"2022-08-23T17:50:20.352Z","dependency_job_id":null,"html_url":"https://github.com/LemonHX/optimistic_lock_coupling_rs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/LemonHX/optimistic_lock_coupling_rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LemonHX%2Foptimistic_lock_coupling_rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LemonHX%2Foptimistic_lock_coupling_rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LemonHX%2Foptimistic_lock_coupling_rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LemonHX%2Foptimistic_lock_coupling_rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LemonHX","download_url":"https://codeload.github.com/LemonHX/optimistic_lock_coupling_rs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LemonHX%2Foptimistic_lock_coupling_rs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260109462,"owners_count":22960026,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrency","lock","lock-free","readwritelock","rust-lang"],"created_at":"2024-11-08T03:08:03.083Z","updated_at":"2025-06-16T06:04:34.904Z","avatar_url":"https://github.com/LemonHX.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Optimistic Lock Coupling\n\n![CI](https://github.com/LemonHX/optimistic_lock_coupling_rs/actions/workflows/rust.yml/badge.svg) ![docs.rs](https://docs.rs/optimistic_lock_coupling/badge.svg)\n\n\u003e from paper \"Optimistic Lock Coupling: A Scalable and Efficient General-Purpose Synchronization Method\"\n\nIn actual projects, there are some lock-free data structures, especially database-related ones such as `BwTree`, `Split-Ordered List` (also known as Lock Free HashTable) when there are many write conflicts.\nThe performance loss is very serious, and sometimes it is not as good as the brainless Mutex. However, the performance of the brainless Mutex is often very bad under normal circumstances, so is there an intermediate form that can solve this problem?\n\nThis is the intermediate form. So this can be used everywhere as a general lock, and the performance is satisfactory.\n\n## But I have a lock-free data structure that is well designed and optimized for usage scenarios. Can’t it be your implementation?\n\nOf course, this is better, but when you don't have 114514 PHD students to optimize your data structure, and you don't have 1919810 powerful debugging masters to deal with problems such as Memory Order, it will be tricky. \n\n\u003cdel\u003eAt this time, my project is already online, the investor has given me money. \u003c/del\u003e\n\n## So what are the disadvantages of such a data structure?\n\nOf course there is~\n\nThe disadvantage of this data structure is mainly because of the use of a 61bit version, when this version is full, we can lie flat.\nOf course, your data structure is crazy to change to this binary, it should be a problem for you to write the code. \n\n## Bench Mark\nsource code is under `\\benches` dir.\nyou can run it on your own~\n\n## Bench Result on my MacOS 2.3 GHz Intel Core i5 Images\n- heavy read\n![hr](/images/hr_cmp.jpg)\n- heavy write\n![hw](/images/hw_cmp.jpg)\n- read only\n![ro](/images/ro_cmp.jpg)\n- write only\n![wo](/images/wo_cmp.jpg)\n\n## Drawback\nThe shortcomings of optimistic lock are obvious. When there is a serious conflict, it will be slammed by Mutex and others.\nBut when **read \u003e write**, optimistic locking works better.\n\n## Lock Usage\nwhen 3 reader core and 2 writer core\n\nremoved intermediate part of blocking log\n\n| Operation | Delta Time | ThreadID    | Status                                                     |\n| --------- | ---------- | ----------- | ---------------------------------------------------------- |\n| Read      | 142869     | ThreadId(6) | OptimisticLockCouplingReadGuard { version: 0, data: 1 }    |\n| ErrRead   | 216320     | ThreadId(6) | failed to sync                                             |\n| ErrRead   | 222578     | ThreadId(6) | Blocked                                                    |\n| ErrRead   | 241218     | ThreadId(6) | Blocked                                                    |\n| Write     | 145456     | ThreadId(2) | OptimisticLockCouplingWriteGuard { version: 0, data: 1 }   |\n| Write     | 291942     | ThreadId(2) | OptimisticLockCouplingWriteGuard { version: 1, data: 2 }   |\n| Write     | 312349     | ThreadId(2) | OptimisticLockCouplingWriteGuard { version: 2, data: 3 }   |\n| ErrWrite  | 147945     | ThreadId(3) | Blocked                                                    |\n| ErrWrite  | 530522     | ThreadId(3) | Blocked                                                    |\n| Write     | 319592     | ThreadId(2) | OptimisticLockCouplingWriteGuard { version: 3, data: 4 }   |\n| Write     | 548172     | ThreadId(2) | OptimisticLockCouplingWriteGuard { version: 4, data: 5 }   |\n| Write     | 605291     | ThreadId(2) | OptimisticLockCouplingWriteGuard { version: 5, data: 6 }   |\n| Write     | 613679     | ThreadId(2) | OptimisticLockCouplingWriteGuard { version: 6, data: 7 }   |\n| Write     | 618416     | ThreadId(2) | OptimisticLockCouplingWriteGuard { version: 7, data: 8 }   |\n| Write     | 623453     | ThreadId(2) | OptimisticLockCouplingWriteGuard { version: 8, data: 9 }   |\n| Write     | 627723     | ThreadId(2) | OptimisticLockCouplingWriteGuard { version: 9, data: 10 }  |\n| ErrWrite  | 536923     | ThreadId(3) | Blocked                                                    |\n| Write     | 696435     | ThreadId(3) | OptimisticLockCouplingWriteGuard { version: 10, data: 11 } |\n| Write     | 704458     | ThreadId(3) | OptimisticLockCouplingWriteGuard { version: 11, data: 12 } |\n| Write     | 712664     | ThreadId(3) | OptimisticLockCouplingWriteGuard { version: 12, data: 13 } |\n| Write     | 718093     | ThreadId(3) | OptimisticLockCouplingWriteGuard { version: 13, data: 14 } |\n| Write     | 749839     | ThreadId(3) | OptimisticLockCouplingWriteGuard { version: 14, data: 15 } |\n| Write     | 755558     | ThreadId(3) | OptimisticLockCouplingWriteGuard { version: 15, data: 16 } |\n| ErrRead   | 149826     | ThreadId(5) | Blocked                                                    |\n| ErrRead   | 805119     | ThreadId(5) | Blocked                                                    |\n| ErrRead   | 810206     | ThreadId(5) | Blocked                                                    |\n| Write     | 775039     | ThreadId(3) | OptimisticLockCouplingWriteGuard { version: 16, data: 17 } |\n| Write     | 871475     | ThreadId(3) | OptimisticLockCouplingWriteGuard { version: 17, data: 18 } |\n| Write     | 891289     | ThreadId(3) | OptimisticLockCouplingWriteGuard { version: 18, data: 19 } |\n| Write     | 896488     | ThreadId(3) | OptimisticLockCouplingWriteGuard { version: 19, data: 20 } |\n| ErrRead   | 273387     | ThreadId(6) | Blocked                                                    |\n| Read      | 925559     | ThreadId(6) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 971184     | ThreadId(6) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 994963     | ThreadId(6) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 998833     | ThreadId(6) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1002179    | ThreadId(6) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1005515    | ThreadId(6) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1008870    | ThreadId(6) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| ErrRead   | 831229     | ThreadId(5) | Blocked                                                    |\n| Read      | 1055143    | ThreadId(5) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1076076    | ThreadId(5) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1080036    | ThreadId(5) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1083564    | ThreadId(5) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1086850    | ThreadId(5) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1090126    | ThreadId(5) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1093422    | ThreadId(5) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1110135    | ThreadId(5) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1115111    | ThreadId(5) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1118556    | ThreadId(5) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1038825    | ThreadId(6) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1142881    | ThreadId(6) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1146449    | ThreadId(6) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| ErrRead   | 148865     | ThreadId(4) | Blocked                                                    |\n| Read      | 1197872    | ThreadId(4) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1217034    | ThreadId(4) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1220737    | ThreadId(4) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1224141    | ThreadId(4) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1227430    | ThreadId(4) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1230666    | ThreadId(4) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1233888    | ThreadId(4) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1237159    | ThreadId(4) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1240422    | ThreadId(4) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |\n| Read      | 1243714    | ThreadId(4) | OptimisticLockCouplingReadGuard { version: 20, data: 20 }  |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemonhx%2Foptimistic_lock_coupling_rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemonhx%2Foptimistic_lock_coupling_rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemonhx%2Foptimistic_lock_coupling_rs/lists"}