Add Supercomputer category: 12 P2P resource-sharing modules (164 total)
Introduce a new production category for distributed system resource pooling over Hyperswarm — CPU, RAM, GPU, bandwidth, disk, jobs, cache, and egress. New modules (supercomputer/): - hyper-p2p-capacity-registry — gossip CPU/RAM/GPU/disk/bandwidth ads - hyper-p2p-cpu-share — CPU millisecond credit pool - hyper-p2p-ram-pool — RAM byte lend/claim/release - hyper-p2p-gpu-slot — GPU slot register/reserve - hyper-p2p-bandwidth-share — shared up/down Mbps - hyper-p2p-disk-stripe — striped block shards - hyper-p2p-job-dispatcher — submit/claim/complete jobs - hyper-p2p-thermal-guard — load/temperature throttle signals - hyper-p2p-cache-farm — distributed LRU cache - hyper-p2p-net-gateway — peer internet egress routing - hyper-p2p-cluster-affinity — hardware tag placement scoring - hyper-p2p-work-stealer — shard queues + work stealing Each package: index.js, tests, README, api/architecture docs, examples/basic.js. Shared layering guide: _shared/SUPERCOMPUTER_LAYERS.md. Registry, module-paths, MODULE_CATEGORIES, and workspace README updated to 164. Parent workspace also adds docs/supercomputer hub and demo-supercomputer-mesh (outside this repo). Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## 0.3.0
|
||||
|
||||
- Initial Supercomputer category release (capacity-registry/v1).
|
||||
@@ -0,0 +1,30 @@
|
||||
# hyper-p2p-capacity-registry
|
||||
|
||||
Production **Supercomputer** module: pool P2P system resources over Hyperswarm.
|
||||
|
||||
**Category:** Supercomputer · **Protocol:** `capacity-registry/v1` · **Export:** `HyperP2PCapacityRegistry`
|
||||
|
||||
## When to use
|
||||
|
||||
Gossip registry of peer CPU, RAM, GPU, disk, and bandwidth capacity.
|
||||
|
||||
## Quick start
|
||||
|
||||
```js
|
||||
const { HyperP2PCapacityRegistry } = require('hyper-p2p-capacity-registry')
|
||||
const mod = new HyperP2PCapacityRegistry({ topic: 'my-super-mesh' })
|
||||
await mod.ready()
|
||||
// ...
|
||||
await mod.close()
|
||||
```
|
||||
|
||||
## Docs
|
||||
|
||||
- [docs/api.md](docs/api.md)
|
||||
- [docs/architecture.md](docs/architecture.md)
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
npm install && npm test
|
||||
```
|
||||
@@ -0,0 +1,36 @@
|
||||
# API: hyper-p2p-capacity-registry
|
||||
|
||||
**Protocol:** `capacity-registry/v1` · **Export:** `HyperP2PCapacityRegistry`
|
||||
|
||||
## Overview
|
||||
|
||||
Gossip registry of peer CPU, RAM, GPU, disk, and bandwidth capacity.
|
||||
|
||||
## Constructor
|
||||
|
||||
```js
|
||||
const mod = new HyperP2PCapacityRegistry(opts)
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
|--------|------|---------|-------------|
|
||||
| `topic` | Buffer \| string \| null | `null` | Hyperswarm topic |
|
||||
| `keyPair` | KeyPair | random | Discovery identity |
|
||||
|
||||
## Methods
|
||||
|
||||
See [`index.js`](../index.js) for the full method list. All modules implement `getStats()`, `async ready()`, and `async close()`.
|
||||
|
||||
## getStats()
|
||||
|
||||
Returns `{ ...stats, protocol: 'capacity-registry/v1' }` plus module-specific counters.
|
||||
|
||||
## P2P
|
||||
|
||||
When `topic` is set, `ready()` joins Hyperswarm and opens Protomux `capacity-registry/v1`.
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
npm install && npm test
|
||||
```
|
||||
@@ -0,0 +1,14 @@
|
||||
# Architecture: hyper-p2p-capacity-registry
|
||||
|
||||
**Category:** Supercomputer · **Protocol:** `capacity-registry/v1`
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
App[Application] --> Mod[HyperP2PCapacityRegistry]
|
||||
Mod --> Mux[Protomux capacity-registry/v1]
|
||||
Mux --> Swarm[Hyperswarm]
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
See [`../../_shared/SUPERCOMPUTER_LAYERS.md`](../../_shared/SUPERCOMPUTER_LAYERS.md) and [`../README.md`](../README.md).
|
||||
@@ -0,0 +1,10 @@
|
||||
require('bare-process/global')
|
||||
const { HyperP2PCapacityRegistry } = require('../index.js')
|
||||
|
||||
async function main () {
|
||||
const mod = new HyperP2PCapacityRegistry()
|
||||
console.log('stats', mod.getStats())
|
||||
await mod.close()
|
||||
console.log('done')
|
||||
}
|
||||
main().catch(console.error)
|
||||
@@ -0,0 +1,104 @@
|
||||
require('bare-process/global')
|
||||
const EventEmitter = require('bare-events')
|
||||
const b4a = require('b4a')
|
||||
const { initModuleSwarm, gossipSend } = require('../../_shared/p2p-bare.js')
|
||||
|
||||
const PROTOCOL = 'capacity-registry/v1'
|
||||
|
||||
class HyperP2PCapacityRegistry extends EventEmitter {
|
||||
constructor (opts = {}) {
|
||||
super()
|
||||
this._stats = { ops: 0, errors: 0 }
|
||||
this.topic = opts.topic || null
|
||||
this.keyPair = opts.keyPair || require('hypercore-crypto').keyPair()
|
||||
this.peerId = b4a.toString(this.keyPair.publicKey, 'hex')
|
||||
this._peers = new Map()
|
||||
this.swarm = null
|
||||
this._peerMsgs = null
|
||||
}
|
||||
|
||||
_pid (peerId) {
|
||||
return typeof peerId === 'string' ? peerId : b4a.toString(peerId, 'hex')
|
||||
}
|
||||
|
||||
advertise (resources = {}, peerId = null) {
|
||||
const id = this._pid(peerId || this.peerId)
|
||||
const rec = {
|
||||
peerId: id,
|
||||
cpuCores: Math.max(0, resources.cpuCores ?? 0),
|
||||
ramMb: Math.max(0, resources.ramMb ?? 0),
|
||||
diskGb: Math.max(0, resources.diskGb ?? 0),
|
||||
gpuSlots: Math.max(0, resources.gpuSlots ?? 0),
|
||||
upMbps: Math.max(0, resources.upMbps ?? 0),
|
||||
downMbps: Math.max(0, resources.downMbps ?? 0),
|
||||
tags: resources.tags || [],
|
||||
at: Date.now()
|
||||
}
|
||||
this._peers.set(id, rec)
|
||||
this._stats.ops++
|
||||
if (this._peerMsgs) gossipSend(this, { type: 'advertise', record: rec })
|
||||
this.emit('advertise', rec)
|
||||
return rec
|
||||
}
|
||||
|
||||
lookup (peerId) {
|
||||
return this._peers.get(this._pid(peerId)) || null
|
||||
}
|
||||
|
||||
listPeers () { return [...this._peers.values()] }
|
||||
|
||||
bestMatch (requirements = {}) {
|
||||
let best = null
|
||||
let bestScore = -1
|
||||
for (const rec of this._peers.values()) {
|
||||
if (requirements.cpuCores != null && rec.cpuCores < requirements.cpuCores) continue
|
||||
if (requirements.ramMb != null && rec.ramMb < requirements.ramMb) continue
|
||||
if (requirements.gpuSlots != null && rec.gpuSlots < requirements.gpuSlots) continue
|
||||
const score = rec.cpuCores + rec.ramMb / 1024 + rec.gpuSlots * 4 + rec.upMbps / 10
|
||||
if (score > bestScore) { bestScore = score; best = rec }
|
||||
}
|
||||
return best
|
||||
}
|
||||
|
||||
merge (remote) {
|
||||
if (!remote || !remote.records) return 0
|
||||
let n = 0
|
||||
for (const rec of remote.records) {
|
||||
const cur = this._peers.get(rec.peerId)
|
||||
if (!cur || rec.at > cur.at) {
|
||||
this._peers.set(rec.peerId, rec)
|
||||
n++
|
||||
}
|
||||
}
|
||||
if (n) this.emit('merge', { updated: n })
|
||||
return n
|
||||
}
|
||||
|
||||
toJSON () { return { records: this.listPeers() } }
|
||||
|
||||
async ready () {
|
||||
if (this.swarm || !this.topic) return this
|
||||
await initModuleSwarm(this, {
|
||||
keyPair: this.keyPair,
|
||||
topic: this.topic,
|
||||
protocol: PROTOCOL,
|
||||
onmessage: (data) => {
|
||||
if (data?.type === 'advertise' && data.record) this.merge({ records: [data.record] })
|
||||
}
|
||||
})
|
||||
return this
|
||||
}
|
||||
|
||||
getStats () {
|
||||
return { ...this._stats, peers: this._peers.size, protocol: PROTOCOL }
|
||||
}
|
||||
|
||||
async close () {
|
||||
if (this.swarm) await this.swarm.destroy().catch(() => {})
|
||||
this.swarm = null
|
||||
this._peers.clear()
|
||||
this.emit('closed')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { HyperP2PCapacityRegistry, PROTOCOL }
|
||||
+1774
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "hyper-p2p-capacity-registry",
|
||||
"version": "0.3.0",
|
||||
"description": "Peer resource advertisement registry for Bare/Pear P2P supercomputer mesh.",
|
||||
"main": "index.js",
|
||||
"type": "commonjs",
|
||||
"license": "Apache-2.0",
|
||||
"scripts": { "test": "brittle-bare test/test.js" },
|
||||
"dependencies": {
|
||||
"bare-events": "^2.8.0",
|
||||
"bare-process": "^4.4.0",
|
||||
"b4a": "^1.6.7",
|
||||
"hypercore-crypto": "^3.0.0",
|
||||
"protomux": "^3.0.0",
|
||||
"compact-encoding": "^2.0.0"
|
||||
},
|
||||
"peerDependencies": { "hyperswarm": "^4.0.0", "bare": ">=1.0.0" },
|
||||
"devDependencies": { "brittle": "^3.0.0" },
|
||||
"imports": {
|
||||
"process": { "bare": "bare-process", "default": "process" },
|
||||
"events": { "bare": "bare-events", "default": "events" }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
require('bare-process/global')
|
||||
const test = require('brittle')
|
||||
const { HyperP2PCapacityRegistry } = require('../index.js')
|
||||
|
||||
test('capacity-registry: advertise and match', async (t) => {
|
||||
const r = new HyperP2PCapacityRegistry()
|
||||
r.advertise({ cpuCores: 8, ramMb: 16384 })
|
||||
const best = r.bestMatch({ cpuCores: 4, ramMb: 8192 })
|
||||
t.ok(best)
|
||||
t.is(best.cpuCores, 8)
|
||||
await r.close()
|
||||
})
|
||||
|
||||
test('capacity-registry: getStats', async (t) => {
|
||||
const r = new HyperP2PCapacityRegistry()
|
||||
t.is(r.getStats().protocol, 'capacity-registry/v1')
|
||||
await r.close()
|
||||
})
|
||||
|
||||
test('capacity-registry: close idempotent', async (t) => {
|
||||
const m = new HyperP2PCapacityRegistry()
|
||||
await m.close()
|
||||
await m.close()
|
||||
t.pass()
|
||||
})
|
||||
Reference in New Issue
Block a user