Running Ruby&Rails on a tiny MIPS machine
Here's a quick summary of which versions of ruby and rails app servers I've successfully ran on my router (see previous post):
| Ruby | Success | Comment |
|---|---|---|
| 1.8.7p334 | YES | Typo quickly takes more RAM than is comfortable (95-125MB) |
| 1.8.7 enterprise | NO | Segfault in GC in webrick |
| 1.9.1 from ipkg-opt | NO | Cross compiled paths to gcc, libs, and includes are hardcoded wrong |
| 1.9.1p431 | YES | Typo memory footprint is lower (75-95MB), get nice warning about rails test suites in 1.9.1 |
| 1.9.2p290 | NO | Webrick dies with NotImplementedError: ruby engine can initialize only in the main thread |
I've had a lot of trouble finding a compatible rack app server. Unfortunately, webrick is the only one so far.
| Rails App Server | Success | Comment |
|---|---|---|
| Webrick | YES | Can't get uploaded files to work so far |
| Thin | NO | Segfault in pthread |
| Unicorn | NO | Won't compile because lib_atomic_ops is not supported in MIPS |
| Passenger-Nginx | NO | ext/oxt/detail/../detail/spin_lock_pthreads.hpp can't find pthread functions |
I'm running this ruby Typo blog on a home router
Hardware

To replace my Asus eeePC netbook/apple airport extreme/linksys smallbiz VPN router, I chose the Asus N16 router for $86. It's equipped with 128MB of RAM (the most important thing for this project), 32MB of flash (which allows me to run the largest firmware), and a 480mhz broadcom MIPS processor.
DD-WRT
The DD-WRT project is an open source firmware that runs on tons of home routers. It was easy to install on mine, just flash the build that was listed in their database for my router. Next I connected a USB 4GB flash drive that I partitioned into 3 partitions using a different machine (/opt, SWAP, and /mnt) and enabled all the necessary features in the web GUI to automount /opt and enable JFFS. I finally installed optware using these instructions which proved to much better than figuring out everything be hand. Then I installed the build tools (g++, gcc, make, etc) and nginx to host static content, sqlite as a DB, and probably tons of other packages I forgot as this point. At one point I got mysql server 5.0 working, but went back to sqlite.
The LD_LIBRARY_PATH variable that's preset with optware (maybe in /opt/etc/profile?) breaks the compiler like crazy. I found the only way to fix it was unset LIBRARY_PATH, then I can configure/make software with some success.
Building ruby
I had no success with the binary ruby 1.9.1 package that comes with optware, so I tried to build it myself. Ruby 1.8.7 was fairly easy to build (takes hours of course), though I did have to manually specify the build target as "mips". Ruby 1.9.2 was easy to build and install as well, and uses less memory, but I couldn't get webrick to run without segmentation faulting. RubyEE 1.8.7 seemed to work, but I had seg fault in the GC when I ran webrick.
Installing Typo
First I installed bundler. It takes about 20 minutes to install a gem, unless you specify --no-ri --no-rdoc --no-update-sources, but you have to download the sources at least once. Then I ran bundle install, which takes several hours. I failed to get any app servers working except webrick to work (unicorn is not supported on MIPS, and thin segfaults).
Memory Issues
The webrick process inflates to a pretty large size and I have to kill it frequently. 128MB of RAM is the bare minimum for a big rails app on ruby 1.8.7, I wish that I could get 1.9.x to work. I do some amount of swapping to flash drive, which may be bad for the life of the disk. I'm also planning on using monit to restart rails automatically sometimes. Nginx works like a dream and uses less than 1MB of RAM.