Ensure logs are reported after 10s max#65
Ensure logs are reported after 10s max#65juliangruber wants to merge 1 commit intofilecoin-saturn:mainfrom
Conversation
hannahhoward
left a comment
There was a problem hiding this comment.
This actually means any infrequently reporting client will send logs immediately, which may not be great for the network (the whole point is to capture bursts of requests as one group)
My recommendation is:
reportLogs (log) {
this.logs.push(log)
if (!this.reportingLogs) return
this.reportLogsTimeout && clearTimeout(this.reportLogsTimeout)
if (!this.logsTimeoutStartedAt) {
this.logsTimeoutStartedAt = new Date()
this.reportLogsTimeout = setTimeout(this._reportLogs.bind(this), 3_000)
} else if (this.logsTimeoutStartedAt.getTime() < new Date().getTime() - 10_000) {
this._reportLogs()
} else {
this.reportLogsTimeout = setTimeout(this._reportLogs.bind(this), 3_000)
}
}
async _reportLogs () {
if (!this.logs.length) {
return
}
try {
const bandwidthLogs = this.hasPerformanceAPI
? this._matchLogsWithPerformanceMetrics(this.logs)
: this.logs
await fetch(
this.config.logURL,
{
method: 'POST',
body: JSON.stringify({ bandwidthLogs, logSender: this.config.logSender })
}
)
this.logsTimeoutStartedAt = null
this.onReportLogs(bandwidthLogs)
} catch (e) {
console.log(e)
throw e
} finally {
this.logs = []
this._clearPerformanceBuffer()
}
}| if (!this.reportingLogs) return | ||
| this.reportLogsTimeout && clearTimeout(this.reportLogsTimeout) | ||
| this.reportLogsTimeout = setTimeout(this._reportLogs.bind(this), 3_000) | ||
| clearTimeout(this.reportLogsTimeout) |
There was a problem hiding this comment.
| clearTimeout(this.reportLogsTimeout) | |
| this.reportLogsTimeout && clearTimeout(this.reportLogsTimeout) |
this.reportLogsTimeout may be null
Isn't this already the case? After inactivity of 3s, logs will be submitted. |
The goal is to debounce since most clients will requests in bursts. So if I make one saturn request, in the same second I'm likely to make 100 saturn request (see all assets on a web page). The 10 second makes as a maximum debounce time, but we don't want to submit just one log at a time. |
The current implementation reports logs after not seeing any new ones for 3s. The Voyager clients creates frequent requests, which can lead to no logs being reported for a whole while. This PR makes it so that logs will be reported after 10s max.