BPG-Based Initial Partitioning for Hybrid Data Partitioning in NewSQL Databases
Tạm dịch: Thay thế thuật toán khởi tạo bằng BPG cho phương pháp phân mảnh dữ liệu hybrid trong hệ cơ sở dữ liệu NewSQL
Dự án hiện thực hóa thuật toán Bregman Proximal Gradient (BPG) cho bài toán phân bổ dữ liệu khởi tạo trong các phương án phân mảnh hybrid cho hệ cơ sở dữ liệu phân tán NewSQL
Mã nguồn này thay thế thuật toán phân mảnh khởi đầu tham lam (Algorithm 5 của Schreiner và cộng sự) bằng mô hình tối ưu Normalized Cut liên tục được giải bằng BPG (Niu và cộng sự) nhằm giảm thiểu chi phí nghẽn mạng do giao dịch phân tán và cân bằng tải công việc giữa các máy chủ
Cài đặt
pip install bpg-partitioning
Chạy nhanh kịch bản mô phỏng đối chiếu trên terminal:
bpg-partitioning
Ví dụ sử dụng nhanh
import bpg_partitioning as bp
# tạo dữ liệu giả lập và đồ thị nhiệt
creator = bp.CreatePartitionScheme(num_records=5, seed=42)
scheme = creator.run()
# phân mảnh khởi tạo bằng bpg
bpg_scheme = bp.bpg_partition(scheme, site_num=2, step_size=1.0, iterations_num=50, seed=42)
print(bpg_scheme.partitions)
# chạy điều phối phân mảnh thích ứng động (algorithm 2) kết hợp bpg
dyn_scheme = bp.Partitioning(
partition_scheme=creator.run(),
site_num=2,
workload_factor=0.2,
distributed_percentage=0.02,
use_bpg=True
).run()
print(dyn_scheme.partitions)
Tài liệu API và kiểu trả về
1. Cấu trúc dữ liệu và khởi tạo đồ thị nhiệt
PartitionScheme(heat_graph: nx.Graph, partitions: dict[int, set[int]])
Cấu trúc dữ liệu trung tâm lưu trữ trạng thái phân mảnh của hệ thống:
heat_graph(nx.Graph): Đồ thị nhiệt với mỗi đỉnh là một projection thuộc tính (tuple_id: int,table: str,attrs: list[str],weight: float) và mỗi cạnh mang trọng sốweight: float(0.0cho các mảnh cùng một tuple,> 0.0cho tần suất đồng truy cập trong giao dịch)partitions(dict[int, set[int]]): Từ điển ánh xạ từ mã máy chủ (site_id) sang tập hợp các mã đỉnh (set[int]) được đặt tại máy chủ đó
CreatePartitionScheme(num_records: int = 5, seed: int = 42)
Bộ sinh dữ liệu khách hàng, giao dịch giả lập và đồ thị nhiệt:
generate_mock_data() -> list[dict]: Trả về danh sách các bản ghi khách hàng gồmid,name,email,phone,city,balancegenerate_mock_transactions(num_transactions: int = 10) -> list[dict]: Trả về danh sách giao dịch dạng{'tx_id': int, 'ops': list[{'tuple_id': int, 'attrs': list[str]}]}build_heat_graph() -> nx.Graph: Xây dựng và trả về đối tượng đồ thị nhiệtnx.Graphtừ danh sách giao dịchrun() -> PartitionScheme: Thực thi toàn bộ quy trình sinh dữ liệu và trả vềPartitionSchemeban đầu với mọi đỉnh nằm chung tại phân vùng0({0: set(nodes)})
2. Nhóm thuật toán Bregman Proximal Gradient (BPG)
bpg_partition(partition_scheme: PartitionScheme, site_num: int = 2, step_size: float = 1.0, iterations_num: int = 50, seed: int = 42) -> PartitionScheme
Hàm gọi nhanh toàn bộ chu trình phân mảnh bằng BPG (gom cụm cạnh 0 -> giải tối ưu Normalized Cut -> ánh xạ về phân vùng):
- Return:
PartitionSchememới vớipartitionschứa các khóa phân vùng từ1đếnsite_num
PartitionScheme_BPG(partition_scheme: PartitionScheme, use_coarsening: bool = True)
Chuyển đổi đồ thị nhiệt sang ma trận ái lực thưa:
run() -> scipy.sparse.csr_array: Gom các đỉnh nối bởi cạnh trọng số0.0(khiuse_coarsening=True) và trả về ma trận kề đối xứng $W \in \mathbb{R}^{N \times N}$ dạngcsr_array- Thuộc tính sau khi chạy:
W(csr_array): Ma trận ái lực giữa các tuplecoarse_to_nodes(dict[int, list[int]]): Ánh xạ từ chỉ số cụm thu gọn sang danh sách cácnode_idgốc trên đồ thị nhiệtnode_to_idx,idx_to_node(dict[int, int]): Ánh xạ hai chiều giữa ID đỉnh thu gọn và chỉ số hàng/cột của ma trận
BregmanProximalGradient(W: csr_array, partitions_num: int, step_size: float, iterations_num: int, seed: int | None = None)
Bộ giải tối ưu liên tục Normalized Cut bằng cập nhật hàm mũ và phép chiếu Bregman:
run() -> np.ndarray: Trả về mảng 1 chiềulabels(np.ndarraykiểu số nguyên kích thước(N,), giá trị nhãn nằm trong đoạn[1, partitions_num])- Thuộc tính sau khi chạy:
X(np.ndarray): Ma trận phân bổ xác suất mềm kích thước(N, partitions_num)trước khi rời rạc hóa bằngargmax
BPG_PartitionScheme(heat_graph: nx.Graph, labels: np.ndarray, coarse_to_nodes: dict[int, list[int]] | None = None)
Chuyển đổi nhãn phân cụm từ bộ giải BPG về lại cấu trúc phân mảnh:
run() -> PartitionScheme: Bung các nhãn cụm về lại các đỉnh projection gốc trênheat_graphvà trả vềPartitionScheme
3. Nhóm thuật toán phân mảnh thích ứng (Autonomous NewSQL)
FirstPartitioning(partition_scheme: PartitionScheme, site_num: int) (Algorithm 5)
Thuật toán phân mảnh khởi tạo tham lam dùng làm cơ sở đối chiếu (baseline):
run() -> PartitionScheme: Gom cụm cạnh 0, chọnsite_numđỉnh có trọng số nhiệt lớn nhất làm hạt giống (seed) cho từng site rồi phân bổ phần còn lại theo độ liên kết và cân bằng tải; cập nhật tại chỗ và trả vềPartitionSchemevới khóa site từ0đếnsite_num - 1(quăngValueErrornếusite_num <= 0hoặc không nguyên)
Partitioning(partition_scheme: PartitionScheme, site_num: int, workload_factor: float, distributed_percentage: float = 0.02, use_bpg: bool = False) (Algorithm 2)
Bộ điều phối phân mảnh thích ứng động:
getLoads(partition_scheme: PartitionScheme) -> list[float]: Trả về danh sách tổng trọng số nhiệt của từng phân vùnggetCriticalEdgesLoad(partition_scheme: PartitionScheme) -> float: Trả về tổng trọng số của tất cả các cạnh bị cắt qua nhiều phân vùngrun(recursion_depth: int = 20) -> PartitionScheme: Tự động kiểm tra độ lệch tải (gọiPartitioningUnbalancedGraph), kiểm tra tỷ lệ giao dịch phân tán (gọiPartitioningMinimumCutGraph), và khởi tạo phân mảnh (bằngbpg_partitionnếuuse_bpg=True, ngược lại dùngFirstPartitioning) khi hệ thống mới chỉ có 1 phân vùng; trả vềPartitionSchemeđã tối ưu
PartitioningUnbalancedGraph(partition_scheme: PartitionScheme, site_num: int, workload_factor: float) (Algorithm 3)
Thuật toán tái cân bằng khi có máy chủ vượt ngưỡng tải $(1 \pm \alpha) \times \text{avg_load}$:
getLoads(partition_scheme: PartitionScheme) -> dict[int, float]: Trả về từ điển{partition_id: total_weight}mostProeminentTuple(partition_scheme: PartitionScheme, overloadedPartition: int) -> int | None: Trả vềnode_idcó trọng số nhiệt lớn nhất và tổng trọng số cạnh kề nhỏ nhất trong phân vùng quá tải (hoặcNonenếu phân vùng rỗng)relocateTuple(partition_scheme: PartitionScheme, proeminent_tuple: int, underloadPartition: int, overloadPartition: int) -> bool: Chuyển đỉnh sang phân vùng nhẹ tải nếu không làm phân vùng đích vượt ngưỡng tải tối đa, trả vềTruenếu chuyển thành công vàFalsenếu từ chốirun(recursion_depth: int = 20) -> PartitionScheme: Trả về bản saoPartitionSchemesau khi đã cân bằng tải
PartitioningMinimumCutGraph(partition_scheme: PartitionScheme, workload_factor: float, depth_search: int = 2) (Algorithm 4)
Thuật toán giảm chi phí giao dịch phân tán bằng di chuyển cụm đỉnh lân cận hoặc nhân bản dữ liệu:
criticalEdges(partition_scheme: PartitionScheme) -> list[tuple[int, int, float]]: Trả về danh sách(u, v, weight)của các cạnh cóweight > 0mà hai đầu mút không có phân vùng chunghottestEdge(criticalEdges: list[tuple[int, int, float]]) -> tuple[int, int, float]: Trả về cạnh(u, v, weight)có trọng số lớn nhấtcalculateMinimumCut(partition_scheme: PartitionScheme) -> float: Trả về tổng trọng số các cạnh cắtcheckBalance(partition_scheme: PartitionScheme) -> bool: Kiểm tra mọi phân vùng có thỏa mãn giới hạn tải Equation 1 hay khôngcheckMinPartition(original_scheme: PartitionScheme, new_scheme: PartitionScheme) -> bool: Kiểm tra phương án mới có tổng trọng số cắt nhỏ hơn hẳn phương án cũ hay không (Equation 2)updateMinCut(partition_scheme: PartitionScheme, vertex_groups, origin_partition: int, target_partition: int) -> tuple[float, list[int]]: Thử nghiệm các nhóm đỉnh ứng viên và trả về(minimal_cut, best_vertices)thỏa mãn cân bằng tải có vết cắt nhỏ nhấtexplorePossibility(partition_scheme: PartitionScheme, vertex: int, origin_partition: int, target_partition: int) -> tuple[float, list[int]]: Dò tìm phương án di chuyển từ 0-hop đếndepth_searchhops, trả về(minimal_cut, best_vertices)nếu giảm được vết cắt hiện tại, ngược lại trả về(-1, [])createReplication(partition_scheme: PartitionScheme, vertex: int, target_partition: int) -> PartitionScheme: Nhân bản đỉnhvertexsangtarget_partition(giữ nguyên đỉnh gốc)explorePossibilititesReplication(partition_scheme: PartitionScheme, vertex_one: int, vertex_two: int, partition_one: int, partition_two: int) -> PartitionScheme: Thử nhân bản một trong hai đầu mút của cạnh cắt nếu thỏa mãn đồng thời Equation 1 và Equation 2, trả vềPartitionSchememớirun() -> PartitionScheme: Duyệt các cạnh cắt theo trọng số giảm dần để di chuyển hoặc tạo bản sao tối ưu, trả về bản saoPartitionSchemeđã giảm vết cắt
Tài liệu tham khảo
[1] P. Niu, B. Ren, H. Wu, and X. Yao, "Modeling and optimization for massive data allocation in database," arXiv:2605.31002, Jun 2026
[2] G. A. Schreiner, R. de Santiago, D. Duarte, and R. dos Santos Mello, "An autonomous hybrid data partitioning approach for NewSQL databases," Journal of the Brazilian Computer Society, vol. 32, no. 1, Art. no. 1, 2026, doi: 10.5753/jbcs.2026.5684
Metadata
Release files for bpg-partitioning 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bpg_partitioning-0.1.1.tar.gz | 36.4 kB | Without provenance | Details for bpg_partitioning-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bpg_partitioning-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for bpg_partitioning-0.1.1-py3-none-any.whl |
Total release size: 56.7 kB
Release files / bpg_partitioning-0.1.1.tar.gz
| Download URL | bpg_partitioning-0.1.1.tar.gz |
|---|---|
| Size | 36.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ed51687a64055cd5e6dd71f806fc8bddd7f82aa210d5bf927420e9584e2de02
|
|
BLAKE2b-256 checksum How to use checksums |
87fcb0c5caf1222cf2d6ae85f9e4e2a6bbe194ca129070aa004b535e1e5db525
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.9
|
Release files / bpg_partitioning-0.1.1-py3-none-any.whl
| Download URL | bpg_partitioning-0.1.1-py3-none-any.whl |
|---|---|
| Size | 20.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e36474ffde1ba30808a44f4c969f420512589a2fe9c1dca703c427f345189f7
|
|
BLAKE2b-256 checksum How to use checksums |
1f3ce60ebde2a5ea8b4b8993d374d092b270fced4bb2428af5b166738d85872b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.9
|
Security for bpg-partitioning 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.