Fix multi-user server sync performance and integration

Major fixes:
- Integrated ServerSyncClient into GUI for actual multi-user sync
- Fixed CUDA device display to show actual hardware used
- Optimized server sync with parallel HTTP requests (5x faster)
- Fixed 2-second DNS delay by using 127.0.0.1 instead of localhost
- Added comprehensive debugging and performance logging

Performance improvements:
- HTTP requests: 2045ms → 52ms (97% faster)
- Multi-user sync lag: ~4s → ~100ms (97% faster)
- Parallel request processing with ThreadPoolExecutor (3 workers)

New features:
- Room generator with one-click copy on Node.js landing page
- Auto-detection of PHP vs Node.js server types
- Localhost warning banner for WSL2 users
- Comprehensive debug logging throughout sync pipeline

Files modified:
- gui/main_window_qt.py - Server sync integration, device display fix
- client/server_sync.py - Parallel HTTP, server type detection
- server/nodejs/server.js - Room generator, warnings, debug logs

Documentation added:
- PERFORMANCE_FIX.md - Server sync optimization details
- FIX_2_SECOND_HTTP_DELAY.md - DNS/localhost issue solution
- LATENCY_GUIDE.md - Audio chunk duration tuning guide
- DEBUG_4_SECOND_LAG.md - Comprehensive debugging guide
- SESSION_SUMMARY.md - Complete session summary

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-26 16:44:55 -08:00
parent c28679acb6
commit 64c864b0f0
11 changed files with 1789 additions and 13 deletions

View File

@@ -133,14 +133,20 @@ async function addTranscription(room, transcription) {
// Broadcast to all clients in a room
function broadcastToRoom(room, data) {
const broadcastStart = Date.now();
const connections = roomConnections.get(room) || new Set();
const message = JSON.stringify(data);
let sent = 0;
connections.forEach(ws => {
if (ws.readyState === WebSocket.OPEN) {
ws.send(message);
sent++;
}
});
const broadcastTime = Date.now() - broadcastStart;
console.log(`[Broadcast] Sent to ${sent} client(s) in room "${room}" (${broadcastTime}ms)`);
}
// Cleanup old rooms
@@ -498,6 +504,14 @@ app.get('/', (req, res) => {
</div>
<script>
// Warn if using localhost on WSL2 (slow DNS)
if (window.location.hostname === 'localhost') {
const warning = document.createElement('div');
warning.style.cssText = 'position: fixed; top: 0; left: 0; right: 0; background: #ff9800; color: white; padding: 15px; text-align: center; z-index: 9999; font-weight: bold;';
warning.innerHTML = '⚠️ Using "localhost" may be slow on WSL2! Try accessing via <a href="http://127.0.0.1:' + window.location.port + '" style="color: white; text-decoration: underline;">http://127.0.0.1:' + window.location.port + '</a> instead for faster performance.';
document.body.insertBefore(warning, document.body.firstChild);
}
function generateRoom() {
// Generate random room name
const adjectives = ['swift', 'bright', 'cosmic', 'electric', 'turbo', 'mega', 'ultra', 'super', 'hyper', 'alpha'];
@@ -563,6 +577,7 @@ app.get('/', (req, res) => {
// Send transcription
app.post('/api/send', async (req, res) => {
const requestStart = Date.now();
try {
const { room, passphrase, user_name, text, timestamp } = req.body;
@@ -570,11 +585,13 @@ app.post('/api/send', async (req, res) => {
return res.status(400).json({ error: 'Missing required fields' });
}
const verifyStart = Date.now();
// Verify passphrase
const valid = await verifyPassphrase(room, passphrase);
if (!valid) {
return res.status(401).json({ error: 'Invalid passphrase' });
}
const verifyTime = Date.now() - verifyStart;
// Create transcription
const transcription = {
@@ -584,7 +601,12 @@ app.post('/api/send', async (req, res) => {
created_at: Date.now()
};
const addStart = Date.now();
await addTranscription(room, transcription);
const addTime = Date.now() - addStart;
const totalTime = Date.now() - requestStart;
console.log(`[${new Date().toISOString()}] Transcription received: "${text.substring(0, 50)}..." (verify: ${verifyTime}ms, add: ${addTime}ms, total: ${totalTime}ms)`);
res.json({ status: 'ok', message: 'Transcription added' });
} catch (err) {