Imrpove upload speed by spam sending

This commit is contained in:
Niklas Jensen
2026-02-21 15:24:00 +01:00
parent c9a5b6c2fc
commit 0ee459b1a7
2 changed files with 10 additions and 27 deletions
+4 -6
View File
@@ -343,8 +343,7 @@ export class FileSystemClient {
this.activeUploads.set(transferId, upload)
// Stream chunks one at a time, waiting for each to be sent
;(async () => {
// Stream all chunks without waiting for ACKs
for (let chunkIndex = 0; chunkIndex < totalChunks; chunkIndex++) {
const offset = chunkIndex * chunkSize
const end = Math.min(offset + chunkSize, fileSize)
@@ -356,12 +355,12 @@ export class FileSystemClient {
data: chunkData
}
// Wait for chunk to be sent before continuing
await socket.emit(FSMessages.FSUploadData, uploadData)
// Send chunk as fire-and-forget message
socket.emit(FSMessages.FSUploadData, uploadData)
upload.chunksSent++
// Report progress after chunk is actually sent
// Report progress
if (onProgress) {
onProgress({
transferId,
@@ -376,7 +375,6 @@ export class FileSystemClient {
// All chunks sent - now wait for completion message from server
// The timeout will handle if server doesn't respond
})()
})
}
+6 -21
View File
@@ -198,27 +198,12 @@ function createWebSocket() {
unresponsiveTimeoutId = setTimeout(() => disconnect('unresponsive'), reconnectTimeoutTime)
}
function emit<T>(event: MessageFns<T>, data: T): Promise<void> {
return new Promise((resolve) => {
if (!ws || ws.readyState !== WebSocket.OPEN) {
resolve()
return
}
const type = getNameFromMessageType(event)
const wsm = Message.create() as Record<string, unknown>
wsm[type] = data
send(wsm as Message)
// Wait for buffer to flush before resolving
const checkBuffer = () => {
if (!ws || ws.bufferedAmount === 0) {
resolve()
} else {
setTimeout(checkBuffer, 5)
}
}
checkBuffer()
})
function emit<T>(event: MessageFns<T>, data: T) {
if (!ws || ws.readyState !== WebSocket.OPEN) return
const type = getNameFromMessageType(event)
const wsm = Message.create() as Record<string, unknown>
wsm[type] = data
send(wsm as Message)
}
function unsubscribeToMessageFromServer<T>(event_type: MessageFns<T>) {