In one of my rails apps, the console has started running really slowly when i paste in text, type and (especially) delete text. I can see in top that irb is using lots of cpu. But i don't know how to diagnose this problem any further. It just started happening a couple of weeks ago. I'm wondering if it's possibly readline/wirble related? I use both of those.
I just tried it in another app, pasting in a block of text, and it seems just as bad - the text is appearing at the rate of one char a second! Maybe my command line history has filled up or something? How can i delete it? (for the rails console, not my bash command line history)
grateful for any advice - max
Edit - sorry, should have supplied some system details. Here you go:
System - Ubuntu 10.04
Ruby version - ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]
I just tried plain irb and i have the same problem. It might even be slower, it's pretty much ground to a halt halfway through the block of text i pasted in to test it.
I've rebooted many times (my laptop battery is knackered so i have to restart every time i unplug it anyway).
I'm not in a vm.
I have recently started using RVM (ruby version manager) and it seems to have coincided with that, though it might just be a coincidence. The problematic consoles are happening using system ruby, though, not an rvm.
Here's the output from ps aux | grep irb
:
max 12583 0.0 0.0 1756 484 pts/7 S+ Apr11 0:00 sh -c irb -r irb/completion -r "/home/max/work/rails_apps/millionaire_container/millionaire/config/environment" -r console_app -r console_with_helpers --simple-prompt
max 12584 15.9 2.7 61872 56956 pts/7 S+ Apr11 158:26 irb
max 13981 64.4 0.9 20080 18708 pts/9 R+ 09:40 29:51 irb
max 14625 21.8 0.6 15020 12628 pts/12 Rl+ 10:25 0:20 irb
max 14757 0.0 0.0 3048 804 pts/13 R+ 10:27 0:00 grep --color=auto irb
It seems like rvm's readline is causing the slowness, put this line in your ~/.irbrc:
IRB.conf[:USE_READLINE] = false
Now try pasting something on irb. Is it fast? Good!
Only problem now is that you've lost the ability to edit your lines. We need to fix rvm's readline.
# assuming 1.8.6 is your rvm's default ruby version
rvm package install readline
rvm remove 1.8.6
rvm install 1.8.6 --with-readline-dir=$rvm_path/usr
Don't forget to edit out the IRB.conf line from your irbrc.
Simply using readline didn't help for me; there seems to be a deeper problem with libreadline, at least on OSX 10.7 where the select() system call waits for the timeout to expire before returning, even when there's data available.
My hack, which fixes this annoyance, is:
cd $rvm_path/src/readline-6.2
vi config.h
(change the line "#define HAVE_SELECT" -> #undef HAVE_SELECT)
make install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With