From 2c4b4ab928df3bc316b783988a7fd0acd53c9196 Mon Sep 17 00:00:00 2001
From: ed
Date: Wed, 21 Apr 2021 18:39:55 +0200
Subject: [PATCH] up2k-cli: cond. readahead
---
copyparty/web/up2k.js | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js
index 6c3a2f93..9bb5be1e 100644
--- a/copyparty/web/up2k.js
+++ b/copyparty/web/up2k.js
@@ -491,6 +491,7 @@ function up2k_init(have_crypto) {
var ask_up = bcfg_get('ask_up', true);
var flag_en = bcfg_get('flag_en', false);
var fsearch = bcfg_get('fsearch', false);
+ var min_filebuf = 0;
var fdom_ctr = 0;
var st = {
@@ -936,13 +937,14 @@ function up2k_init(have_crypto) {
pvis.move(t.n, 'bz');
var segm_next = function () {
- if (nchunk >= nchunks || (bpend > chunksize && bpend >= 32 * 1024 * 1024))
+ if (nchunk >= nchunks || (bpend > chunksize && bpend >= min_filebuf))
return false;
var reader = new FileReader(),
nch = nchunk++,
car = nch * chunksize,
- cdr = car + chunksize;
+ cdr = car + chunksize,
+ t0 = new Date().getTime();
if (cdr >= t.size)
cdr = t.size;
@@ -950,6 +952,14 @@ function up2k_init(have_crypto) {
bpend += cdr - car;
reader.onload = function (e) {
+ if (!min_filebuf && nch == 1) {
+ min_filebuf = 1;
+ var td = (new Date().getTime()) - t0;
+ if (td > 50) {
+ ebi('u2foot').innerHTML += "
excessive filereader latency (" + td + " ms), increasing readahead
"; + min_filebuf = 32 * 1024 * 1024; + } + } hash_calc(nch, e.target.result); }; reader.onerror = segm_err;