Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sftp upload performance deterioration after update to 2.10.0 #407

Closed
lzzcg opened this issue Aug 26, 2023 · 0 comments · Fixed by #408
Closed

sftp upload performance deterioration after update to 2.10.0 #407

lzzcg opened this issue Aug 26, 2023 · 0 comments · Fixed by #408
Assignees
Labels
bug An issue describing a bug in the code
Milestone

Comments

@lzzcg
Copy link

lzzcg commented Aug 26, 2023

Version

2.10.0

Bug description

at org.apache.sshd.sftp.client.fs.SftpFileSystemProvider#newOutputStream method, SftpOutputStreamAsync is decorated by FilterOutputStream.

the java.io.FilterOutputStream#write(byte[], int, int) method will invoke the org.apache.sshd.sftp.client.impl.SftpOutputStreamAsync#write(int) method each byte in a loop, this cause the buffer in SftpOutputStreamAsync is Invalidation。

Actual behavior

at org.apache.sshd.sftp.client.fs.SftpFileSystemProvider#newOutputStream method, SftpOutputStreamAsync is decorated by FilterOutputStream.

the java.io.FilterOutputStream#write(byte[], int, int) method will invoke the org.apache.sshd.sftp.client.impl.SftpOutputStreamAsync#write(int) method each byte in a loop, this cause the buffer in SftpOutputStreamAsync is Invalidation。

Expected behavior

override the java.io.FilterOutputStream#write(byte[], int, int) method in org.apache.sshd.sftp.client.fs.SftpFileSystemProvider#newOutputStream like below:

return new FilterOutputStream(client.write(p.toString(), modes)) {

                        @Override
                        public void close() throws IOException {
                            try {
                                super.close();
                            } finally {
                                client.close();
                            }
                        }

                        @Override
                        public void write(byte b[], int off, int len) throws IOException {
                            if ((off | len | (b.length - (len + off)) | (off + len)) < 0) {
                                throw new IndexOutOfBoundsException();
                            }
                            out.write(b, off, len);
                        }
                    };

Relevant log output

No response

Other information

No response

@tomaswolf tomaswolf added this to the 2.10.1 milestone Aug 26, 2023
@tomaswolf tomaswolf added the bug An issue describing a bug in the code label Aug 26, 2023
@tomaswolf tomaswolf self-assigned this Aug 26, 2023
tomaswolf added a commit to tomaswolf/mina-sshd that referenced this issue Aug 26, 2023
The default implementation calls write(int) for every byte, which may
be very inefficient. Override it in the few cases where we use a
FilterOutputStream to pass through the operation to the underlying
OutputStream, which is also responsible for any index and length
validations.

Bug: apache#407
tomaswolf added a commit to tomaswolf/mina-sshd that referenced this issue Aug 26, 2023
The default implementation calls write(int) for every byte, which may
be very inefficient. Override it in the few cases where we use a
FilterOutputStream to pass through the operation to the underlying
OutputStream, which is also responsible for any index and length
validations.

Bug: apache#407
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue describing a bug in the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants