peercache 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. peercache-0.1.1/.github/workflows/ci.yml +62 -0
  2. peercache-0.1.1/.github/workflows/docs.yml +48 -0
  3. peercache-0.1.1/.github/workflows/release.yml +71 -0
  4. peercache-0.1.1/.gitignore +16 -0
  5. peercache-0.1.1/CHANGELOG.md +44 -0
  6. peercache-0.1.1/CMakeLists.txt +53 -0
  7. peercache-0.1.1/LICENSE +190 -0
  8. peercache-0.1.1/PKG-INFO +123 -0
  9. peercache-0.1.1/README.md +110 -0
  10. peercache-0.1.1/cpp/bindings/pybind.cpp +75 -0
  11. peercache-0.1.1/cpp/include/peercache/connection_manager.h +51 -0
  12. peercache-0.1.1/cpp/include/peercache/rdma_context.h +54 -0
  13. peercache-0.1.1/cpp/include/peercache/rdma_endpoint.h +46 -0
  14. peercache-0.1.1/cpp/include/peercache/transfer_engine.h +39 -0
  15. peercache-0.1.1/cpp/include/peercache/types.h +34 -0
  16. peercache-0.1.1/cpp/src/connection_manager.cpp +207 -0
  17. peercache-0.1.1/cpp/src/rdma_context.cpp +113 -0
  18. peercache-0.1.1/cpp/src/rdma_endpoint.cpp +147 -0
  19. peercache-0.1.1/cpp/src/transfer_engine.cpp +72 -0
  20. peercache-0.1.1/docs/architecture.md +98 -0
  21. peercache-0.1.1/docs/architecture.zh.md +85 -0
  22. peercache-0.1.1/docs/changelog.md +38 -0
  23. peercache-0.1.1/docs/changelog.zh.md +34 -0
  24. peercache-0.1.1/docs/getting-started.md +97 -0
  25. peercache-0.1.1/docs/getting-started.zh.md +93 -0
  26. peercache-0.1.1/docs/index.md +54 -0
  27. peercache-0.1.1/docs/index.zh.md +50 -0
  28. peercache-0.1.1/docs/sdk.md +162 -0
  29. peercache-0.1.1/docs/sdk.zh.md +166 -0
  30. peercache-0.1.1/examples/sglang_launch.md +103 -0
  31. peercache-0.1.1/mkdocs.yml +78 -0
  32. peercache-0.1.1/pyproject.toml +35 -0
  33. peercache-0.1.1/python/peercache/__init__.py +14 -0
  34. peercache-0.1.1/python/peercache/config.py +108 -0
  35. peercache-0.1.1/python/peercache/directory.py +168 -0
  36. peercache-0.1.1/python/peercache/discovery.py +148 -0
  37. peercache-0.1.1/python/peercache/examples/__init__.py +0 -0
  38. peercache-0.1.1/python/peercache/examples/launch_meta.py +61 -0
  39. peercache-0.1.1/python/peercache/hashring.py +93 -0
  40. peercache-0.1.1/python/peercache/pool.py +121 -0
  41. peercache-0.1.1/python/peercache/rpc.py +190 -0
  42. peercache-0.1.1/python/peercache/server.py +146 -0
  43. peercache-0.1.1/python/peercache/store.py +380 -0
  44. peercache-0.1.1/python/peercache/transport.py +238 -0
  45. peercache-0.1.1/python/peercache/types.py +66 -0
  46. peercache-0.1.1/requirements-docs.txt +4 -0
  47. peercache-0.1.1/tests/test_auto_meta.py +108 -0
  48. peercache-0.1.1/tests/test_directory.py +76 -0
  49. peercache-0.1.1/tests/test_e2e_tcp.py +134 -0
  50. peercache-0.1.1/tests/test_hashring.py +54 -0
  51. peercache-0.1.1/tests/test_pool.py +65 -0
@@ -0,0 +1,62 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+ workflow_dispatch:
9
+
10
+ concurrency:
11
+ group: ci-${{ github.ref }}
12
+ cancel-in-progress: true
13
+
14
+ jobs:
15
+ test-rdma-build:
16
+ name: build (libibverbs) + tests
17
+ runs-on: ubuntu-latest
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ python-version: ["3.9", "3.10", "3.11", "3.12"]
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - name: Install RDMA dev headers and build tools
26
+ run: |
27
+ sudo apt-get update
28
+ sudo apt-get install -y libibverbs-dev librdmacm-dev cmake ninja-build
29
+
30
+ - uses: actions/setup-python@v5
31
+ with:
32
+ python-version: ${{ matrix.python-version }}
33
+
34
+ - name: Install (builds the C++ extension) + test deps
35
+ run: |
36
+ python -m pip install --upgrade pip
37
+ pip install ".[test]"
38
+
39
+ - name: Verify the extension built with RDMA support
40
+ run: |
41
+ python -c "from peercache import _peercache; assert _peercache.HAS_RDMA, 'expected RDMA build'; print('HAS_RDMA', _peercache.HAS_RDMA)"
42
+
43
+ - name: Run tests (TCP fallback; runners have no RDMA device)
44
+ run: pytest -q
45
+
46
+ test-no-rdma:
47
+ name: build (PEERCACHE_NO_RDMA) + tests
48
+ runs-on: ubuntu-latest
49
+ steps:
50
+ - uses: actions/checkout@v4
51
+ - uses: actions/setup-python@v5
52
+ with:
53
+ python-version: "3.11"
54
+ - name: Install without RDMA (stub extension + TCP fallback)
55
+ run: |
56
+ python -m pip install --upgrade pip
57
+ pip install ".[test]" --config-settings=cmake.define.PEERCACHE_NO_RDMA=ON
58
+ - name: Verify stub build falls back to TCP
59
+ run: |
60
+ python -c "from peercache import _peercache; assert _peercache.HAS_RDMA is False; print('stub build OK')"
61
+ - name: Run tests
62
+ run: pytest -q
@@ -0,0 +1,48 @@
1
+ name: Docs
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ paths:
7
+ - "docs/**"
8
+ - "mkdocs.yml"
9
+ - "requirements-docs.txt"
10
+ - ".github/workflows/docs.yml"
11
+ workflow_dispatch:
12
+
13
+ # Allow the workflow to publish to GitHub Pages.
14
+ permissions:
15
+ contents: read
16
+ pages: write
17
+ id-token: write
18
+
19
+ # Only one concurrent Pages deployment.
20
+ concurrency:
21
+ group: pages
22
+ cancel-in-progress: false
23
+
24
+ jobs:
25
+ build:
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ - uses: actions/setup-python@v5
30
+ with:
31
+ python-version: "3.12"
32
+ - name: Install docs dependencies
33
+ run: pip install -r requirements-docs.txt
34
+ - name: Build site
35
+ run: mkdocs build --strict --site-dir _site
36
+ - uses: actions/upload-pages-artifact@v3
37
+ with:
38
+ path: _site
39
+
40
+ deploy:
41
+ needs: build
42
+ runs-on: ubuntu-latest
43
+ environment:
44
+ name: github-pages
45
+ url: ${{ steps.deployment.outputs.page_url }}
46
+ steps:
47
+ - id: deployment
48
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,71 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: write # create the GitHub Release
11
+
12
+ jobs:
13
+ build-sdist:
14
+ name: Build source distribution
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.12"
21
+ - name: Build sdist
22
+ run: |
23
+ python -m pip install --upgrade pip build
24
+ python -m build --sdist
25
+ - name: Check metadata
26
+ run: |
27
+ python -m pip install twine
28
+ python -m twine check dist/*
29
+ - uses: actions/upload-artifact@v4
30
+ with:
31
+ name: sdist
32
+ path: dist/*.tar.gz
33
+
34
+ github-release:
35
+ name: Publish GitHub Release
36
+ needs: build-sdist
37
+ runs-on: ubuntu-latest
38
+ steps:
39
+ - uses: actions/download-artifact@v4
40
+ with:
41
+ name: sdist
42
+ path: dist
43
+ - name: Create release and attach the package
44
+ uses: softprops/action-gh-release@v2
45
+ with:
46
+ files: dist/*.tar.gz
47
+ generate_release_notes: true
48
+
49
+ pypi-publish:
50
+ name: Publish to PyPI (trusted publishing)
51
+ needs: build-sdist
52
+ runs-on: ubuntu-latest
53
+ # Requires a PyPI Trusted Publisher for this repo/workflow:
54
+ # PyPI project -> Publishing -> add GitHub publisher: flymysql/PeerCache,
55
+ # workflow release.yml, environment pypi. skip-existing avoids failures when
56
+ # re-running a tag whose version is already on PyPI.
57
+ environment:
58
+ name: pypi
59
+ url: https://pypi.org/project/peercache/
60
+ permissions:
61
+ id-token: write
62
+ steps:
63
+ - uses: actions/download-artifact@v4
64
+ with:
65
+ name: sdist
66
+ path: dist
67
+ - name: Publish
68
+ uses: pypa/gh-action-pypi-publish@release/v1
69
+ with:
70
+ packages-dir: dist
71
+ skip-existing: true
@@ -0,0 +1,16 @@
1
+ build/
2
+ dist/
3
+ *.egg-info/
4
+ __pycache__/
5
+ *.py[cod]
6
+ *.so
7
+ .pytest_cache/
8
+ .venv/
9
+ venv/
10
+ *.o
11
+ *.obj
12
+ CMakeCache.txt
13
+ CMakeFiles/
14
+ site/
15
+ .cache/
16
+ _skbuild/
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+
3
+ All notable changes to PeerCache are documented here. The format is based on
4
+ [Keep a Changelog](https://keepachangelog.com/) and this project adheres to
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [0.1.1] - 2026-05-31
8
+
9
+ ### Changed
10
+ - **Embedded meta**: removed the requirement for a separate meta process. The
11
+ node whose IP equals `discovery_addr` now auto-hosts the discovery service
12
+ in-process; co-located nodes that cannot bind the port fall back to client
13
+ mode automatically. Adds `PeerCacheConfig.meta_bind_host` and
14
+ `NodeRuntime.is_meta`.
15
+
16
+ ### Added
17
+ - Bilingual (English / 中文) documentation with a language switcher
18
+ (`mkdocs-static-i18n`).
19
+
20
+ ## [0.1.0] - 2026-05-31
21
+
22
+ Initial release.
23
+
24
+ ### Added
25
+ - **Decentralized architecture**: a single meta node for service discovery only,
26
+ plus a consistent-hash distributed directory (DHT) sharded across nodes -- no
27
+ centralized master or metadata service.
28
+ - **C++ RDMA data plane** (`cpp/`): raw `libibverbs` + TCP QP bootstrap, RC QPs,
29
+ one-sided `IBV_WR_RDMA_READ`, shared CQ polling, lazy per-peer connection
30
+ pooling, exposed to Python via `pybind11` (`_peercache`).
31
+ - **Two-MR model**: receive MR (`mem_pool_host.kv_buffer`) as READ destination +
32
+ backend-owned published pool (LRU, eviction deletes the directory entry).
33
+ - **`PeerCacheStore`**: a SGLang `HiCacheStorage` backend with the v1 zero-copy
34
+ paths (`batch_set_v1` / `batch_get_v1` / `batch_exists`), the v2 hybrid-pool
35
+ paths, and the single-key/batch APIs. Mooncake-compatible key suffixing
36
+ (MHA `_k`/`_v`, MLA single key).
37
+ - **Zero-touch SGLang integration** via the `dynamic` backend mechanism.
38
+ - **TCP fallback transport** for functional testing without RDMA hardware.
39
+ - Service discovery, consistent-hash ring, directory client/server, and a
40
+ lightweight TCP RPC.
41
+ - MkDocs SDK documentation site and GitHub Actions for CI, docs, and release.
42
+
43
+ [0.1.1]: https://github.com/flymysql/PeerCache/releases/tag/v0.1.1
44
+ [0.1.0]: https://github.com/flymysql/PeerCache/releases/tag/v0.1.0
@@ -0,0 +1,53 @@
1
+ cmake_minimum_required(VERSION 3.18)
2
+ project(peercache LANGUAGES CXX)
3
+
4
+ set(CMAKE_CXX_STANDARD 17)
5
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
6
+ # Use GNU extensions (-std=gnu++17) so POSIX/SVID symbols (sockets, etc.) are
7
+ # exposed; _GNU_SOURCE below makes this robust even under strict -std=c++17.
8
+ set(CMAKE_CXX_EXTENSIONS ON)
9
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
10
+
11
+ option(PEERCACHE_NO_RDMA "Build without libibverbs/librdmacm (stub transport)" OFF)
12
+
13
+ find_package(pybind11 CONFIG REQUIRED)
14
+
15
+ # Try to locate the RDMA core libraries unless explicitly disabled.
16
+ if(NOT PEERCACHE_NO_RDMA)
17
+ find_library(IBVERBS_LIB ibverbs)
18
+ find_library(RDMACM_LIB rdmacm)
19
+ find_path(IBVERBS_INCLUDE infiniband/verbs.h)
20
+ find_path(RDMACM_INCLUDE rdma/rdma_cma.h)
21
+ if(NOT IBVERBS_LIB OR NOT RDMACM_LIB OR NOT IBVERBS_INCLUDE OR NOT RDMACM_INCLUDE)
22
+ message(WARNING
23
+ "libibverbs/librdmacm not found; building PeerCache C++ module in STUB mode. "
24
+ "The pure-Python TCP fallback transport will be used at runtime.")
25
+ set(PEERCACHE_NO_RDMA ON)
26
+ endif()
27
+ endif()
28
+
29
+ set(PEERCACHE_SOURCES cpp/bindings/pybind.cpp)
30
+
31
+ if(NOT PEERCACHE_NO_RDMA)
32
+ list(APPEND PEERCACHE_SOURCES
33
+ cpp/src/rdma_context.cpp
34
+ cpp/src/rdma_endpoint.cpp
35
+ cpp/src/connection_manager.cpp
36
+ cpp/src/transfer_engine.cpp)
37
+ endif()
38
+
39
+ pybind11_add_module(_peercache ${PEERCACHE_SOURCES})
40
+ target_include_directories(_peercache PRIVATE cpp/include)
41
+
42
+ if(PEERCACHE_NO_RDMA)
43
+ target_compile_definitions(_peercache PRIVATE PEERCACHE_NO_RDMA=1)
44
+ else()
45
+ # _GNU_SOURCE exposes POSIX socket APIs and SVID helpers regardless of the
46
+ # active -std level (it must be defined before any system header is included,
47
+ # which a compile definition guarantees).
48
+ target_compile_definitions(_peercache PRIVATE _GNU_SOURCE)
49
+ target_include_directories(_peercache PRIVATE ${IBVERBS_INCLUDE} ${RDMACM_INCLUDE})
50
+ target_link_libraries(_peercache PRIVATE ${IBVERBS_LIB} ${RDMACM_LIB} pthread)
51
+ endif()
52
+
53
+ install(TARGETS _peercache LIBRARY DESTINATION peercache)
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works.
111
+
112
+ You may add Your own copyright statement to Your modifications and
113
+ may provide additional or different license terms and conditions
114
+ for use, reproduction, or distribution of Your modifications, or
115
+ for any such Derivative Works as a whole, provided Your use,
116
+ reproduction, and distribution of the Work otherwise complies with
117
+ the conditions stated in this License.
118
+
119
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
120
+ any Contribution intentionally submitted for inclusion in the Work
121
+ by You to the Licensor shall be under the terms and conditions of
122
+ this License, without any additional terms or conditions.
123
+ Notwithstanding the above, nothing herein shall supersede or modify
124
+ the terms of any separate license agreement you may have executed
125
+ with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade
128
+ names, trademarks, service marks, or product names of the Licensor,
129
+ except as required for reasonable and customary use in describing the
130
+ origin of the Work and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or
133
+ agreed to in writing, Licensor provides the Work (and each
134
+ Contributor provides its Contributions) on an "AS IS" BASIS,
135
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
136
+ implied, including, without limitation, any warranties or conditions
137
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
138
+ PARTICULAR PURPOSE. You are solely responsible for determining the
139
+ appropriateness of using or redistributing the Work and assume any
140
+ risks associated with Your exercise of permissions under this License.
141
+
142
+ 8. Limitation of Liability. In no event and under no legal theory,
143
+ whether in tort (including negligence), contract, or otherwise,
144
+ unless required by applicable law (such as deliberate and grossly
145
+ negligent acts) or agreed to in writing, shall any Contributor be
146
+ liable to You for damages, including any direct, indirect, special,
147
+ incidental, or consequential damages of any character arising as a
148
+ result of this License or out of the use or inability to use the
149
+ Work (including but not limited to damages for loss of goodwill,
150
+ work stoppage, computer failure or malfunction, or any and all
151
+ other commercial damages or losses), even if such Contributor
152
+ has been advised of the possibility of such damages.
153
+
154
+ 9. Accepting Warranty or Additional Liability. While redistributing
155
+ the Work or Derivative Works thereof, You may choose to offer,
156
+ and charge a fee for, acceptance of support, warranty, indemnity,
157
+ or other liability obligations and/or rights consistent with this
158
+ License. However, in accepting such obligations, You may act only
159
+ on Your own behalf and on Your sole responsibility, not on behalf
160
+ of any other Contributor, and only if You agree to indemnify,
161
+ defend, and hold each Contributor harmless for any liability
162
+ incurred by, or claims asserted against, such Contributor by reason
163
+ of your accepting any such warranty or additional liability.
164
+
165
+ END OF TERMS AND CONDITIONS
166
+
167
+ APPENDIX: How to apply the Apache License to your work.
168
+
169
+ To apply the Apache License to your work, attach the following
170
+ boilerplate notice, with the fields enclosed by brackets "[]"
171
+ replaced with your own identifying information. (Don't include
172
+ the brackets!) The text should be enclosed in the appropriate
173
+ comment syntax for the file format. We also recommend that a
174
+ file or class name and description of purpose be included on the
175
+ same "printed page" as the copyright notice for easier
176
+ identification within third-party archives.
177
+
178
+ Copyright 2026 PeerCache contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.2
2
+ Name: peercache
3
+ Version: 0.1.1
4
+ Summary: Peer-to-peer RDMA zero-copy L3 KV-cache backend for SGLang HiCache
5
+ Author: PeerCache contributors
6
+ License: Apache-2.0
7
+ Requires-Python: >=3.9
8
+ Provides-Extra: test
9
+ Requires-Dist: pytest>=7.0; extra == "test"
10
+ Provides-Extra: fast
11
+ Requires-Dist: msgpack>=1.0; extra == "fast"
12
+ Description-Content-Type: text/markdown
13
+
14
+ # PeerCache
15
+
16
+ [![CI](https://github.com/flymysql/PeerCache/actions/workflows/ci.yml/badge.svg)](https://github.com/flymysql/PeerCache/actions/workflows/ci.yml)
17
+ [![Docs](https://github.com/flymysql/PeerCache/actions/workflows/docs.yml/badge.svg)](https://flymysql.github.io/PeerCache/)
18
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
19
+
20
+ A lightweight, peer-to-peer **L3 storage backend for SGLang HiCache**.
21
+
22
+ Docs: <https://flymysql.github.io/PeerCache/>
23
+
24
+ PeerCache gives you Mooncake-style RDMA zero-copy KV-cache sharing across nodes,
25
+ but **without** the centralized `master` + `metadata` services. Instead it uses:
26
+
27
+ - **Embedded service discovery** — no separate meta process. One node (chosen by
28
+ `discovery_addr`) auto-hosts the discovery service in-process; nodes register
29
+ their endpoint, heartbeat, and pull the live membership list.
30
+ - **A consistent-hash distributed directory (DHT)** — the mapping
31
+ `key -> {data_node, remote_addr, rkey, length}` is sharded across all nodes by
32
+ hashing the key. There is no central metadata store.
33
+ - **Data stays local on write** — `set()` copies the page into a node-local
34
+ *published pool* (a host memcpy, no network, no master) and pushes only a tiny
35
+ location record to the directory.
36
+ - **One-sided RDMA READ on read** — `get()` looks up the directory, then issues a
37
+ zero-copy `IBV_WR_RDMA_READ` straight into SGLang's registered host buffer.
38
+
39
+ ```
40
+ write: set() ── local memcpy ──> published pool MR
41
+ └── PUT key->{node,addr,rkey,len} ──> directory shard (hash(key))
42
+ read: get() ── GET key ──> directory shard ──> {node,addr,rkey,len}
43
+ └── one-sided RDMA READ ──> local host buffer (zero copy)
44
+ ```
45
+
46
+ ## Why simpler than Mooncake?
47
+
48
+ | | Mooncake | PeerCache |
49
+ |---|---|---|
50
+ | metadata | central master + metadata service | sharded directory (consistent hash) |
51
+ | data placement | dedicated managed pool | stays on producing node |
52
+ | coordination | master allocates / tracks objects | only service discovery on meta node |
53
+ | transfer | RDMA zero-copy | RDMA zero-copy (one-sided READ) |
54
+
55
+ ## Architecture
56
+
57
+ - **C++ data plane** (`cpp/`): raw `libibverbs` + `librdmacm`. RC QPs, one-sided
58
+ READ/WRITE, CQ polling, lazy per-peer connection pooling. Exposed to Python via
59
+ `pybind11` as the `_peercache` module.
60
+ - **Python control plane** (`python/peercache/`): TCP RPC, service discovery,
61
+ consistent-hash ring, distributed directory, and the published-pool with LRU.
62
+ - **TCP fallback transport**: a pure-Python transport that mirrors the RDMA API so
63
+ the design can be validated end-to-end on machines without RDMA hardware.
64
+
65
+ ## Two-MR model (correctness)
66
+
67
+ SGLang's host KV buffer is the L2 tier and is evicted/overwritten by HiCache, so we
68
+ cannot register *its* address into the directory directly (dangling reference). Each
69
+ node therefore registers **two memory regions**:
70
+
71
+ 1. **Receive MR** = `mem_pool_host.kv_buffer` — destination of one-sided READ on `get`.
72
+ 2. **Published pool MR** = a backend-owned host pool with LRU — source of READ on
73
+ remote nodes. `set` memcpys the page into this pool (node-local, no network) and
74
+ publishes its `addr+rkey+len` to the directory. Eviction from the pool deletes the
75
+ corresponding directory entry, so a published address stays valid until evicted.
76
+
77
+ ## Install
78
+
79
+ ```bash
80
+ # Linux with RDMA (Mellanox OFED / rdma-core dev headers installed)
81
+ pip install .
82
+
83
+ # Without RDMA (control-plane + TCP fallback only, e.g. for tests on a laptop)
84
+ pip install -e . --config-settings=cmake.define.PEERCACHE_NO_RDMA=ON
85
+ ```
86
+
87
+ ## Run with SGLang
88
+
89
+ The meta service is **embedded** — there is no separate meta process. Point
90
+ `discovery_addr` at one node's IP on every node; the node whose IP matches
91
+ auto-starts the discovery service in-process.
92
+
93
+ ```bash
94
+ # On every SGLang node, set discovery_addr to the SAME node's IP (say node-0).
95
+ # node-0 detects the IP is itself and hosts the embedded meta automatically.
96
+ python -m sglang.launch_server --enable-hierarchical-cache \
97
+ --hicache-storage-backend dynamic \
98
+ --hicache-storage-backend-extra-config \
99
+ '{"backend_name":"peercache","module_path":"peercache.store","class_name":"PeerCacheStore","discovery_addr":"NODE0_IP:9100","protocol":"rdma","device_name":"mlx5_0","global_segment_size":"4gb"}'
100
+ ```
101
+
102
+ (Optionally, you can still run a standalone meta with `peercache-meta --bind
103
+ 0.0.0.0:9100` if you prefer a dedicated discovery host.)
104
+
105
+ See [examples/sglang_launch.md](examples/sglang_launch.md) for details.
106
+
107
+ ## Test
108
+
109
+ ```bash
110
+ pip install pytest
111
+ PYTHONPATH=python pytest tests/ -v
112
+ ```
113
+
114
+ ## Maintainer setup (one-time)
115
+
116
+ - **GitHub Pages**: Settings → Pages → Build and deployment → Source = **GitHub
117
+ Actions**. The `Docs` workflow then publishes to
118
+ <https://flymysql.github.io/PeerCache/> on every push to `main`.
119
+ - **PyPI Trusted Publishing**: on the PyPI `peercache` project, add a GitHub
120
+ publisher (owner `flymysql`, repo `PeerCache`, workflow `release.yml`,
121
+ environment `pypi`). Tagging `vX.Y.Z` then builds the sdist, attaches it to a
122
+ GitHub Release, and publishes to PyPI. Until configured, the PyPI step is
123
+ non-blocking and the GitHub Release still ships the package.