[ 
https://issues.apache.org/jira/browse/SSHD-1217?focusedWorklogId=670814&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-670814
 ]

ASF GitHub Bot logged work on SSHD-1217:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 27/Oct/21 15:29
            Start Date: 27/Oct/21 15:29
    Worklog Time Spent: 10m 
      Work Description: lgoldstein commented on a change in pull request #206:
URL: https://github.com/apache/mina-sshd/pull/206#discussion_r737584656



##########
File path: 
sshd-sftp/src/main/java/org/apache/sshd/sftp/server/RemoteDirectoryHandle.java
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.sftp.server;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.apache.sshd.sftp.client.SftpClient;
+import org.apache.sshd.sftp.client.SftpClient.DirEntry;
+import org.apache.sshd.sftp.client.fs.SftpPath;
+import org.apache.sshd.sftp.client.impl.SftpIterableDirEntry;
+
+public class RemoteDirectoryHandle extends Handle implements 
Iterator<SftpClient.DirEntry> {
+
+    private final SftpIterableDirEntry entries;
+
+    private Iterator<SftpClient.DirEntry> iterator;
+
+    private boolean atStart = true;
+
+    private boolean done;
+
+    protected RemoteDirectoryHandle(SftpSubsystem subsystem, SftpPath file, 
String handle) throws IOException {
+        super(subsystem, file, handle);
+        entries = new SftpIterableDirEntry(file.getFileSystem().getClient(), 
file.toString());
+    }
+
+    public boolean atStart() {

Review comment:
       I recommend using `isAtStart()` to conform with Java beans conventions 
(even though this is not a bean...)

##########
File path: 
sshd-sftp/src/main/java/org/apache/sshd/sftp/server/RemoteDirectoryHandle.java
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.sftp.server;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.apache.sshd.sftp.client.SftpClient;
+import org.apache.sshd.sftp.client.SftpClient.DirEntry;
+import org.apache.sshd.sftp.client.fs.SftpPath;
+import org.apache.sshd.sftp.client.impl.SftpIterableDirEntry;
+
+public class RemoteDirectoryHandle extends Handle implements 
Iterator<SftpClient.DirEntry> {
+
+    private final SftpIterableDirEntry entries;
+
+    private Iterator<SftpClient.DirEntry> iterator;
+
+    private boolean atStart = true;
+
+    private boolean done;
+
+    protected RemoteDirectoryHandle(SftpSubsystem subsystem, SftpPath file, 
String handle) throws IOException {
+        super(subsystem, file, handle);
+        entries = new SftpIterableDirEntry(file.getFileSystem().getClient(), 
file.toString());
+    }
+
+    public boolean atStart() {
+        return atStart;
+    }
+
+    @Override
+    public boolean hasNext() {
+        if (done) {
+            return false;
+        }
+        if (iterator == null) {
+            iterator = entries.iterator();
+        }
+        done = !iterator.hasNext();
+        return !done;
+    }
+
+    @Override
+    public DirEntry next() {
+        if (!hasNext()) {
+            throw new NoSuchElementException();

Review comment:
       Recommend adding some informative text to the exception - e.g., `"No 
more entries to iterate for " + getPath()` so that if it occurs the user will 
know what directory was being iterated

##########
File path: 
sshd-sftp/src/main/java/org/apache/sshd/sftp/server/RemoteDirectoryHandle.java
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.sftp.server;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.apache.sshd.sftp.client.SftpClient;
+import org.apache.sshd.sftp.client.SftpClient.DirEntry;
+import org.apache.sshd.sftp.client.fs.SftpPath;
+import org.apache.sshd.sftp.client.impl.SftpIterableDirEntry;
+
+public class RemoteDirectoryHandle extends Handle implements 
Iterator<SftpClient.DirEntry> {
+
+    private final SftpIterableDirEntry entries;
+
+    private Iterator<SftpClient.DirEntry> iterator;
+
+    private boolean atStart = true;
+
+    private boolean done;
+
+    protected RemoteDirectoryHandle(SftpSubsystem subsystem, SftpPath file, 
String handle) throws IOException {
+        super(subsystem, file, handle);
+        entries = new SftpIterableDirEntry(file.getFileSystem().getClient(), 
file.toString());
+    }
+
+    public boolean atStart() {
+        return atStart;
+    }
+
+    @Override
+    public boolean hasNext() {
+        if (done) {
+            return false;
+        }
+        if (iterator == null) {
+            iterator = entries.iterator();
+        }
+        done = !iterator.hasNext();
+        return !done;
+    }
+
+    @Override
+    public DirEntry next() {
+        if (!hasNext()) {
+            throw new NoSuchElementException();
+        }
+        atStart = false;
+        return iterator.next();
+    }
+
+    @Override
+    public void close() throws IOException {
+        super.close();

Review comment:
       What if `super.close()` throws an exception ? the code after it will not 
be executed. Perhaps better:
   ```java
   try {
       super.close();
   } finally {
       ... the rest of the code ...
   }
   ```

##########
File path: 
sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpEventListener.java
##########
@@ -155,6 +155,21 @@ default void readingEntries(
         // ignored
     }
 
+    /**
+     * About to read entries from a remote directory - <B>Note:</B> might not 
be the 1st time it is called for the
+     * directory in case several iterations are required in order to go 
through all the entries in the directory
+     *
+     * @param  session      The {@link ServerSession} through which the 
request was handled
+     * @param  remoteHandle The (opaque) assigned handle for the directory
+     * @param  localHandle  The associated {@link RemoteDirectoryHandle}
+     * @throws IOException  If failed to handle the call
+     * @see                 #readEntries(ServerSession, String, 
RemoteDirectoryHandle, Map) readEntries
+     */
+    default void readingEntries(ServerSession session, String remoteHandle, 
RemoteDirectoryHandle localHandle)

Review comment:
       I think that overloading the method is not a good idea - let's rename 
this `readingRemoteEntries`

##########
File path: 
sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpEventListener.java
##########
@@ -172,6 +187,24 @@ default void readEntries(
         // ignored
     }
 
+    /**
+     * Result of reading entries from a remote directory - <B>Note:</B> it may 
be a <U>partial</U> result if the
+     * directory contains more entries than can be accommodated in the response
+     *
+     * @param  session      The {@link ServerSession} through which the 
request was handled
+     * @param  remoteHandle The (opaque) assigned handle for the directory
+     * @param  localHandle  The associated {@link RemoteDirectoryHandle}
+     * @param  entries      A {@link Map} of the listed entries - key = short 
name, value = {@link Path} of the
+     *                      sub-entry
+     * @throws IOException  If failed to handle the call
+     */
+    default void readEntries(

Review comment:
       I think that overloading the method is not a good idea - let's rename 
this `readRemoteEntries`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 670814)
    Time Spent: 20m  (was: 10m)

> Slow performance listing huge number of files on Apache SSHD server
> -------------------------------------------------------------------
>
>                 Key: SSHD-1217
>                 URL: https://issues.apache.org/jira/browse/SSHD-1217
>             Project: MINA SSHD
>          Issue Type: Improvement
>    Affects Versions: 2.6.0
>            Reporter: Roberto Deandrea
>            Assignee: Thomas Wolf
>            Priority: Minor
>         Attachments: trace.ssh-frontend-sftplist.finest.log.zip
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Hi Thomas,
> I noted slow performance listing files on the front-end Apache SSHD server in 
> the same scenario as https://issues.apache.org/jira/browse/SSHD-1215
> The front-end Apache SSHD server is configured with a Filesystem built upon 
> SFTPFileSystemProvider to proxy files to an Apache SSHD back-end server.
>  
> In the /inbox folder of the Apache SSHD backend server I have 2000 files.
> The client sftp ls  commands take 2 secs on the backend Apache SSHD server, 
> instead it takes about 48 secs on the front-end Apache SSHD server.
> For greater number of files in the /inbox folder times are getting worse.
>  
> I have full traces of  sftp list commands to front-end Apache SSHD server 
> that is attached to this jira.[^trace.frontend.sshd.log.zip]
> I looked through the traces on the front-end server and it seems to me that 
> for every files in the folder the sftp client on the front-end server creates 
> a SSH_MSG_CHANNEL_DATA generating tcp traffic that slow down the performance 
> of the list command.
> Obviously this does not happen when a sftp client connects directly to the 
> backend Apache SSHD server.
> Can you take a look at traces on the front-end Apache SSHD server   ?
> Do you think it's possbile change something to improve performance of list 
> files in this situation ?
>  
> Thanks in advance
>  
> Kind Regards
> Roberto
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to