Archive for the ‘programming’ Category

Why the f*@& is RoR so freakin’ slow?

Friday, November 14th, 2008

Is it just me, or is it every time I visit a Rails-related site, it takes forever to respond?

I’ve noticed with my own Rails sites that if they haven’t been accessed in a while, the site will time out, and a second reload will load up just fine. I’m seeing similar issues on other public Rails sites that may be running RoR servers.

WTF?

Now, I have an internal Rails app that I’m constantly working on that doesn’t have this problem. It has four load-balanced Mongrel instances running, serving a very small office. But it never seems to “go to sleep” when there are no accesses of the app for a while. Nonetheless, there is definitely a problem with some things seem to “pause” a few milliseconds on a quad-core Xserve with not much else running on it.

I’m not gonna bail on RoR, but I gotta wonder what’s going on with performance with Ruby and by extension, Rails. It’s so bad even Tim Bray has called for the Ruby people to take a look at the issue. It’s sad that people acknowledge the problem, but no one knows what the cause is.

Do not name table columns “type” in Rails

Friday, March 14th, 2008

Or error emissions ensue: Chris tells you why. I was really scratching my head on this one, when an application configuration table had a “type” column. Grrr.

I can has iPhone SDK!

Wednesday, October 17th, 2007

It’s official! iPhone SDK out in February. Woot!!!!!11!!1!!!!!!1one.

Running iPhone Apps in Boonies Mode

Wednesday, July 18th, 2007

So, you’re developing an app for iPhone, but you’re bummed because the phone needs to be either within Wi-Fi range or have good signal from AT&T’s EDGE network to access your app’s server on the internet. What if you’re working on a remote data collection app, and can’t guarantee EDGE access, let alone Wi-Fi? Mike at “Phone Different” calls this boonies mode.

Storing an entire web page, complete with CSS, images, and JavaScript, in a data: URL may be the answer. The author of the “Life with Lunchhooks” blog describes, and commenters elaborate on, what could be a huge win for iPhone developers.

This isn’t really a hackish perversion, either. The data: URL is an internet standard, codified in RFC 2397. It just turns out that Safari, and probably most other browsers, will let you bookmark a data: URL just like any other. With that, you now have your app locally stored on your iPhone.

WestHost Rails application deployment — What I’ve learned

Tuesday, March 13th, 2007

After many days of frustration, my Rails app is up and running on our WestHost server. Getting the app uploaded was not so bad, but it appears that you simply can’t do it with Capistrano because SVN is not one of the installable applications on WestHost. I really didn’t want to load up gcc and install SVN by hand. But when I did try out Capistrano, it did partially upload my app — it populated the database!

What do you need to know to get your rails app running on WestHost? Here’s what I learned:

Just FTP it

Since Capistrano was looking like it would be an ordeal, I just decided to roll up the app in a tarball and upload it to the host by ftp. That worked well, and I added an Alias in httpd.conf so that the server would see the new Rails directory. I also updated the .htaccess in the apps Public folder, all as described in the Rails wiki entry HowtoDeployMoreThanOneRailsAppOnOneMachine.

#!/usr/bin/env ruby in the scripts doesn’t work

WestHost doesn’t have a copy of env in /usr/bin, so that little bit of portability is broken. I had to go through and change all the scripts to start with #!/usr/local/ruby/bin/ruby instead. I tried creating a symlink to env in /usr/bin, but it didn’t work. I probably did it wrong (prolly shoulda been a hard link), but didn’t feel like messing around with it any more, and I had already changed the scripts to use the new shebang.

Basic HTTP Authentication is different for Apache

I followed The Teenage Mutant Ninja Hero Coders method to get basic authentication in my app. When I was first doing development on my Mac with lighttpd, all was swell. Then after deploying, I couldn’t figure out why I couldn’t log in. Well, it was my ignorance of the part on the above page that says “If you are using Apache and mod_fastcgi, this method will likely not work out of the box.” After playing around, I edited my httpd.conf to look like this:

<IfDefine HAVE_FASTCGI>
AddModule mod_fastcgi.c
# Added the following line to allow
# passing of http headers to fcgi
FastCgiConfig -pass-header Authorization
</IfDefine>

Ta da! Authentication works!

Still to do

I think I have some routing issues. I have to access the app by doing http://www.server.com/appname/appname/. Actually, I think I need to play with the RewriteBase or something. And, if I leave off the trailing slash, the images used by the app don’t load.

Other than that, the app appears to be working well. I can do all the things with this basic app that I’m supposed to be able to do. All the CRUD stuff is working. All the goodies I put in, since it was so easy, are working too, like webcal:// calendar subscription and CSV export of the data.

I do want to change my report printing from just javascript prints to using PDF::Writer for more control over pagination. That shouldn’t be too hard now that the basic app is running.

The only big issue is normalizing the app so that it’s the same on the production server and the Mac I’m developing on. I think the biggest problem is the shebangs in the scripts folder. I think the best thing is to get env in /usr/bin so I can use that portable method of invoking Ruby.

As I get farther, I’ll post updates. I hope this helps anyone who comes across this, and who is deploying to WestHost.

WestHost Rails application deployment — Why is this hard?

Monday, March 12th, 2007

I’ve written a tidy little app in Rails for work, and need to deploy it to our server. It’s really a basic program so using svn and Capistrano and all that seems like overkill. I just want to upload the folder where I did development locally on my Mac, and have it run on WestHost’s Rails installation. I do, however, want it to be in it’s own separate path, because I anticipate more programs coming along in the future.

I’ve been trying to get this to work for a week, and nothing is working the way it should be. I’ve added the Alias directive in httpd.conf to get it to see the new application directory, but after that, things just fall apart. Why is this so hard? Why does it seem that each hosting provider does this in a different way? This is frustrating.

So, in the full OSS spirit, as soon as I get this figured out, I’ll post my discoveries here to the blog. I hope that it will spare others some of the pain I’m going through at the moment.

Wish me luck!

Poignant Prose

Tuesday, February 20th, 2007

So, I’m re-reading why’s (poignant) guide to Ruby, trying to stay focussed on the code, but secretly waiting for each and every bizarrely delicious metaphor. Like:

[A code block is] like one of those little Hello Kitty boxes they sell at the mall that’s stuffed with tiny pencils and microscopic paper, all crammed into a glittery transparent case that can be concealed in your palm for covert stationery operations. Except that blocks don’t require so much squinting.

I can’t figure out this guy who calls himself “why.” Either he’s insane, or absolutely brilliant. I tend to think he’s the latter. If you are interested in programming, especially Ruby and Ruby on Rails, check out why’s stuff: