开发者

Rails console running incredibly slowly when editing text

In one of my rails apps, the console has started running really slowly when i paste in text, type and (espe开发者_StackOverflow中文版cially) 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


I ran into the same issue using REE on Ubuntu 12.04 and tried all the solutions listed here without any success. The final working solution for me was:

  1. apt-get remove libreadline6-dev
  2. apt-get install libreadline-gplv2-dev
  3. rvm remove 1.8.6
  4. rvm install 1.8.6

The issue appears to be a minor incompatibility with libreadline6-dev. When libreadline6-dev was present on the machine, it would be used when compiling Ruby, and the problem would occur. This would happen regardless of the --with-readline-dir options passed when compiling ruby. Unfortunately, in the latest version of Ubuntu, there is no libreadline5-dev, but there is libreadline-gplv2-dev.


FWIW the fix suggested by @fl00r does indeed work. For me, this new behavior appears to correlate with installing the Snow Leopard 10.6.7 update. It happens in both IRB and Rails Console.

Another thing that seems to work for me is to make sure the last line of the pasted test includes a "naked" newline character.

This is definitely new behavior and it is very annoying.


I see it on OS X too. @fl00r's fix works (hitting any key while the paste is trying to, um, paste.) @jesvs fix works and is permanent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