Rails console running incredibly slowly when editing text - ruby-on-rails

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

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:
apt-get remove libreadline6-dev
apt-get install libreadline-gplv2-dev
rvm remove 1.8.6
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.

Related

How does one make sure that their rails environment on one machine is the same as another?

I have three macs. I have a rails app, that I can run on two of them. On the third, I can create a new rails app and it works fine and some of my other rails apps from the other machines work fine, however the one that I need to have work on the one machine always gives me a message about not being able to find an image:
/Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': dlopen(/Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
Referenced from: /usr/local/opt/mysql/lib/libmysqlclient.21.dylib
Reason: image not found - /Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle
I have followed suggestions about installing the mysql2 bundle using:
gem install mysql2 -v '0.5.3' -- --with-cflags=\"-I/usr/local/opt/openssl/include\" --with-ldflags=\"-L/usr/local/opt/openssl/lib\"
then bundle install, and it says all is fine. Yet 'rails s' produces that unable to find image message.
I use rbenv to manage versions and on all machines ruby is 2.6.3 and rails is 5.2.4.
What other aspects of the configuration of the app do I need to check to make sure they are the same? I have a script called 'laptop' that I obtained using:
cd ~
curl --remote-name https://raw.githubusercontent.com/monfresh/laptop/master/mac
curl --remote-name https://raw.githubusercontent.com/monfresh/laptop/master/Brewfile
/usr/bin/env bash mac 2>&1 | tee ~/laptop.log
I run this on each machine when I am setting up to install or run a rails app. On the problem machine I do get messages like:
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/usr/local/Cellar/python#2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
during the laptop run, but at the end it says all modules were installed correctly. I have a feeling that's not really true and may be part of the problem. If so, what is causing this? I'm running OS X 10.14.6 on the machine in question.
I also notice that libssl.1.0.0.dylib is NOT present at the specified location. How do I install this and moreover, how to I make sure that all of these pieces are properly coordinated?
Found it finally! Thank you:
https://rorguide.blogspot.com/2011/07/getting-error-library-not-loaded.html
I had looked at a lot of these and tried the making a soft link to no effect, but this was the first time I found this one!:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
worked!

EOFError: end of file reached -- all js specs are crashing Capybara with an older Chrome driver

