[
https://issues.apache.org/jira/browse/HADOOP-20079?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18141860#comment-18141860
]
ASF GitHub Bot commented on HADOOP-20079:
-----------------------------------------
iatsuk opened a new pull request, #8967:
URL: https://github.com/apache/hadoop/pull/8967
### Description of PR
`SFTPInputStream` overrides only `read()`, so bulk reads use the default
`InputStream.read(byte[], int, int)` and go to JSch one byte at a time. This
method was removed in HADOOP-14566 (seek support).
This PR adds `read(byte[], int, int)` again. It passes the whole buffer to
the JSch stream and updates `pos`, `nextPos` and the statistics in the same way
as `read()`. The arguments are checked with `validatePositionedReadArgs()` like
in `S3AInputStream`. As in `fsdatainputstream.md`, a read with `len == 0`
returns 0, and a read at EOF returns -1.
### How was this patch tested?
- New test `TestSFTPFileSystem#testReadFileInBulk`: reads a 1 MB + 17 bytes
random file with 64 KB bulk reads, checks the data, the position, the result at
EOF, a backward seek with `readFully()` and the `bytesRead` statistic.
- `mvn -pl hadoop-common-project/hadoop-common test
-Dtest='TestSFTPFileSystem,TestSFTPContractSeek'`: 32 tests, no failures.
`TestSFTPContractSeek` is important here, because `readFully()` and positioned
reads now use the new method.
Benchmark: sequential read of a 1 GiB file (from `/dev/urandom`) from a
local OpenSSH sftp server, with `FileSystem.open()` and `IOUtils.copyBytes(in,
OutputStream.nullOutputStream(), 65536, false)`. Corretto 21.0.13, 16 vCPU,
runs were interleaved.
| Build | Run 1 | Run 2 | Run 3 | Mean |
|---|---|---|---|---|
| trunk (28c018cdafe) | 6.0 MB/s | 6.0 MB/s | 6.0 MB/s | 6.0 MB/s |
| this PR | 530.5 MB/s | 554.7 MB/s | 539.7 MB/s | 541.6 MB/s |
The SHA-256 of the data read with the fix is the same as the SHA-256 of the
file.
### For code changes:
- [x] Does the title of this PR start with the corresponding JIRA issue id
(e.g. 'HADOOP-17799. Your PR title ...')?
- [ ] Object storage: Have the integration tests been executed and the
endpoint declared according to the connector-specific documentation? *Not an
object store.*
- [ ] If adding new dependencies to the code, are these dependencies
licensed in a way that is compatible for inclusion under [ASF
2.0](http://www.apache.org/legal/resolved.html#category-a)? *No new
dependencies.*
- [ ] If applicable, have you updated the `LICENSE`, `LICENSE-binary`,
`NOTICE-binary` files? *Not applicable.*
### AI Tooling
If an AI tool was used:
- [x] The PR includes the phrase "Contains content generated by <tool>"
where <tool> is the name of the AI tool used.
- [x] My use of AI contributions follows the ASF legal policy
https://www.apache.org/legal/generative-tooling.html
Contains content generated by Claude. I reviewed all the changes manually.
> SFTPInputStream reads one byte per call: override read(byte[], int, int)
> ------------------------------------------------------------------------
>
> Key: HADOOP-20079
> URL: https://issues.apache.org/jira/browse/HADOOP-20079
> Project: Hadoop Common
> Issue Type: Bug
> Components: fs
> Affects Versions: 3.3.1, 3.3.6, 3.5.0, 3.4.1
> Reporter: Andrei Iatsuk
> Priority: Major
>
> {{SFTPInputStream}} overrides only {{read()}}. It does not override
> {{read(byte[], int, int)}}, so the default implementation from
> {{java.io.InputStream}} is used, and it calls {{read()}} for every byte.
> Because of this, every bulk read from an {{sftp://}} path goes byte by byte:
> {{IOUtils.copyBytes}}, {{readFully}}, positioned reads,
> {{BufferedInputStream}}. For each byte there is a synchronized call, the
> checks for closed stream, EOF and seek, a one-byte read in JSch and a
> statistics update. The read is CPU-bound and very slow, about 6 MB/s on
> localhost. A bigger buffer on the caller side does not help, because all
> wrappers end in the same default method.
> This is a regression from HADOOP-14566. In branch-3.2 {{SFTPInputStream}} had
> {{read(byte[], int, int)}}, which called the JSch stream directly.
> HADOOP-14566 rewrote the class to support seek, and this method was removed.
> So all releases since 3.3.1 have the problem, and trunk too.
> Fix: add {{read(byte[], int, int)}} again. It passes the whole buffer to the
> JSch stream and updates {{pos}}, {{nextPos}} and the statistics in the same
> way as {{read()}}.
> Benchmark: sequential read of a 1 GiB file from a local OpenSSH sftp server,
> with {{FileSystem.open()}} and {{IOUtils.copyBytes()}} with a 64 KB buffer:
> ||Build||Run 1||Run 2||Run 3||Mean||
> |trunk (28c018cdafe)|6.0 MB/s|6.0 MB/s|6.0 MB/s|6.0 MB/s|
> |with fix|530.5 MB/s|554.7 MB/s|539.7 MB/s|541.6 MB/s|
> Corretto 21.0.13, 16 vCPU. Runs were interleaved: before, after, before,
> after, ...
> I will open a PR with the fix and a unit test.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]