dx42 / MockFtpServer

Apache License 2.0
14 stars 3 forks source link

DefaultSession.readData is "slow" #17

Closed fabio-boldrini closed 1 year ago

fabio-boldrini commented 2 years ago

Hello,

This is not an issue, but more a possible improvment.

I'm using MockFtpServer successfully for my tests, but on one test I noticed it was really slow (comparing it with an implementation that not use ftp but use local files).

In started to look if my implementation using ftp client was "bad", and then I started to see that the slow part was uploading file to the ftp.

I looked on StorCommandHandler, and then on DefaultSession.readData() and then on DefaultSession.readData(int numBytes).

Here the InputStream is read using the read() method. I'm no expert on InputStream stuff, but debugging the method I saw that the read() returned few byte at each loop... and that seem suspicious.

I tried to switch to Guava ByteStreams.toByteArray() method and my test elapsed time went from 30s to 5s.

I'm not arguing about using Guava in your project (it will be another dependency) but there are probable other plain java solution to make that code faster.

On my project, I resolved replacing StorCommandHandler with a custom one that read the data with guava (with some reflection/nasty stuff.. but it's ok)

chrismair commented 2 years ago

Yeah, it is probably reasonable to use a BufferedInputStream or some other optimization there.

chrismair commented 1 year ago

Available in MockFtpServer version 3.1.0