Metadata-Version: 2.4
Name: huddle-cluster
Version: 3.5.0
Summary: A penguin-inspired self-organizing server load balancer with adaptive thermal eviction — now with master/agent cluster management
Author-email: Rahad Bhuiya <rahadbhuiya2021@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Rahad Bhuiya
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/rahadbhuiya/HuddleCluster
Project-URL: Repository, https://github.com/rahadbhuiya/HuddleCluster
Project-URL: Documentation, https://github.com/rahadbhuiya/HuddleCluster/blob/main/USAGE.md
Project-URL: Bug Tracker, https://github.com/rahadbhuiya/HuddleCluster/issues
Project-URL: Paper, https://github.com/rahadbhuiya/HuddleCluster/blob/main/docs/HuddleCluster.pdf
Keywords: load-balancer,load-balancing,distributed-systems,cluster,master,agent,server-routing,bio-inspired,penguin,self-organizing,adaptive,anomaly-detection,fairness
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: System :: Distributed Computing
Classifier: Topic :: System :: Networking
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.111.0; extra == "fastapi"
Requires-Dist: uvicorn[standard]>=0.29.0; extra == "fastapi"
Requires-Dist: httpx>=0.27.0; extra == "fastapi"
Requires-Dist: pydantic>=2.7.0; extra == "fastapi"
Provides-Extra: redis
Requires-Dist: redis>=5.0.0; extra == "redis"
Provides-Extra: grpc
Requires-Dist: grpcio>=1.62.0; extra == "grpc"
Provides-Extra: kubernetes
Requires-Dist: kubernetes>=29.0.0; extra == "kubernetes"
Provides-Extra: simulation
Requires-Dist: rich>=13.7.0; extra == "simulation"
Provides-Extra: benchmark
Requires-Dist: matplotlib>=3.8; extra == "benchmark"
Requires-Dist: numpy>=1.26; extra == "benchmark"
Requires-Dist: scipy>=1.13; extra == "benchmark"
Requires-Dist: httpx>=0.27.0; extra == "benchmark"
Provides-Extra: dev
Requires-Dist: pytest>=8.2.0; extra == "dev"
Requires-Dist: pytest-timeout>=2.3.0; extra == "dev"
Requires-Dist: build>=1.0.0; extra == "dev"
Requires-Dist: twine>=5.0.0; extra == "dev"
Requires-Dist: fakeredis>=2.21.0; extra == "dev"
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/rahadbhuiya/HuddleCluster/main/assets/logo.svg" width="380" alt="HuddleCluster"/>
</p>

<p align="center">
  <a href="https://pypi.org/project/huddle-cluster/"><img src="https://img.shields.io/pypi/v/huddle-cluster?color=0e7a0e&label=PyPI" alt="PyPI version"/></a>
  <a href="https://pypi.org/project/huddle-cluster/"><img src="https://img.shields.io/pypi/pyversions/huddle-cluster?color=0e7a0e" alt="Python versions"/></a>
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT License"/></a>
  <a href="https://doi.org/10.5281/zenodo.20348019"><img src="https://img.shields.io/badge/DOI-10.5281%2Fzenodo.20348019-blue" alt="DOI"/></a>
  <a href="https://github.com/rahadbhuiya/HuddleCluster/actions"><img src="https://img.shields.io/github/actions/workflow/status/rahadbhuiya/HuddleCluster/ci.yml?label=tests" alt="CI"/></a>
</p>

<p align="center">
  <strong>Penguin-inspired self-organizing load balancer with adaptive thermal eviction.</strong>
</p>

---

Emperor Penguins survive Antarctic blizzards without any central coordinator — each bird follows one rule: if you're cold, push inward; if you're warm, drift outward. The huddle self-organizes.

HuddleCluster applies this directly to server scheduling. Servers that run hot rotate to an outer ring to cool down. Cooled servers rotate back in. No manual tuning. No fixed thresholds. The cluster finds its own equilibrium.

---

## Install

```bash
pip install huddle-cluster
```

Optional extras: `fastapi` · `redis` · `grpc` · `kubernetes`

---

## Single-instance

```python
from huddle_cluster import create_cluster
import requests

cluster = create_cluster([
    ("web-1", "10.0.0.1", 8080),
    ("web-2", "10.0.0.2", 8080),
    ("web-3", "10.0.0.3", 8080),
])
cluster.start()

with cluster.get_server_context() as server:
    response = requests.get(f"http://{server.host}:{server.port}/api")
```

