# 算力集市 **Repository Path**: tianyeHome/compute_bazaar ## Basic Information - **Project Name**: 算力集市 - **Description**: 做Ai时代的房东,让每一张显卡都不闲着 - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-10-17 - **Last Updated**: 2026-10-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
Make Every GPU Count
🌐 Visit Website | 🛡️ Privacy Policy | 🎬 Demo Video
--- ## Compute Bazaar > The bulletin board of the AI era — securely and conveniently distribute idle GPU computing power to those who need it. **Compute Bazaar** is a LAN computing power sharing platform based on Flutter and FastAPI. It is dedicated to securely and conveniently distributing idle GPU computing power within a LAN, serving as "the bulletin board of the AI era." For detailed product design, see: [Product Design Whitepaper](docs/product_design.md)
Docker sandbox isolation execution, real nvidia-smi output returned
Real-time monitoring of GPU utilization, VRAM and temperature
One-click authorization, environment detection (NVIDIA driver / GPU / CUDA / Docker) all green ✅
| Page | Function | |------|----------| | **GPU Monitor** | Request /api/gpu/metrics every 2s, real-time render utilization / VRAM / temperature + fl_chart ECG-style scrolling charts (30-point sliding window) | | **Task Management** | Connect to /api/task/list, clickable stat items for filtering + SegmentedButton status filter + search + paginated loading, show desensitized task name / status / duration, support task termination | | **Revenue Stats** | Calculate time slices / service duration / completed tasks based on real data, show recent service records | | **Agent Settings** | Real-time detect Agent process / NVIDIA driver / GPU / CUDA / Docker engine status; blue "Start & Authorize Agent" button when offline, red "Stop & Deactivate Service" button when running | ### General Features - **Online / Offline toggle**: Manually switch online status; submit button auto-disables when offline - **Agent not started warning**: Red warning banner at top when Agent unreachable in landlord mode - **Authorization status banner**: After authorization succeeds, a green banner "🛡️ Authorized for rental, sandbox isolation enabled" appears at the top - **Rental authorization agreement**: First switch to landlord mode requires agreeing to the "Compute Sharing Rental Agreement" (no sleep / platform as info intermediary only / liability separation / sandbox security), followed by real HTTP handshake to detect Agent - **Docker isolation badge**: Task submit page clearly marks 🛡️ Tasks run in Docker isolated sandbox - **Log system**: In-app log viewer with search / level filter / auto-scroll / copy / export JSON - **Agent process log capture**: Auto-launched Python backend stdout/stderr written to App log page in real-time, tagged [Agent], ERROR log + auto-restart on abnormal exit; uvicorn INFO/WARNING level stderr correctly identified as normal logs, not errors - **Heartbeat anti-misjudgment**: 30s polling + /api/health priority probe + 3 consecutive failures (90s) before disconnect + proactive heartbeat confirm, avoids single network jitter misjudgment; heartbeat failure counting paused during Agent startup, no yellow/red warning before first ready - **Agent standalone packaging**: PyInstaller build.spec packages as compute-bazaar-agent.exe, frontend prioritizes exe launch, falls back to python main.py; mode_switch_dialog home dialog "Agree & Start" auto-launches Agent --- ## Backend API ### GPU Monitoring | Method | Path | Description | |--------|------|-------------| | GET | `/api/gpu/info` | Return GPU list (name, VRAM) | | GET | `/api/gpu/metrics` | Return GPU utilization, VRAM usage, temperature | | GET | `/api/gpu/stream` | SSE real-time GPU metrics stream | ### Task Management | Method | Path | Description | |--------|------|-------------| | POST | `/api/task/submit` | Submit controlled task (Docker container isolation, 60s timeout) | | GET | `/api/task/list` | List all tasks | | GET | `/api/task/{id}/status` | Query single task status and output | | POST | `/api/task/{id}/stop` | Force stop task | **Allowed task types (whitelist)**: `system_check` (System Check Docker), `ai_inference` (AI Inference Sim) **Docker execution commands**: ```bash # Windows (WSL) wsl docker run --rm --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all nvidia/cuda:11.0-base nvidia-smi # Linux/Mac docker run --rm --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all nvidia/cuda:11.0-base nvidia-smi ``` > 🛡️ All tasks execute in Docker isolated containers, never directly invoke host commands. 60-second timeout auto-kill. Task names are desensitized (e.g., "System Check (Docker)" instead of raw docker command). ### Other | Method | Path | Description | |--------|------|-------------| | GET | `/api/env/check` | Environment detection (NVIDIA driver, GPU, CUDA, Docker engine) | | GET | `/api/health` | Agent health check | | GET | `/api/heartbeat/status` | Heartbeat status | | POST | `/api/heartbeat/confirm` | Confirm heartbeat (prevent unconfirmed_count accumulation) | --- ## UDP Node Discovery Protocol | Parameter | Value | |-----------|-------| | Broadcast port | 39878 | | Broadcast interval | 3 seconds | | Broadcast address | 255.255.255.255 | | Timeout removal | Remove node after 45s without heartbeat | --- ## 📥 Download & Experience - **Windows Client**: The app is currently under review on the Microsoft Store. Please visit [the official website](https://computebazaar.netlify.app) for installation instructions. - **Build from Source**: See the "Quick Start" section below. ## Quick Start ### Requirements | Dependency | Version | Purpose | |------------|---------|---------| | **Flutter** | 3.27+ / Dart 3.6+ | Frontend desktop app | | **Python** | 3.10+ | Agent backend service | | **Docker Desktop** | Latest stable | Task sandbox isolation (Windows via WSL2) | | **NVIDIA Container Toolkit** | Latest stable | Docker GPU passthrough (`--runtime=nvidia`) | | **NVIDIA GPU + driver + CUDA** | Any CUDA 11+ capable GPU | Landlord mode GPU collection & task execution | | **Windows** | 10/11 | Current single-machine platform | > 💡 **Tip**: If you only use tenant mode (submitting tasks to remote nodes), you don't need Docker or an NVIDIA GPU on your machine. ### 🚀 Detailed Startup & Verification Guide (with Docker/WSL Isolation) To ensure LAN discovery and Docker sandbox isolation work properly, follow these steps in order. It's recommended to open **three terminal windows** to observe logs. #### 1. Start Backend Agent Service (PowerShell Window A) ```powershell # Activate Python virtual environment (modify name to match your setup) conda activate ai_env # Enter backend directory cd agent_backend # Install dependencies (first time or when dependencies change) pip install -r requirements.txt # Start FastAPI service python main.py ``` On successful startup, you should see output like: ``` INFO: Started server process [xxxxx] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:39877 (Press CTRL+C to quit) [UDP] Broadcasting node info to 255.255.255.255:39878 ... ``` **Verify the backend is running**: ```powershell # Health check curl http://127.0.0.1:39877/api/health # Expected: {"status":"ok","agent":"running"} # Environment check (confirm GPU / Docker are recognized) curl http://127.0.0.1:39877/api/env/check # Expected: response with driver_version, gpu, cuda, docker fields # GPU info curl http://127.0.0.1:39877/api/gpu/info # Expected: GPU name, total VRAM, etc. ``` #### 2. Verify Docker + WSL2 GPU Isolation (PowerShell Window B) > ⚠️ This step is only needed on first deployment or when Docker/GPU configuration seems broken. ```powershell # Confirm WSL2 is installed and Docker Desktop is running wsl --list --verbose # Expected: Docker Desktop's WSL2 distribution listed # Verify Docker is available inside WSL2 wsl docker --version # Verify NVIDIA Container Toolkit works inside WSL2 wsl docker run --rm --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all nvidia/cuda:11.0-base nvidia-smi # Expected: GPU info matching host nvidia-smi output ``` If `nvidia-smi` fails to detect GPU inside the container, check: - Docker Desktop → Settings → Resources → WSL Integration is enabled - NVIDIA Container Toolkit is properly installed (`nvidia-ctk --version`) - Host `nvidia-smi` works correctly #### 3. Start Frontend Flutter App (PowerShell Window C) ```powershell # Enter frontend directory cd apps/compute_bazaar_local # Install dependencies (first time or when dependencies change) flutter pub get # Start Windows desktop app flutter run -d windows ``` On successful startup, the Flutter window opens automatically, defaulting to **Tenant Mode**. #### 4. End-to-End Verification **Tenant Mode Verification**: 1. Open the app, default to tenant mode 2. Wait for LAN nodes to appear on "Node Discovery" page (local node auto-discovered when backend is running) 3. On "Task Submit" page, select target node → select task template (System Check Docker / AI Inference Sim) → submit 4. View task execution status and output on "Usage View" page 5. Switch to PowerShell Window A to observe backend logs, confirm Docker container startup and task execution records **Landlord Mode Verification**: 1. Confirm Agent backend is running in Window A 2. Switch to "Landlord Mode" via top-right toggle 3. First-time switch requires agreeing to the "Compute Sharing Rental Agreement"; after clicking "Agree & Start", the frontend sends a real HTTP handshake to `http://127.0.0.1:39877/api/health` 4. Handshake success → authorization complete, green banner "🛡️ Authorized for rental, sandbox isolation enabled" appears at top 5. Handshake failure → dialog prompts "Local Agent service not detected, please ensure python main.py is running in terminal" 6. View real-time GPU status on "GPU Monitor" page (2s refresh, ECG-style charts) 7. View and manage running tasks on "Task Management" page 8. On "Agent Settings" page, confirm environment detection status (NVIDIA driver / GPU / CUDA / Docker all green ✅) 9. Click red "Stop & Deactivate Service" button to clear authorization **Docker Isolation Verification**: 1. Submit a "System Check (Docker)" task in landlord mode 2. Switch to PowerShell Window A, observe `docker run` command in backend logs 3. In Window B, run `wsl docker ps` to confirm the container is running 4. After task completes (~10-30s), run `wsl docker ps` again to confirm container auto-cleanup (`--rm` mode) #### 5. Troubleshooting | Issue | Resolution | |-------|------------| | Backend startup `ModuleNotFoundError` | Confirm `pip install -r requirements.txt` was run, check Python virtual environment is activated | | `/api/health` returns connection refused | Confirm backend is running and port 39877 is not occupied: `netstat -ano \| findstr 39877` | | GPU info returns empty | Confirm host `nvidia-smi` works, pynvml dependency installed: `pip show pynvml` | | Docker container fails to start | Confirm Docker Desktop is running, WSL2 integration enabled, NVIDIA Container Toolkit installed | | `nvidia-smi` fails inside container | Check `--runtime=nvidia` is effective, try `wsl docker run --rm --runtime=nvidia ...` manually | | No nodes on discovery page | Confirm UDP broadcast started (logs should show `[UDP] Broadcasting`), check firewall allows UDP 39878 | | Flutter compilation error | Confirm Flutter 3.27+: `flutter --version`, run `flutter clean && flutter pub get` | | Task persistence lost | Confirm `agent_backend/data/tasks.db` exists and is writable, backend auto-restores on restart | --- ## Contributing 1. Fork this repository 2. Create feature branch: `git checkout -b feature/your-feature` 3. Commit changes: `git commit -m 'Add some feature'` 4. Push branch: `git push origin feature/your-feature` 5. Submit Pull Request ### Development Standards - Dart code follows [Effective Dart](https://dart.dev/guides/language/effective-dart) guidelines - Python code follows PEP 8 - Commit messages follow Conventional Commits format --- ## License This project is licensed under [Apache License 2.0](LICENSE). ---Compute Bazaar — Make Every GPU Count