ftpd icon indicating copy to clipboard operation
ftpd copied to clipboard

CPU usage pegged at 100%

Open pcbeard opened this issue 7 years ago • 9 comments

Using bin/ftpdrb on macOS with ruby 1.4, Activity Monitor shows ruby using 6 threads and 100% of a CPU. Is the server doing a lot of polling? In my configuration, there are 3 active server connections that are otherwise idle most of the time.

pcbeard avatar Jun 25 '17 15:06 pcbeard

No polling. Ffpd runs one listener thread and then one thread per connection. All IO is supposed to be blocking but what you are seeing makes me wonder.

On Jun 25, 2017 08:47, "pcbeard" [email protected] wrote:

Using bin/ftpdrb on macOS with ruby 1.4, Activity Monitor shows ruby using 6 threads and 100% of a CPU. Is the server doing a lot of polling?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/wconrad/ftpd/issues/47, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2JiA6biP4atwrp-Bk_EqSWJDXgTsbRks5sHoD6gaJpZM4OEpDU .

wconrad avatar Jun 25 '17 18:06 wconrad

Even w/o any connections, simply starting the server by running bin/fptdrb, here's what top shows:

PID    COMMAND      %CPU TIME     #TH   COW     #PORT MEM    PURG   CMPRS  STATE    UID  #WQ  BOOSTS                %CPU_ME
17058  ruby         94.2 02:02.52 3/1   237     24    8960K  0B     0B     running  5322 0    *0[1]                 0.00000

pcbeard avatar Jun 26 '17 00:06 pcbeard

The problem was a busy-loop in bin/ftpdrb. I can't release a new gem right now--something in my test/release setup for ftpd has gone wrong, and I can't troubleshoot it right now.

wconrad avatar Jun 26 '17 03:06 wconrad

Yes, I just confirmed that too. Here:

    def run
      puts "FTP server started. (Press CRL+C to stop it)"
      connection_info.each do |key, value|
        puts "#{key}: #{value}"
      end
      $stdout.flush
      begin
        loop{}
      rescue Interrupt
        puts "\nClosing FTP server..."
      end
    end

What's your proposed fix? I think the easiest would be to simply change that loop to a call to the server thread's join method.

pcbeard avatar Jun 26 '17 03:06 pcbeard

Added a pull request.

pcbeard avatar Jun 26 '17 04:06 pcbeard

I think your fix is fine. I'll probably back out my fix and accept your PR after I get some of ftpd's housekeeping taken care of.

wconrad avatar Jul 16 '17 19:07 wconrad

I've released a new version of the gem which includes my fix for this issue. Leaving this issue open tor remind me to replace it with your fix.

wconrad avatar Jul 17 '17 23:07 wconrad

Did you ever consider my fix?

pcbeard avatar Sep 13 '21 15:09 pcbeard

@pcbeard I would love to use your fix. I haven't pulled it in because my upkeep of ftpd stopped when recent versions of Ruby broke the double-bag-ftps gem that ftpd uses for ftps support, and I don't know what the fix for that is. I suppose I could officially not support more recent Ruby versions, but that bothers me.

wconrad avatar Sep 13 '21 15:09 wconrad