A remote storage answers each request a round trip later. Anything that asks one thing, waits, then asks the next is bound by latency × requests, however fast the link. XeFM hides that latency by keeping several requests in flight. It decides how many from what the storage declares, never from its scheme name: XeFM reads the declaration, and a backend an extension adds is treated the same way as the built-in ones (#539, #540, #541).
On PathImpl (xefm/path.py), all Preview in xefm.path_base:
| attribute | meaning | default |
|---|---|---|
CONCURRENCY |
requests the storage serves at once, reads and writes together | 1 |
READ_CONCURRENCY |
how many of those may be reads (a listing is a read) | None: the total |
WRITE_CONCURRENCY |
how many of those may be writes | None: the total |
xefm.path.concurrency(path) reads them as Concurrency(total, read, write).
Read and write are held to the total: declaring more than it has no effect. A
value that is not a count of at least 1 is logged and replaced with the default,
the same warn-and-ignore CAPABILITIES gets. A backend that declares nothing
serves one request at a time, because guessing upwards is the guess that hurts.
LISTING_CONCURRENCY, the Preview attribute this replaces, was the read side
alone. A backend that still sets it gets a warning and its number as
CONCURRENCY.
| backend | total | read | write | why |
|---|---|---|---|---|
local (file) |
8 | 8 | 8 | see Local disk |
| SSH | 64 | 64 | 64 | one SFTP session serves requests side by side; 64 is what OpenSSH’s sftp -R keeps in flight |
| S3 | 16 | 8 | 8 | 16 is the shared client’s pool per host (S3_MAX_POOL_CONNECTIONS); 8 is unmeasured, carried over from the old table |
archive, UriPathImpl, anything else |
1 | 1 | 1 | the default |
Each operation (a copy, a search, a disk-usage scan, a flat view) sizes its own pool from the declarations. Operations do not share a ceiling.
A shared ceiling (one budget per host, which every operation draws from) would honour the declaration exactly. It would also make a task that stops while holding requests block every other task on that storage:
Per-operation ceilings have none of these, because no operation ever waits on
another’s requests. The cost is that two operations on one storage together ask
more than it declared. How many operations run at once is already small: one
foreground task, the one background job holding the queue’s slot, and read-only
tasks (Task.exclusive = False). So the overshoot is bounded at a few times the
declaration, which SFTP absorbs as a longer queue in one session and S3 is far
from throttling at.
Within one operation nothing holds a request while waiting for another: a pool job is one listing, one file read, or one file transfer, and none of them waits on another job. The thread consuming the results holds nothing while it waits for one. That is all it takes to rule out a deadlock inside an operation.
concurrent.futures.ThreadPoolExecutor joins its workers when the
interpreter exits, after they finish every job started or queued. Quitting
XeFM during a content search of a slow SSH host left the process alive after
the window was gone, until every request in flight had come back. The walk and
the content search therefore run on xefm.worker_pool.DaemonPool, whose
threads are daemons like the search dialog’s own worker: their results have
nowhere to go once the app is quitting, and exit does not wait for them. A copy
keeps the executor that finishes what it started.
The walk also keeps no more listings queued in its pool than the pool has workers. The directories it has yet to list wait in the walk, not in the pool, where a file read from the same search would otherwise queue behind every directory of a wide tree.
xefm/tree_walk.pywalk() keeps parallel_reads(root) listings in flight. That is the storage’s
read concurrency where the storage is remote (is_remote()), and 1 where
it is not. Overlapping listings hides round trips, and a local listing has none
to hide: a 9,800-entry tree walked in 0.13 s one directory at a time and 0.42 s
four at once, the pool costing more than the listings. Local walks stay the
depth-first walk they always were.
walk(pool=...) uses a pool the operation already has, for an operation that
also reads files through it. walk(on_error=...) reports a directory that could
not be listed; disk usage counts those.
Every tree walk goes through it: the file-name and content searches, the flat view, and disk usage (#541).
xefm/content_read.pyopen_text() sniffs the encoding from the first
1 KiB and reads on from the same handle, instead of opening the file a
second time as text.parallel_reads(root) workers, so the search as a whole
stays within the storage’s read ceiling. read_ahead() reads small files
(up to 1 MiB) whole on that pool and hands them over in walk order. A
larger file, an empty one, or a PDF or Office file (searched through
document_text) is left for the search to read when it gets there. At most
16 MiB of read-ahead is requested and not yet searched. Stopping or
cancelling drops reads not yet started.transfer_workers() in xefm/file_operations.pyFiles in flight:
TRANSFER_CONCURRENCY overrides the number from step 1, unless that was 1.“Same storage” is the same scheme, so two SSH hosts count as one storage. That can only lower the count, never raise it.
| copy | files in flight |
|---|---|
| local → local | 4 (half of 8) |
| local ⇄ S3, S3 → S3 | 8 |
| local ⇄ SSH | 8 (the disk’s 8) |
| SSH → SSH | 32 (half of 64) |
| extraction to the local disk | 8 (measured the same as 4: 3,000 files, 0.37–0.41 s either way) |
The conflict check before a copy asks whether each destination exists. Into
a remote directory those checks run side by side on parallel_reads(dest_dir)
workers (_existing()). The check asks exists() rather than listing the
directory and matching names, because only the storage knows which names it
treats as the same file (case, Unicode normalisation).
A transfer has to hold only a window of the file, not the whole file, or
several large files in flight become a memory problem. Local ⇄ S3 always
streamed. Local ⇄ SSH streams now too (see
SSH_SYSTEM.md). A download
lands in .<name>.xefm-part beside its destination and replaces it only once
whole, so a transfer that breaks off leaves neither a truncated file nor, when
overwriting, a lost original. Remote ⇄ remote across storage types
(S3 ⇄ SSH) still holds the whole file.
8 comes from a copy between two local paths: four files in flight was the
best (~1.3–1.9x at 2–4 workers on an APFS SSD, worse beyond that, between the
GIL and filesystem metadata serialisation), and each of those files is a read
and a write on the disk. With the other end remote, the disk is not what the
copy waits on. A download from SSH through a 40 ms round trip kept gaining up
to 32 files at once:
| files in flight | 2 | 4 | 8 | 16 | 32 |
|---|---|---|---|---|---|
| 400 × 8 KiB, SSH → local | 40.8 s | 17.5 s | 8.9 s | 5.0 s | 2.4 s |
So a copy between the disk and SSH is capped at 8 by the disk’s declaration, not by anything SSH or the disk runs out of.
The Tart VM’s real sshd (a clone of xefm-demo) was reached through a
userspace delay line adding 20 ms each way. The test data was 259 directories
with 864 files of ~2 KiB each, plus 400 files of 8 KiB.
| before | after | |
|---|---|---|
| disk usage | 22.4 s | 0.68 s |
| content search | 302 s | 3.2 s |
| copy 400 files SSH → local | 80.3 s | 8.9 s |
| copy 400 files local → SSH | 70.4 s | 7.5 s |
A 100 MiB file copied down and back up arrived byte-identical (SHA-256), with no part file left behind.
The same data on a real server, an EC2 host reached through SSM, ~29 ms SFTP round trip:
| before | after | |
|---|---|---|
| disk usage | 19.5 s | 0.61 s |
| content search | 258 s | 3.7 s |
| copy 400 files SSH → local, tags not carried | 67.3 s | 8.9 s |
| copy 400 files SSH → local | 647 s | 140 s |
| copy 400 files local → SSH | 81.0 s | 9.8 s |
A download carries each file’s tags, and reading an SSH file’s tags is an
ssh command of its own (SSHConnection.run_remote), one login per file. Through
SSM that login costs over a second, which is what the two download rows differ
by.
SEARCH_STRATEGY is still declared and still read by nothing; the read-ahead
is gated on is_remote() and the read ceiling instead.test/test_tree_walk.py: overlap, order, cancel, on_error, a shared pool,
the queued listings held to the pool’s size, local walks staying sequential,
and a process quitting mid-walk without waiting for its listings.test/test_content_read.py: one open giving the same text as a second open
(BOMs, line endings), read-ahead order, overlap, byte budget, what is left to
the caller, cancel (also while waiting on a read), the daemon pool, and a
content search over a real sftp-server matching the local one.test/test_disk_usage.py: an SSH tree’s totals match the same local tree’s.test/test_parallel_copy.py: the worker count for each pair of storages, the
override, and an undeclared backend.test/test_path_capabilities.py: validation, the total capping read and
write, and the old LISTING_CONCURRENCY.test/test_ssh_sftp_session.py: streaming larger than the window, local ⇄ SSH
copies, and a failed download keeping the file it would replace.