distributed-compute-locally 0.1.2__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.
- distributed_compute_locally-0.1.2/.gitignore +134 -0
- distributed_compute_locally-0.1.2/LICENSE +21 -0
- distributed_compute_locally-0.1.2/MANIFEST.in +11 -0
- distributed_compute_locally-0.1.2/PKG-INFO +295 -0
- distributed_compute_locally-0.1.2/README.md +255 -0
- distributed_compute_locally-0.1.2/distributed_compute/__init__.py +22 -0
- distributed_compute_locally-0.1.2/distributed_compute/cli.py +446 -0
- distributed_compute_locally-0.1.2/distributed_compute/coordinator.py +469 -0
- distributed_compute_locally-0.1.2/distributed_compute/exceptions.py +23 -0
- distributed_compute_locally-0.1.2/distributed_compute/protocol.py +95 -0
- distributed_compute_locally-0.1.2/distributed_compute/task.py +86 -0
- distributed_compute_locally-0.1.2/distributed_compute/worker.py +247 -0
- distributed_compute_locally-0.1.2/distributed_compute_locally.egg-info/PKG-INFO +295 -0
- distributed_compute_locally-0.1.2/distributed_compute_locally.egg-info/SOURCES.txt +28 -0
- distributed_compute_locally-0.1.2/distributed_compute_locally.egg-info/dependency_links.txt +1 -0
- distributed_compute_locally-0.1.2/distributed_compute_locally.egg-info/entry_points.txt +2 -0
- distributed_compute_locally-0.1.2/distributed_compute_locally.egg-info/requires.txt +8 -0
- distributed_compute_locally-0.1.2/distributed_compute_locally.egg-info/top_level.txt +1 -0
- distributed_compute_locally-0.1.2/examples/basic_usage.py +73 -0
- distributed_compute_locally-0.1.2/examples/data_processing.py +123 -0
- distributed_compute_locally-0.1.2/examples/ml_inference.py +102 -0
- distributed_compute_locally-0.1.2/integration_test.py +63 -0
- distributed_compute_locally-0.1.2/pyproject.toml +72 -0
- distributed_compute_locally-0.1.2/requirements.txt +2 -0
- distributed_compute_locally-0.1.2/run_computation.py +94 -0
- distributed_compute_locally-0.1.2/setup.cfg +4 -0
- distributed_compute_locally-0.1.2/setup.py +48 -0
- distributed_compute_locally-0.1.2/start_worker.py +31 -0
- distributed_compute_locally-0.1.2/tests/__init__.py +1 -0
- distributed_compute_locally-0.1.2/tests/test_distributed_compute.py +206 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Unit test / coverage reports
|
|
39
|
+
htmlcov/
|
|
40
|
+
.tox/
|
|
41
|
+
.nox/
|
|
42
|
+
.coverage
|
|
43
|
+
.coverage.*
|
|
44
|
+
.cache
|
|
45
|
+
nosetests.xml
|
|
46
|
+
coverage.xml
|
|
47
|
+
*.cover
|
|
48
|
+
*.py,cover
|
|
49
|
+
.hypothesis/
|
|
50
|
+
.pytest_cache/
|
|
51
|
+
|
|
52
|
+
# Translations
|
|
53
|
+
*.mo
|
|
54
|
+
*.pot
|
|
55
|
+
|
|
56
|
+
# Django stuff:
|
|
57
|
+
*.log
|
|
58
|
+
local_settings.py
|
|
59
|
+
db.sqlite3
|
|
60
|
+
db.sqlite3-journal
|
|
61
|
+
|
|
62
|
+
# Flask stuff:
|
|
63
|
+
instance/
|
|
64
|
+
.webassets-cache
|
|
65
|
+
|
|
66
|
+
# Scrapy stuff:
|
|
67
|
+
.scrapy
|
|
68
|
+
|
|
69
|
+
# Sphinx documentation
|
|
70
|
+
docs/_build/
|
|
71
|
+
|
|
72
|
+
# PyBuilder
|
|
73
|
+
target/
|
|
74
|
+
|
|
75
|
+
# Jupyter Notebook
|
|
76
|
+
.ipynb_checkpoints
|
|
77
|
+
|
|
78
|
+
# IPython
|
|
79
|
+
profile_default/
|
|
80
|
+
ipython_config.py
|
|
81
|
+
|
|
82
|
+
# pyenv
|
|
83
|
+
.python-version
|
|
84
|
+
|
|
85
|
+
# pipenv
|
|
86
|
+
Pipfile.lock
|
|
87
|
+
|
|
88
|
+
# PEP 582
|
|
89
|
+
__pypackages__/
|
|
90
|
+
|
|
91
|
+
# Celery stuff
|
|
92
|
+
celerybeat-schedule
|
|
93
|
+
celerybeat.pid
|
|
94
|
+
|
|
95
|
+
# SageMath parsed files
|
|
96
|
+
*.sage.py
|
|
97
|
+
|
|
98
|
+
# Environments
|
|
99
|
+
.env
|
|
100
|
+
.venv
|
|
101
|
+
env/
|
|
102
|
+
venv/
|
|
103
|
+
ENV/
|
|
104
|
+
env.bak/
|
|
105
|
+
venv.bak/
|
|
106
|
+
|
|
107
|
+
# Spyder project settings
|
|
108
|
+
.spyderproject
|
|
109
|
+
.spyproject
|
|
110
|
+
|
|
111
|
+
# Rope project settings
|
|
112
|
+
.ropeproject
|
|
113
|
+
|
|
114
|
+
# mkdocs documentation
|
|
115
|
+
/site
|
|
116
|
+
|
|
117
|
+
# mypy
|
|
118
|
+
.mypy_cache/
|
|
119
|
+
.dmypy.json
|
|
120
|
+
dmypy.json
|
|
121
|
+
|
|
122
|
+
# Pyre type checker
|
|
123
|
+
.pyre/
|
|
124
|
+
|
|
125
|
+
# IDE
|
|
126
|
+
.vscode/
|
|
127
|
+
.idea/
|
|
128
|
+
*.swp
|
|
129
|
+
*.swo
|
|
130
|
+
*~
|
|
131
|
+
|
|
132
|
+
# OS
|
|
133
|
+
.DS_Store
|
|
134
|
+
Thumbs.db
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nebu0528
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include TESTING.md
|
|
4
|
+
include requirements.txt
|
|
5
|
+
include pyproject.toml
|
|
6
|
+
recursive-include distributed_compute *.py
|
|
7
|
+
recursive-include examples *.py
|
|
8
|
+
recursive-include tests *.py
|
|
9
|
+
global-exclude __pycache__
|
|
10
|
+
global-exclude *.py[co]
|
|
11
|
+
global-exclude .DS_Store
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: distributed-compute-locally
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: A library for distributing computational workloads across multiple devices
|
|
5
|
+
Home-page: https://github.com/Nebu0528/distributor
|
|
6
|
+
Author: Nebu0528
|
|
7
|
+
Author-email: nebu0528distributor@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/Nebu0528/distributor
|
|
10
|
+
Project-URL: Documentation, https://github.com/Nebu0528/distributor#readme
|
|
11
|
+
Project-URL: Repository, https://github.com/Nebu0528/distributor
|
|
12
|
+
Project-URL: Issues, https://github.com/Nebu0528/distributor/issues
|
|
13
|
+
Keywords: distributed,computing,parallel,cluster,workload
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Requires-Python: >=3.7
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: cloudpickle>=2.0.0
|
|
30
|
+
Requires-Dist: psutil>=5.8.0
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: flake8>=4.0.0; extra == "dev"
|
|
36
|
+
Dynamic: author-email
|
|
37
|
+
Dynamic: home-page
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
Dynamic: requires-python
|
|
40
|
+
|
|
41
|
+
[](https://pypi.org/project/distributed-compute-locally/) [](https://pepy.tech/project/distributed-compute-locally) [](https://pepy.tech/project/distributed-compute-locally) [](https://opensource.org/licenses/MIT)
|
|
42
|
+
|
|
43
|
+
# Distributed Compute
|
|
44
|
+
|
|
45
|
+
A Python library for distributing computational workloads across multiple devices on a local network. Turn your spare laptops, desktops, and servers into a unified computing cluster with just a few commands.
|
|
46
|
+
|
|
47
|
+
Distributed Compute allows you to easily harness the power of multiple machines to process large workloads in parallel. Whether you're training ML models, processing data, or running simulations, this library makes distributed computing accessible without complex cluster management tools.
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- **Simple Setup** - Get started with just 2 commands
|
|
52
|
+
- **Automatic Load Balancing** - Tasks distributed to least-loaded workers
|
|
53
|
+
- **Fault Tolerance** - Automatic task redistribution on worker failure
|
|
54
|
+
- **Real-time Monitoring** - Beautiful CLI with live progress tracking
|
|
55
|
+
- **Clean API** - Pythonic interface similar to `multiprocessing.Pool`
|
|
56
|
+
- **Plug & Play** - No complex configuration required
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
Install via pip (Python 3.7+):
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install distributed-compute-locally
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Quick Start
|
|
67
|
+
|
|
68
|
+
### 1. Start the Coordinator
|
|
69
|
+
|
|
70
|
+
On your main machine:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
distcompute coordinator
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 2. Connect Workers
|
|
77
|
+
|
|
78
|
+
On each worker machine (laptops, desktops, etc.):
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
distcompute worker <coordinator-ip>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Example:
|
|
85
|
+
```bash
|
|
86
|
+
distcompute worker 192.168.1.100
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 3. Run Your Computation
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from distributed_compute import Coordinator
|
|
93
|
+
|
|
94
|
+
# Initialize coordinator
|
|
95
|
+
coordinator = Coordinator(port=5555)
|
|
96
|
+
coordinator.start()
|
|
97
|
+
|
|
98
|
+
# Define your compute function
|
|
99
|
+
def heavy_computation(x):
|
|
100
|
+
return x ** 2
|
|
101
|
+
|
|
102
|
+
# Distribute work across all connected workers
|
|
103
|
+
results = coordinator.map(heavy_computation, range(1000))
|
|
104
|
+
print(results) # [0, 1, 4, 9, 16, ...]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
That's it! Your computation is now running across all connected machines.
|
|
108
|
+
|
|
109
|
+
## Usage Examples
|
|
110
|
+
|
|
111
|
+
### Running the Demo
|
|
112
|
+
|
|
113
|
+
See it in action with the built-in demo:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
distcompute demo
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
This runs a Monte Carlo Pi estimation across 2 local workers with beautiful progress visualization.
|
|
120
|
+
|
|
121
|
+
### Basic Usage
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from distributed_compute import Coordinator
|
|
125
|
+
|
|
126
|
+
# Start coordinator
|
|
127
|
+
coordinator = Coordinator(port=5555)
|
|
128
|
+
coordinator.start()
|
|
129
|
+
|
|
130
|
+
# Simple map operation
|
|
131
|
+
def square(x):
|
|
132
|
+
return x ** 2
|
|
133
|
+
|
|
134
|
+
results = coordinator.map(square, range(100))
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Progress Tracking (New in v0.1.2!)
|
|
138
|
+
|
|
139
|
+
Track computation progress in real-time with callbacks:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from distributed_compute import Coordinator
|
|
143
|
+
|
|
144
|
+
coordinator = Coordinator(port=5555)
|
|
145
|
+
coordinator.start()
|
|
146
|
+
|
|
147
|
+
def process_task(x):
|
|
148
|
+
return x ** 2
|
|
149
|
+
|
|
150
|
+
# Progress bar callback
|
|
151
|
+
def show_progress(completed, total):
|
|
152
|
+
percent = (completed / total) * 100
|
|
153
|
+
print(f"Progress: {completed}/{total} ({percent:.1f}%)")
|
|
154
|
+
|
|
155
|
+
# Per-task callback
|
|
156
|
+
def on_task_done(task_idx, result):
|
|
157
|
+
print(f"Task {task_idx} completed: {result}")
|
|
158
|
+
|
|
159
|
+
results = coordinator.map(
|
|
160
|
+
process_task,
|
|
161
|
+
range(100),
|
|
162
|
+
on_progress=show_progress, # Called after each task
|
|
163
|
+
on_task_complete=on_task_done # Called with task details
|
|
164
|
+
)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
See `examples/progress_callback_example.py` for more advanced usage including ETA calculation and custom progress trackers.
|
|
168
|
+
|
|
169
|
+
### ML Model Inference
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from distributed_compute import Coordinator
|
|
173
|
+
|
|
174
|
+
coordinator = Coordinator(port=5555)
|
|
175
|
+
coordinator.start()
|
|
176
|
+
|
|
177
|
+
def predict(data_batch):
|
|
178
|
+
# Your ML inference code
|
|
179
|
+
return model.predict(data_batch)
|
|
180
|
+
|
|
181
|
+
# Distribute inference across workers
|
|
182
|
+
predictions = coordinator.map(predict, data_batches)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Data Processing Pipeline
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from distributed_compute import Coordinator
|
|
189
|
+
|
|
190
|
+
coordinator = Coordinator(port=5555)
|
|
191
|
+
coordinator.start()
|
|
192
|
+
|
|
193
|
+
def process_file(filepath):
|
|
194
|
+
# Your data processing logic
|
|
195
|
+
data = load_file(filepath)
|
|
196
|
+
result = transform(data)
|
|
197
|
+
return result
|
|
198
|
+
|
|
199
|
+
# Process files in parallel
|
|
200
|
+
results = coordinator.map(process_file, file_list)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## CLI Commands
|
|
204
|
+
|
|
205
|
+
The `distcompute` command provides several options:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# Start coordinator
|
|
209
|
+
distcompute coordinator [port]
|
|
210
|
+
|
|
211
|
+
# Connect worker
|
|
212
|
+
distcompute worker <host> [port] [name]
|
|
213
|
+
|
|
214
|
+
# Run demo
|
|
215
|
+
distcompute demo
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Architecture
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
┌─────────────┐
|
|
222
|
+
│ Coordinator │ ← Main machine
|
|
223
|
+
└──────┬──────┘
|
|
224
|
+
│
|
|
225
|
+
┌───┴────┬─────────┬─────────┐
|
|
226
|
+
│ │ │ │
|
|
227
|
+
┌──▼──┐ ┌──▼──┐ ┌──▼──┐ ┌──▼──┐
|
|
228
|
+
│ W-1 │ │ W-2 │ │ W-3 │ │ W-4 │ ← Worker machines
|
|
229
|
+
└─────┘ └─────┘ └─────┘ └─────┘
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
- **Coordinator**: Manages task distribution and collects results
|
|
233
|
+
- **Workers**: Execute tasks and report back to coordinator
|
|
234
|
+
- **Load Balancing**: Tasks assigned to least-loaded workers
|
|
235
|
+
- **Fault Tolerance**: Failed tasks automatically redistributed
|
|
236
|
+
|
|
237
|
+
## Advanced Configuration
|
|
238
|
+
|
|
239
|
+
### Custom Port
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
coordinator = Coordinator(port=6000)
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Verbose Logging
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
coordinator = Coordinator(port=5555, verbose=True)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Worker with Custom Name
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
distcompute worker 192.168.1.100 5555 my-worker-name
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Requirements
|
|
258
|
+
|
|
259
|
+
- Python 3.7 or higher
|
|
260
|
+
- Network connectivity between machines
|
|
261
|
+
- Same Python environment on all workers (recommended)
|
|
262
|
+
|
|
263
|
+
## Examples
|
|
264
|
+
|
|
265
|
+
Check out the `examples/` directory for more:
|
|
266
|
+
|
|
267
|
+
- `basic_usage.py` - Simple distributed map example
|
|
268
|
+
- `ml_inference.py` - ML model inference simulation
|
|
269
|
+
- `data_processing.py` - Data processing pipeline
|
|
270
|
+
- `integration_test.py` - Full end-to-end test
|
|
271
|
+
|
|
272
|
+
## Troubleshooting
|
|
273
|
+
|
|
274
|
+
**Workers not connecting?**
|
|
275
|
+
- Ensure port 5555 (default) is open on the coordinator machine
|
|
276
|
+
- Check firewall settings
|
|
277
|
+
- Verify machines are on the same network
|
|
278
|
+
- Try specifying IP explicitly: `distcompute worker 192.168.1.100`
|
|
279
|
+
|
|
280
|
+
**Tasks failing?**
|
|
281
|
+
- Ensure all workers have required dependencies installed
|
|
282
|
+
- Check worker logs for error messages
|
|
283
|
+
- Verify functions are serializable (no lambdas with external state)
|
|
284
|
+
|
|
285
|
+
## Contributing
|
|
286
|
+
|
|
287
|
+
Contributions are welcome! This project aims to make distributed computing accessible to everyone.
|
|
288
|
+
|
|
289
|
+
## License
|
|
290
|
+
|
|
291
|
+
MIT License - see LICENSE file for details.
|
|
292
|
+
|
|
293
|
+
## Acknowledgments
|
|
294
|
+
|
|
295
|
+
Built to democratize distributed computing. Powered by Python's `cloudpickle` for seamless function serialization and `psutil` for resource monitoring.
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
[](https://pypi.org/project/distributed-compute-locally/) [](https://pepy.tech/project/distributed-compute-locally) [](https://pepy.tech/project/distributed-compute-locally) [](https://opensource.org/licenses/MIT)
|
|
2
|
+
|
|
3
|
+
# Distributed Compute
|
|
4
|
+
|
|
5
|
+
A Python library for distributing computational workloads across multiple devices on a local network. Turn your spare laptops, desktops, and servers into a unified computing cluster with just a few commands.
|
|
6
|
+
|
|
7
|
+
Distributed Compute allows you to easily harness the power of multiple machines to process large workloads in parallel. Whether you're training ML models, processing data, or running simulations, this library makes distributed computing accessible without complex cluster management tools.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Simple Setup** - Get started with just 2 commands
|
|
12
|
+
- **Automatic Load Balancing** - Tasks distributed to least-loaded workers
|
|
13
|
+
- **Fault Tolerance** - Automatic task redistribution on worker failure
|
|
14
|
+
- **Real-time Monitoring** - Beautiful CLI with live progress tracking
|
|
15
|
+
- **Clean API** - Pythonic interface similar to `multiprocessing.Pool`
|
|
16
|
+
- **Plug & Play** - No complex configuration required
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
Install via pip (Python 3.7+):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install distributed-compute-locally
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### 1. Start the Coordinator
|
|
29
|
+
|
|
30
|
+
On your main machine:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
distcompute coordinator
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Connect Workers
|
|
37
|
+
|
|
38
|
+
On each worker machine (laptops, desktops, etc.):
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
distcompute worker <coordinator-ip>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Example:
|
|
45
|
+
```bash
|
|
46
|
+
distcompute worker 192.168.1.100
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 3. Run Your Computation
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from distributed_compute import Coordinator
|
|
53
|
+
|
|
54
|
+
# Initialize coordinator
|
|
55
|
+
coordinator = Coordinator(port=5555)
|
|
56
|
+
coordinator.start()
|
|
57
|
+
|
|
58
|
+
# Define your compute function
|
|
59
|
+
def heavy_computation(x):
|
|
60
|
+
return x ** 2
|
|
61
|
+
|
|
62
|
+
# Distribute work across all connected workers
|
|
63
|
+
results = coordinator.map(heavy_computation, range(1000))
|
|
64
|
+
print(results) # [0, 1, 4, 9, 16, ...]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
That's it! Your computation is now running across all connected machines.
|
|
68
|
+
|
|
69
|
+
## Usage Examples
|
|
70
|
+
|
|
71
|
+
### Running the Demo
|
|
72
|
+
|
|
73
|
+
See it in action with the built-in demo:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
distcompute demo
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
This runs a Monte Carlo Pi estimation across 2 local workers with beautiful progress visualization.
|
|
80
|
+
|
|
81
|
+
### Basic Usage
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from distributed_compute import Coordinator
|
|
85
|
+
|
|
86
|
+
# Start coordinator
|
|
87
|
+
coordinator = Coordinator(port=5555)
|
|
88
|
+
coordinator.start()
|
|
89
|
+
|
|
90
|
+
# Simple map operation
|
|
91
|
+
def square(x):
|
|
92
|
+
return x ** 2
|
|
93
|
+
|
|
94
|
+
results = coordinator.map(square, range(100))
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Progress Tracking (New in v0.1.2!)
|
|
98
|
+
|
|
99
|
+
Track computation progress in real-time with callbacks:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from distributed_compute import Coordinator
|
|
103
|
+
|
|
104
|
+
coordinator = Coordinator(port=5555)
|
|
105
|
+
coordinator.start()
|
|
106
|
+
|
|
107
|
+
def process_task(x):
|
|
108
|
+
return x ** 2
|
|
109
|
+
|
|
110
|
+
# Progress bar callback
|
|
111
|
+
def show_progress(completed, total):
|
|
112
|
+
percent = (completed / total) * 100
|
|
113
|
+
print(f"Progress: {completed}/{total} ({percent:.1f}%)")
|
|
114
|
+
|
|
115
|
+
# Per-task callback
|
|
116
|
+
def on_task_done(task_idx, result):
|
|
117
|
+
print(f"Task {task_idx} completed: {result}")
|
|
118
|
+
|
|
119
|
+
results = coordinator.map(
|
|
120
|
+
process_task,
|
|
121
|
+
range(100),
|
|
122
|
+
on_progress=show_progress, # Called after each task
|
|
123
|
+
on_task_complete=on_task_done # Called with task details
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
See `examples/progress_callback_example.py` for more advanced usage including ETA calculation and custom progress trackers.
|
|
128
|
+
|
|
129
|
+
### ML Model Inference
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from distributed_compute import Coordinator
|
|
133
|
+
|
|
134
|
+
coordinator = Coordinator(port=5555)
|
|
135
|
+
coordinator.start()
|
|
136
|
+
|
|
137
|
+
def predict(data_batch):
|
|
138
|
+
# Your ML inference code
|
|
139
|
+
return model.predict(data_batch)
|
|
140
|
+
|
|
141
|
+
# Distribute inference across workers
|
|
142
|
+
predictions = coordinator.map(predict, data_batches)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Data Processing Pipeline
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from distributed_compute import Coordinator
|
|
149
|
+
|
|
150
|
+
coordinator = Coordinator(port=5555)
|
|
151
|
+
coordinator.start()
|
|
152
|
+
|
|
153
|
+
def process_file(filepath):
|
|
154
|
+
# Your data processing logic
|
|
155
|
+
data = load_file(filepath)
|
|
156
|
+
result = transform(data)
|
|
157
|
+
return result
|
|
158
|
+
|
|
159
|
+
# Process files in parallel
|
|
160
|
+
results = coordinator.map(process_file, file_list)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## CLI Commands
|
|
164
|
+
|
|
165
|
+
The `distcompute` command provides several options:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Start coordinator
|
|
169
|
+
distcompute coordinator [port]
|
|
170
|
+
|
|
171
|
+
# Connect worker
|
|
172
|
+
distcompute worker <host> [port] [name]
|
|
173
|
+
|
|
174
|
+
# Run demo
|
|
175
|
+
distcompute demo
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Architecture
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
┌─────────────┐
|
|
182
|
+
│ Coordinator │ ← Main machine
|
|
183
|
+
└──────┬──────┘
|
|
184
|
+
│
|
|
185
|
+
┌───┴────┬─────────┬─────────┐
|
|
186
|
+
│ │ │ │
|
|
187
|
+
┌──▼──┐ ┌──▼──┐ ┌──▼──┐ ┌──▼──┐
|
|
188
|
+
│ W-1 │ │ W-2 │ │ W-3 │ │ W-4 │ ← Worker machines
|
|
189
|
+
└─────┘ └─────┘ └─────┘ └─────┘
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
- **Coordinator**: Manages task distribution and collects results
|
|
193
|
+
- **Workers**: Execute tasks and report back to coordinator
|
|
194
|
+
- **Load Balancing**: Tasks assigned to least-loaded workers
|
|
195
|
+
- **Fault Tolerance**: Failed tasks automatically redistributed
|
|
196
|
+
|
|
197
|
+
## Advanced Configuration
|
|
198
|
+
|
|
199
|
+
### Custom Port
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
coordinator = Coordinator(port=6000)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Verbose Logging
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
coordinator = Coordinator(port=5555, verbose=True)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Worker with Custom Name
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
distcompute worker 192.168.1.100 5555 my-worker-name
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Requirements
|
|
218
|
+
|
|
219
|
+
- Python 3.7 or higher
|
|
220
|
+
- Network connectivity between machines
|
|
221
|
+
- Same Python environment on all workers (recommended)
|
|
222
|
+
|
|
223
|
+
## Examples
|
|
224
|
+
|
|
225
|
+
Check out the `examples/` directory for more:
|
|
226
|
+
|
|
227
|
+
- `basic_usage.py` - Simple distributed map example
|
|
228
|
+
- `ml_inference.py` - ML model inference simulation
|
|
229
|
+
- `data_processing.py` - Data processing pipeline
|
|
230
|
+
- `integration_test.py` - Full end-to-end test
|
|
231
|
+
|
|
232
|
+
## Troubleshooting
|
|
233
|
+
|
|
234
|
+
**Workers not connecting?**
|
|
235
|
+
- Ensure port 5555 (default) is open on the coordinator machine
|
|
236
|
+
- Check firewall settings
|
|
237
|
+
- Verify machines are on the same network
|
|
238
|
+
- Try specifying IP explicitly: `distcompute worker 192.168.1.100`
|
|
239
|
+
|
|
240
|
+
**Tasks failing?**
|
|
241
|
+
- Ensure all workers have required dependencies installed
|
|
242
|
+
- Check worker logs for error messages
|
|
243
|
+
- Verify functions are serializable (no lambdas with external state)
|
|
244
|
+
|
|
245
|
+
## Contributing
|
|
246
|
+
|
|
247
|
+
Contributions are welcome! This project aims to make distributed computing accessible to everyone.
|
|
248
|
+
|
|
249
|
+
## License
|
|
250
|
+
|
|
251
|
+
MIT License - see LICENSE file for details.
|
|
252
|
+
|
|
253
|
+
## Acknowledgments
|
|
254
|
+
|
|
255
|
+
Built to democratize distributed computing. Powered by Python's `cloudpickle` for seamless function serialization and `psutil` for resource monitoring.
|