mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-24 19:42:04 +00:00
b456ea726d
* wip generate directory for hash content * cleanup, remove console logging * add content caching module * Return PDF stream ranges with compile response * Return the PDF file size in the compile response * PDF range endpoint * [misc] WIP: pdf caching: preserve the m-time on static content files * [misc] WIP: pdf caching: improve browser caching, emit caching headers * [misc] WIP: pdf caching: do not emit very small chunks <1kB * [misc] keep up with moving output files into a separate directory * [OutputCacheManager] add global feature flag for enabling pdf caching * [misc] add contentId into the URL for protecting PDF stream contents * [misc] support PDF stream caching for anonymous users * [misc] add per-request feature flag for enabling PDF stream caching * [misc] enable pdf caching in CI and emit metrics at the end of run * [misc] expose compile stats and timings to the frontend * [misc] log an error in case saving output files fails * [misc] add metrics for pdf bandwidth and pdf caching performance * [misc] add a dark mode to the pdf caching for computing ranges only * [misc] move pdf caching metrics into ContentCacheMetrics * [misc] add a config option for the min chunk size of pdf ranges Co-authored-by: Brian Gough <brian.gough@overleaf.com> Co-authored-by: Eric Mc Sween <eric.mcsween@overleaf.com>
80 lines
2.5 KiB
JavaScript
80 lines
2.5 KiB
JavaScript
const Metrics = require('./Metrics')
|
|
|
|
const ONE_MB = 1024 * 1024
|
|
|
|
function emitPdfStats(stats, timings) {
|
|
if (timings['compute-pdf-caching']) {
|
|
emitPdfCachingStats(stats, timings)
|
|
} else {
|
|
// How much bandwidth will the pdf incur when downloaded in full?
|
|
Metrics.summary('pdf-bandwidth', stats['pdf-size'])
|
|
}
|
|
}
|
|
|
|
function emitPdfCachingStats(stats, timings) {
|
|
if (!stats['pdf-size']) return // double check
|
|
|
|
// How large is the overhead of hashing up-front?
|
|
const fraction =
|
|
timings.compileE2E - timings['compute-pdf-caching'] !== 0
|
|
? timings.compileE2E /
|
|
(timings.compileE2E - timings['compute-pdf-caching'])
|
|
: 1
|
|
Metrics.summary('overhead-compute-pdf-ranges', fraction * 100 - 100)
|
|
|
|
// How does the hashing scale to pdf size in MB?
|
|
Metrics.timing(
|
|
'compute-pdf-caching-relative-to-pdf-size',
|
|
timings['compute-pdf-caching'] / (stats['pdf-size'] / ONE_MB)
|
|
)
|
|
if (stats['pdf-caching-total-ranges-size']) {
|
|
// How does the hashing scale to total ranges size in MB?
|
|
Metrics.timing(
|
|
'compute-pdf-caching-relative-to-total-ranges-size',
|
|
timings['compute-pdf-caching'] /
|
|
(stats['pdf-caching-total-ranges-size'] / ONE_MB)
|
|
)
|
|
// How fast is the hashing per range on average?
|
|
Metrics.timing(
|
|
'compute-pdf-caching-relative-to-ranges-count',
|
|
timings['compute-pdf-caching'] / stats['pdf-caching-n-ranges']
|
|
)
|
|
|
|
// How many ranges are new?
|
|
Metrics.summary(
|
|
'new-pdf-ranges-relative-to-total-ranges',
|
|
(stats['pdf-caching-n-new-ranges'] / stats['pdf-caching-n-ranges']) * 100
|
|
)
|
|
}
|
|
|
|
// How much content is cacheable?
|
|
Metrics.summary(
|
|
'cacheable-ranges-to-pdf-size',
|
|
(stats['pdf-caching-total-ranges-size'] / stats['pdf-size']) * 100
|
|
)
|
|
|
|
const sizeWhenDownloadedInFull =
|
|
// All of the pdf
|
|
stats['pdf-size'] -
|
|
// These ranges are potentially cached.
|
|
stats['pdf-caching-total-ranges-size'] +
|
|
// These ranges are not cached.
|
|
stats['pdf-caching-new-ranges-size']
|
|
|
|
// How much bandwidth can we save when downloading the pdf in full?
|
|
Metrics.summary(
|
|
'pdf-bandwidth-savings',
|
|
100 - (sizeWhenDownloadedInFull / stats['pdf-size']) * 100
|
|
)
|
|
|
|
// How much bandwidth will the pdf incur when downloaded in full?
|
|
Metrics.summary('pdf-bandwidth', sizeWhenDownloadedInFull)
|
|
|
|
// How much space do the ranges use?
|
|
// This will accumulate the ranges size over time, skipping already written ranges.
|
|
Metrics.summary('pdf-ranges-disk-size', stats['pdf-caching-new-ranges-size'])
|
|
}
|
|
|
|
module.exports = {
|
|
emitPdfStats
|
|
}
|