What the cluster reports at any point:

```python
print(cluster.health_report())
```

```json
{
  "inner_servers": ["web-1", "web-3"],
  "outer_servers": ["web-2"],
  "fairness_score": 0.94,
  "rotation_count": 12,
  "requests_per_sec": 847.3,
  "cluster_health": "healthy"
}
```

---

## Multi-node cluster

Coordinate a fleet of hosts — each node runs its own HuddleCluster; the master tracks enrollment, heartbeats, and health.

```bash
# Start the coordinator
huddle-cluster master start --port 7070

# Enroll nodes on each host
huddle-cluster agent start --id web-01 --master http://master:7070 --port 8080

# Inspect from anywhere
huddle-cluster nodes list
```

```
NODE ID                ADDRESS                STATUS       HB       LAST SEEN
─────────────────────────────────────────────────────────────────────────────
web-01                 10.0.0.1:8080          alive        142      0.8s ago
web-02                 10.0.0.2:8080          alive        139      1.1s ago
web-03                 10.0.0.3:8080          dead         41       34.2s ago
```

Ask the scheduler which node to send the next workload to:

```bash
curl http://master:7070/v1/scheduler/next
```

```json
{ "ok": true, "node": { "node_id": "web-01", "address": "10.0.0.1", "port": 8080 } }
```

Live topology and Prometheus metrics are built in:

```
http://master:7070/dashboard      → real-time cluster topology
http://master:7070/v1/metrics     → Prometheus scrape endpoint
http://master:7070/v1/docs        → interactive API explorer (Swagger UI)
```

---

## How it works

| Concept | What it means |
|---|---|
| **Inner ring** | Active servers handling traffic right now |
| **Outer ring** | Servers cooling down after a hot streak |
| **Thermal score** | EMA of relative latency anomaly, CPU, memory, error rate |
| **Rotation** | Overheated servers evict outward; cooled servers return inward |
| **Relative anomaly** | Compared to the cluster median — adapts to any baseline automatically |

No server is permanently marked bad. Every server gets rest and returns.

---

## Performance

Under server failure, P95 latency stays under **86 ms** where NGINX round-robin reaches **5,027 ms** — a 58× reduction. Full methodology and results in the research paper below.

---

## Documentation

| | |
|---|---|
| **Single-instance guide** | [`USAGE.md`](USAGE.md) |
| **Cluster system** | [`docs/CLUSTER.md`](docs/CLUSTER.md) — MasterNode, Scheduler, RBAC, dashboard, API |
| **API explorer** | `http://your-master:7070/v1/docs` (live, once the master is running) |
| **Research paper** | [`docs/HuddleCluster.pdf`](docs/HuddleCluster.pdf) · [arXiv preprint](docs/HuddleCluster_arxiv.pdf) |

---

## Roadmap

- Thermal eviction, relative anomaly scoring, adaptive thresholds — v1.x
- Redis backend, gRPC routing, Kubernetes discovery, Prometheus, webhooks — v1.4
- Cluster system: MasterNode, AgentNode, CLI — v2.0
- Auto recovery, RBAC, metrics, dashboard, OpenAPI + Swagger UI — v2.x
- Cluster Scheduler — thermal-fitness workload placement — v3.0
- Cluster Auto Scaler — load-signal scale recommendations — v3.1
- Rolling Updater — zero-downtime batch upgrades with health gate — v3.2
- Service Discovery — health-aware registry, metadata-driven, DNS responder — v3.3
- HA Master — simplified Raft leader election, state replication, write redirect — v3.4
- Multi-Region — cross-datacenter topology, region-aware scheduling — v3.5

---

## Citation

```
Bhuiya, R. (2025). HuddleCluster: A Penguin-Inspired Self-Organizing Load Balancer
with Adaptive Thermal Eviction. https://github.com/rahadbhuiya/HuddleCluster
```

```
Bhuiya, Rahad (2026). HuddleCluster. figshare. Journal contribution.
https://doi.org/10.6084/m9.figshare.32397180
```

```
Bhuiya, Rahad (2026). HuddleCluster. Zenodo. https://doi.org/10.5281/zenodo.20348019
```

---

**Author:** Rahad Bhuiya &nbsp;·&nbsp; **License:** MIT
