-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnyamesh-stress-test-v2.html
More file actions
498 lines (427 loc) · 18.1 KB
/
Copy pathnyamesh-stress-test-v2.html
File metadata and controls
498 lines (427 loc) · 18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🔥 NyaMesh v2 負荷テスト - Intent駆動P2P版</title>
<style>
body {
font-family: 'Courier New', monospace;
background: #0a0a0a;
color: #00ff00;
margin: 0;
padding: 20px;
}
.container {
max-width: 1400px;
margin: 0 auto;
}
.header {
text-align: center;
border-bottom: 2px solid #00ff00;
padding-bottom: 20px;
margin-bottom: 20px;
}
.control-panel {
display: flex;
justify-content: center;
gap: 20px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.control-group {
background: #1a1a1a;
border: 1px solid #00ff00;
padding: 15px;
border-radius: 5px;
}
.test-button {
background: #003300;
color: #00ff00;
border: 1px solid #00ff00;
padding: 10px 20px;
margin: 5px;
cursor: pointer;
font-family: inherit;
font-size: 14px;
min-width: 120px;
}
.test-button:hover {
background: #005500;
}
.test-button:disabled {
background: #222;
color: #666;
cursor: not-allowed;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin-bottom: 20px;
}
.stats-panel {
background: #1a1a1a;
border: 1px solid #00ff00;
padding: 15px;
border-radius: 5px;
}
.stats-panel h3 {
margin-top: 0;
color: #44ff44;
border-bottom: 1px solid #00ff00;
padding-bottom: 10px;
}
.stat-row {
display: flex;
justify-content: space-between;
margin: 5px 0;
}
.stat-value {
color: #ffff00;
font-weight: bold;
}
.log-panel {
background: #1a1a1a;
border: 1px solid #00ff00;
padding: 15px;
height: 300px;
overflow-y: auto;
font-size: 12px;
border-radius: 5px;
margin-top: 20px;
}
.log-entry {
margin: 2px 0;
padding: 1px 0;
}
.log-info { color: #00ff00; }
.log-warn { color: #ffaa00; }
.log-error { color: #ff4444; }
.log-success { color: #44ff44; }
.log-perf { color: #00ffff; }
input[type="number"] {
background: #222;
color: #00ff00;
border: 1px solid #00ff00;
padding: 5px;
width: 100px;
font-family: inherit;
}
.progress-bar {
background: #222;
border: 1px solid #00ff00;
height: 20px;
margin: 10px 0;
position: relative;
}
.progress-fill {
background: #00ff00;
height: 100%;
width: 0%;
transition: width 0.3s;
}
.progress-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #000;
font-weight: bold;
mix-blend-mode: difference;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔥 NyaMesh 負荷テスト</h1>
<p>並列処理対応・高速シャットダウン実装</p>
</div>
<div class="control-panel">
<div class="control-group">
<h3>🎯 テスト設定</h3>
<div>
メッシュ数: <input type="number" id="meshCount" value="1000" min="1" max="100000">
</div>
<div>
バッチサイズ: <input type="number" id="batchSize" value="100" min="1" max="1000">
</div>
</div>
<div class="control-group">
<h3>🚀 テスト実行</h3>
<button class="test-button" id="createTest" onclick="runCreateTest()">作成テスト</button>
<button class="test-button" id="shutdownTest" onclick="runShutdownTest()">削除テスト</button>
<button class="test-button" id="fullTest" onclick="runFullTest()">フルテスト</button>
<button class="test-button" id="clearAll" onclick="clearAll()">全クリア</button>
</div>
</div>
<div class="progress-bar" id="progressBar" style="display: none;">
<div class="progress-fill" id="progressFill"></div>
<div class="progress-text" id="progressText">0%</div>
</div>
<div class="stats-grid">
<div class="stats-panel">
<h3>📊 作成統計</h3>
<div class="stat-row">
<span>総メッシュ数:</span>
<span class="stat-value" id="totalMeshes">0</span>
</div>
<div class="stat-row">
<span>作成時間:</span>
<span class="stat-value" id="createTime">-</span>
</div>
<div class="stat-row">
<span>作成速度:</span>
<span class="stat-value" id="createRate">-</span>
</div>
<div class="stat-row">
<span>メモリ使用:</span>
<span class="stat-value" id="memoryUsage">-</span>
</div>
</div>
<div class="stats-panel">
<h3>🗑️ 削除統計</h3>
<div class="stat-row">
<span>削除済み:</span>
<span class="stat-value" id="deletedMeshes">0</span>
</div>
<div class="stat-row">
<span>削除時間:</span>
<span class="stat-value" id="deleteTime">-</span>
</div>
<div class="stat-row">
<span>削除速度:</span>
<span class="stat-value" id="deleteRate">-</span>
</div>
<div class="stat-row">
<span>並列度:</span>
<span class="stat-value" id="parallelism">-</span>
</div>
</div>
<div class="stats-panel">
<h3>⚡ パフォーマンス</h3>
<div class="stat-row">
<span>CPU時間:</span>
<span class="stat-value" id="cpuTime">-</span>
</div>
<div class="stat-row">
<span>実時間:</span>
<span class="stat-value" id="wallTime">-</span>
</div>
<div class="stat-row">
<span>効率性:</span>
<span class="stat-value" id="efficiency">-</span>
</div>
<div class="stat-row">
<span>スループット:</span>
<span class="stat-value" id="throughput">-</span>
</div>
</div>
</div>
<div class="log-panel" id="logPanel">
<div class="log-entry log-info">🔥 NyaMesh負荷テストシステム準備完了</div>
<div class="log-entry log-info">🎯 並列処理対応・高速シャットダウン実装済み</div>
</div>
</div>
<script type="module">
import { NyaMesh } from '../src/nyamesh.js'
let meshes = []
let isRunning = false
function log(message, type = 'info') {
const timestamp = new Date().toLocaleTimeString()
const logPanel = document.getElementById('logPanel')
const entry = document.createElement('div')
entry.className = `log-entry log-${type}`
entry.textContent = `[${timestamp}] ${message}`
logPanel.appendChild(entry)
logPanel.scrollTop = logPanel.scrollHeight
console.log(message)
}
function updateStat(id, value) {
const element = document.getElementById(id)
if (element) {
element.textContent = value
}
}
function updateProgress(current, total) {
const percent = Math.round((current / total) * 100)
document.getElementById('progressFill').style.width = percent + '%'
document.getElementById('progressText').textContent = `${percent}% (${current}/${total})`
}
function showProgress() {
document.getElementById('progressBar').style.display = 'block'
}
function hideProgress() {
document.getElementById('progressBar').style.display = 'none'
}
function setButtonsEnabled(enabled) {
document.getElementById('createTest').disabled = !enabled
document.getElementById('shutdownTest').disabled = !enabled
document.getElementById('fullTest').disabled = !enabled
document.getElementById('clearAll').disabled = !enabled
}
function formatTime(ms) {
if (ms < 1000) return `${ms.toFixed(2)}ms`
if (ms < 60000) return `${(ms / 1000).toFixed(2)}秒`
return `${(ms / 60000).toFixed(2)}分`
}
function formatRate(count, timeMs) {
const perSecond = (count / timeMs) * 1000
if (perSecond > 1000000) return `${(perSecond / 1000000).toFixed(2)}M/秒`
if (perSecond > 1000) return `${(perSecond / 1000).toFixed(2)}K/秒`
return `${perSecond.toFixed(2)}/秒`
}
function getMemoryUsage() {
if (performance.memory) {
const mb = performance.memory.usedJSHeapSize / 1024 / 1024
return `${mb.toFixed(2)} MB`
}
return 'N/A'
}
window.runCreateTest = async () => {
if (isRunning) return
isRunning = true
setButtonsEnabled(false)
const count = parseInt(document.getElementById('meshCount').value)
const batchSize = parseInt(document.getElementById('batchSize').value)
log(`🚀 作成テスト開始: ${count}個のメッシュを作成`, 'info')
showProgress()
updateProgress(0, count)
meshes = []
const startTime = performance.now()
const startMemory = performance.memory?.usedJSHeapSize || 0
try {
// バッチ処理で高速作成
for (let i = 0; i < count; i += batchSize) {
const batchPromises = []
const currentBatchSize = Math.min(batchSize, count - i)
for (let j = 0; j < currentBatchSize; j++) {
const meshIndex = i + j
batchPromises.push(
new Promise((resolve) => {
const mesh = new NyaMesh(null, {
name: `Mesh-${meshIndex}`,
debug: false,
enableBroadcast: false
})
meshes.push(mesh)
resolve(mesh)
})
)
}
await Promise.all(batchPromises)
updateProgress(i + currentBatchSize, count)
updateStat('totalMeshes', i + currentBatchSize)
// UIを更新するため少し待機
if (i % (batchSize * 10) === 0) {
await new Promise(resolve => setTimeout(resolve, 0))
}
}
const endTime = performance.now()
const duration = endTime - startTime
const endMemory = performance.memory?.usedJSHeapSize || 0
const memoryDelta = (endMemory - startMemory) / 1024 / 1024
updateStat('createTime', formatTime(duration))
updateStat('createRate', formatRate(count, duration))
updateStat('memoryUsage', `+${memoryDelta.toFixed(2)} MB`)
log(`✅ 作成完了: ${count}個を${formatTime(duration)}で作成`, 'success')
log(`📊 作成速度: ${formatRate(count, duration)}`, 'perf')
} catch (error) {
log(`❌ 作成エラー: ${error.message}`, 'error')
} finally {
hideProgress()
isRunning = false
setButtonsEnabled(true)
}
}
window.runShutdownTest = async () => {
if (isRunning || meshes.length === 0) return
isRunning = true
setButtonsEnabled(false)
const count = meshes.length
log(`🗑️ 削除テスト開始: ${count}個のメッシュを並列削除`, 'info')
showProgress()
updateProgress(0, count)
const startTime = performance.now()
let deletedCount = 0
try {
// 並列シャットダウン実装
const parallelSize = Math.min(100, count) // 最大100並列
const batches = []
for (let i = 0; i < count; i += parallelSize) {
const batch = meshes.slice(i, Math.min(i + parallelSize, count))
batches.push(batch)
}
updateStat('parallelism', parallelSize)
for (const batch of batches) {
// バッチ内は並列処理
const shutdownPromises = batch.map(mesh =>
mesh.shutdown().then(() => {
deletedCount++
updateStat('deletedMeshes', deletedCount)
})
)
await Promise.all(shutdownPromises)
updateProgress(deletedCount, count)
// UIを更新
await new Promise(resolve => setTimeout(resolve, 0))
}
const endTime = performance.now()
const duration = endTime - startTime
updateStat('deleteTime', formatTime(duration))
updateStat('deleteRate', formatRate(count, duration))
log(`✅ 削除完了: ${count}個を${formatTime(duration)}で削除`, 'success')
log(`📊 削除速度: ${formatRate(count, duration)}`, 'perf')
log(`⚡ 並列度: ${parallelSize}`, 'perf')
meshes = []
updateStat('totalMeshes', 0)
} catch (error) {
log(`❌ 削除エラー: ${error.message}`, 'error')
} finally {
hideProgress()
isRunning = false
setButtonsEnabled(true)
}
}
window.runFullTest = async () => {
log('🎯 フルテスト開始: 作成→削除を連続実行', 'info')
await runCreateTest()
await new Promise(resolve => setTimeout(resolve, 1000)) // 1秒待機
await runShutdownTest()
log('🎉 フルテスト完了', 'success')
}
window.clearAll = async () => {
if (isRunning) return
isRunning = true
setButtonsEnabled(false)
log('🧹 全メッシュクリア中...', 'warn')
try {
if (meshes.length > 0) {
const clearPromises = meshes.map(mesh =>
mesh.shutdown().catch(err => console.error(err))
)
await Promise.all(clearPromises)
}
meshes = []
updateStat('totalMeshes', 0)
updateStat('deletedMeshes', 0)
log('✅ クリア完了', 'success')
} catch (error) {
log(`❌ クリアエラー: ${error.message}`, 'error')
} finally {
isRunning = false
setButtonsEnabled(true)
}
}
// パフォーマンスモニター
setInterval(() => {
if (meshes.length > 0) {
updateStat('memoryUsage', getMemoryUsage())
}
}, 1000)
log('🎉 負荷テストシステム初期化完了', 'success')
log('💡 ヒント: バッチサイズを調整してパフォーマンスを最適化できるにゃ!')
</script>
</body>
</html>