Archive for October, 2009

Linux TCP Window Scaling Problem

Wednesday, October 21st, 2009

The router at my office, a Linksys RV082, doesn’t like Linux computers. Supposedly it doesn’t like Vista or Windows 7 computers either (but what/who doesn’t, anyway?!?!). The problem is TCP window scaling, which (for performance reasons) tinkers with packets in a way that the router does not understand (possibly because the router is running firmware that is older than the concept of TCP window scaling, but firmware upgrades fail so I don’t know if the latest firmware fixes the problem). This command fixes the problem by turning off TCP window scaling.

echo 0 > /proc/sys/net/ipv4/tcp_window_scaling

openSUSE 11.1 + NVidia 9600 GT + Acer AL2216

Friday, October 16th, 2009

Whew… Two years ago I bought two of the Acer budget or economy LCD screens from NewEgg (newegg.com). They’re the 2216 screens that are always nicely priced (mine are AL2216wbd but the last few letters change [my company has purchased several varieties including AL2216WBD and V223WBD -- all are great monitors for typical non-graphic-artist business use]). They worked fine in Windows XP with an ATI FireGL card.

Fast forward to today: I just built a new Linux machine running openSUSE 11.1. The NVidia driver install was simple using “the hard way” described here. But the screens gave me a headache within 30 seconds of looking at them. Text was pixilated and fuzzy, and just about everything was so bright that it had white outlines. It was hard to look at. I thought I installed the driver wrong and it was using the wrong resolution and color combination — but it turns out the settings needed a little tweaking. I tried a bazillion different things, and I even contemplated going back to Windows (OUCH). Finally, I went through the painstaking effort of fiddling with all of NVidia’s settings. I am happy to say that this works:

Step 1: Edit /etc/X11/xorg.conf to add the settings described here in the section that begins with “For nVidia drivers you may have to disable automatic detection of DPI to set it manually.” It says to add these two settings to the Section “Device” section of xorg.conf:

  Option   "UseEdidDpi" "false"
  Option   "DPI" "96 x 96"

Step 2: Use the NVidia X Server Settings applet (just click the Gecko / Application Launcher and type nv in the search box) to adjust the brightness, contrast, and gamma. Those settings are under X Screen 0 -> X Server Color Correction. The brightness, contrast, and gamma settings pictured below worked best for me — the headache has gone away!!!

snapshot1

snapshot1

openSUSE Ruby on Rails Hack

Tuesday, October 13th, 2009

Note: This was my first attempt at using openSUSE. On my second attempt, I no longer had this problem. My guess is that I installed the wrong version of something-or-other which caused this problem.

If you have openSUSE 11.1, like I do, then you have Ruby 1.8.7. I encountered an error when trying to run ruby script/console and ruby script/server for the first time in openSUSE. This pretty much killed everything — most of my plug-ins and models didn’t load.

activesupport-1.4.2/lib/active_support/core_ext/string/access.rb:43:in `first’:NoMethodError: 
undefined method `[]‘ for #<Enumerable::Enumerator:0×7f1e1b77aa20>

The problem is that, in Ruby prior to 1.8.7 (perhaps much prior, I don’t know), the [] and/or first methods on String returned an array of characters. Now that has changed so that they return an Enumerable::Enumerator.

I added a hack to the top of /config/boot.rb so that it’d behave. I’ll figure out the real problem later — I’m busy! I found this example elsewhere, but I chose to but it in boot.rb:

unless '1.9'.respond_to?(:force_encoding)
  puts 'un-defining :chars method on String for ruby 1.8.7 compatibility'
  String.class_eval do
    begin
      remove_method :chars
    rescue NameError
      # OK
    end
  end
end

And unformatted:

unless ’1.9′.respond_to?(:force_encoding)
  puts ’un-defining :chars method on String for ruby 1.8.7 compatibility’
  String.class_eval do
    begin
      remove_method :chars
    rescue NameError
      # OK
    end
  end
end

How to Read a Rails Log File

Monday, October 5th, 2009

Frequently, I need to look at my Rails app’s log file. Normally, I use tail -f production.log and hope it doesn’t scroll by so fast that I can’t read it. Sometimes, I need to watch the log file but can’t do so because it’s just too fast. Here’s a nifty Linux command to find what you’re looking for. It uses tail to follow the production log file, but only spits out lines that you are looking for. In my case, I just want to show the URLs of slow requests (e.g. any request that takes longer than one second). The command below looks for the “(0 reqs/sec)” lines in the log file but can easily be changed to look for other things. Just press CTRL+C to terminate it when you’re done.

tail -f production.log | while read line ; do echo "$line"| grep '(0 reqs/sec)' ; done

And on one line without formatting:

tail -f production.log | while read line ; do echo "$line"| grep '(0 reqs/sec)' ; done