Capybara using Chrome driver with setup:
spec_helper
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.javascript_driver = :chrome
I appear to be getting
EOFError:
end of file reached
On all of my Javascript tests when I run them with chrome driver.
This appears to have began on or around Oct 27, 2016
Running with poltergeist they work fine.
• also when they crash they appear to open multiple instances of chrome which hang (but do not exit) see http://screencast.com/t/Worwl9d6Iuhr screenshot example
• these appear to affect only my javascript specs (:js => true in Capybara)
• Rebooting my machine did not solve the problem
• My Chrome Mac OS X is currently at 54.0.2840.71
• I'm not sure when sub-sub-point version 71 got released since of course Chrome doesn't tell you or even seem to have it available in some kind of update history. The public information says sub-point version 54.0.2840 was released 2016-10-12 but it doesn't specify when sub-sub-point version 71 was released
• I can reproduce the effect on both my code on master, as well, I have a specific memory of running these specs with Chrome driver earlier in this week, so I am strongly suspecting that Chrome did a sub-sub-point release here and broke this.
if anyone else can confirm I would appreciate it. otherwise, if I find a local problem, I will post answer here.
• Capybara 2.7.1
• selenium-webdriver 2.53.0
• I located the Chromedriver executable in my machine at /usr/local/bin/chromedriver [is this the right one -- I seem to have an older one in /Users/jason/bin/chromedriver ?]
$ which chromedriver
/usr/local/bin/chromedriver
$ /usr/local/bin/chromedriver -v
ChromeDriver 2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b)
Upgrading Chrome Driver to 2.25 solved the issue
to do so via brew
$ brew unlink chromedriver
Unlinking /usr/local/Cellar/chromedriver/2.20... 1 symlinks removed
$ brew install chromedriver
==> Using the sandbox
==> Downloading https://chromedriver.storage.googleapis.com/2.25/chromedriver_mac6
######################################################################## 100.0%
==> Caveats
To have launchd start chromedriver now and restart at login:
brew services start chromedriver
Or, if you don't want/need a background service you can just run:
chromedriver
==> Summary
🍺 /usr/local/Cellar/chromedriver/2.25: 4 files, 10.3M, built in 7 seconds
hope this helps someone. I recently got this error when I was using capybara/poltergeist on a specific port (`., then I had a crashed test process still listening on a specific port.
If you are using rbenv, you can upgrade the chromedriver using brew than copy the executable :
for example, I'm using ruby 2.4.1:
$ cp /usr/local/Cellar/chromedriver/2.30/bin/chromedriver $HOME/.rbenv/versions/2.4.1/bin/
$ chmod +x $HOME/.rbenv/versions/2.4.1/bin/chromedriver
thank you

Disable warnings in Ruby - where to place

I'm using Ruby -v 2.2.4 currently and don't want to upgrade to 2.3.1 for compatibility purposes. However, I'm now getting hit with these warning messages.
RubyDep: WARNING: Your Ruby is outdated/buggy.
(To disable warnings, set RUBY_DEP_GEM_SILENCE_WARNINGS=1)
Where do I place that code?
--> set RUBY_DEP_GEM_SILENCE_WARNINGS=1)
It's depend on the OS which you use, for Linux(and MacOS) and bash shell you can place it:
Bash shell
Before command e.g. $user: RUBY_DEP_GEM_SILENCE_WARNINGS=1 irb
Export as env variable
For windows read this.

Node.js not found by Rails / execjs

I have node.js installed by compiling and installing it from the root user. I think this maybe where the hangup is. From the user running the rails app I checked for node.js.
$ which node
/usr/local/bin/node
When I launched my rails app (Rails 3.2.9) I get the universally unhelpful "We're sorry, but something went wrong." Checking the the production error log I saw that the Javascript runtime was not found. That's confusing as it is obviously installed. So I went about forcing the Node javascript runtime. I edited config/boot.rb to include:
ENV['EXECJS_RUNTIME'] = 'Node'
I checked my app again, while watching the production log. This time I got the error
ActionView::Template::Error (Node.js (V8) runtime is not available on this system
Still confused. I went to the execjs gem and changed the runtime command to the exact installed path.
Node = ExternalRuntime.new(
:name => "Node.js (V8)",
:command => "/usr/local/bin/node",
:runner_path => ExecJS.root + "/support/node_runner.js",
:encoding => 'UTF-8'
)
I still get the same error. Node is installed and accessible by the user but the gem/rails can't seem to use it.
The server is run CentOS 6.3. The specific javascript file causing the error to be thrown is jquery.nivo.slider.pack.js. Which I didn't edit after downloading it from nivo.
So, I have Ruby 2.0.0 installed and Rails 4.0.2 on CentOS 5.10 using Apache2 with Passenger. My first step I tried was opening the rails console and typing in the following command:
ExecJS.runtime
It returned the following value:
#<ExecJS::ExternalRuntime:0x99ab380 #name="Node.js (V8)", #command=["nodejs", "node"],#runner_path="/home/foo/vendor/bundle/ruby/2.0.0/gems/execjs-2.1.0
/lib/execjs/support/node_runner.js", #encoding="UTF-8", #deprecated=false, #binary="node">
Which meant that node was indeed installed and detected, but for some reason it was not working.
So, I tried the example on the website:
ExecJS.eval("'red yellow blue'.split(' ')")
and I got the correct response. So, now I am wondering why Passenger isn't picking it up.
Then, I noticed that passenger shows the path variable and it looks like:
/home/foo/vendor/bundle/ruby/2.0.0/bin:/usr/local/rvm/gems/ruby-2.0.0-p481/bin:/usr/local/rvm/gems/ruby-2.0.0-p481#global/bin:/usr/local/rvm/rubies/ruby-2.0.0-p481/bin:/usr/kerberos/bin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/rvm/bin:/home/foo/bin
But, it seems to be missing the usr/local/bin. I'm no expert on Linux, so for me the easiest way to fix this is with a symbolic link. So, I execute ln -s /usr/local/bin/node /usr/bin/node. You may want to note that I found the path to my nodejs using the command find / -name node.
I then refreshed my web application and wouldn't you know it worked. So, if it worked for me I am hoping that it can help someone else out.
UPDATE (Probably Better Way): This is probably a better way to do it. We can compile it from source like so:
mkdir ~/install
cd ~/install
wget https://nodejs.org/dist/v7.2.1/node-v7.2.1.tar.gz
tar xvf node-v7.2.1.tar.gz
cd node-v7.2.1
./configure --prefix=/usr/
make && make install
This way Node.js will be installed in the path where Passenger expects it to be.
I have had similar issue installing nodejs with source on my centos 6.3 system. It was successfully installed but I keep failing in compiling my ror app assets until I explicitly set the PATH to where it was installed (nodejs)
[root]# make install
...
installing /usr/local/lib/node_modules/npm/html/doc/folders.html
symlinking ../lib/node_modules/npm/bin/npm-cli.js -> /usr/local/bin/npm
updating shebang of /usr/local/bin/npm to /usr/local/bin/node
[root]# export PATH=/usr/local/bin:$PATH
Now it works. Hope that helps!
I don't know if this will help but check your $PATH that node is in there. Also, you should be using rvm if you want to use node. Check that your node install is done correctly.

Installing Ruby on Rails on Windows via CYGWIN

I am attempting to follow instructions on this page:
http://www.agilereasoning.com/2011/05/25/ruby-on-rails-on-windows-7-using-cygwin/
I have been trying to install Rails with varying success first using the railsinstaller and I encounter difficulties like no vim and I couldn't copy and paste from the Windows command prompt so I install CYGWIN. It didn't download the files correctly so I downloaded them manually and some were hard to locate. I couldn't find the final package as a .tar file so I downloaded libxslt-devel-1.1.20-1.i386.rpm.
Right click the Cygwin shortcut and choose edit from the menu. Change the contents to >match:
1 #echo off
2 C:\cygwin\bin\rxvt -sr -sl 1500 -e C:\cygwin\bin\bash.exe --login -i
Do I have to put this as a command to run on the executable or inside the cygwin commmand prompt? When I try to do that I get this:
-bash: 'command': command not found
Lots of things wrong here.
You can copy/paste the command prompt with Edit->Mark or Edit->Paste
libxslt-devel-1.1.20-1.i386.rpm is a linux file.
C:\cygwin\bin\rxvt - why are you mesing around with rxvt?
I recommend you install the rubyinstaller + devkit and then do gem install rails. However don't expect to be happy with rails' performance on windows.
Ruby on Rails on Windows via CYGWINTry:
Install Vagrant
Virtual Box,
and Cygwin (or PuTTy, I am using Cygwin).
With this set, open Cygwin, go to your project folder, run vagrant init <box> (my box is hashicorp/precise64 - see others)
(you may also want to cfg your Vagrantfile?). All set, Run: vagrant up and vagrant ssh
Now you have a virtual machine (Ubuntu) running, and you can install rvm (recommended... so you can have different versions of Ruby), or go directly with ruby, rails, etc.. (sudo apt-get ruby -v x.x.x,etc)
- Vagrant "creates and configures lightweight, reproducible, and portable development environments".
- Cygwin helps with ssh issues, etc...
- Virtual Box manages the machine (Ubuntu, or other OS)
With this set, I have no problem at all running Ruby (on Rails) with Windows.

Resources