I was hacking with passwordless ssh login when Capistrano deployment failed with that message. Running (on Mac OS):
$ ssh-agent bash
$ ssh-add
and then running cap tasks fixed the problem for now.
Tuesday, June 19, 2007
Monday, June 18, 2007
Using acts_as_reportable Rails plugin to generate CSV data from Active Record
1) sudo gem install ruport -y
2) require "ruport" in environment.rb
3) include acts_as_reportable in your model.
You are now ready to play with the model in the script/console. Very easy and powerful plugin. For more info, check out http://stonecode.svnrepository.com/ruport/trac.cgi/wiki/AARTutorial
2) require "ruport" in environment.rb
3) include acts_as_reportable in your model.
You are now ready to play with the model in the script/console. Very easy and powerful plugin. For more info, check out http://stonecode.svnrepository.com/ruport/trac.cgi/wiki/AARTutorial
Upgraded Ruby to Ruby 1.8.6-p36
This version is compatible with FasterCSV. Hivelogic instructions will work, but you need to use the the url ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p36.tar.gz
to install the latest Ruby distribution. This release was announced on Ruby-Talk mailing list.
You can skip the readline installation if you have it already installed for Ruby 1.8.6 released on march 07.
to install the latest Ruby distribution. This release was announced on Ruby-Talk mailing list.
You can skip the readline installation if you have it already installed for Ruby 1.8.6 released on march 07.
Sunday, June 17, 2007
Pending Deployment Tasks
1) Find out how deploy_with_migrations Capistrano switch works.
2) Change the style.css for the site.
3) How to connect to the database during deployment without using database.yml?
4) How to upgrade if you freeze gems?
This is answered in Rails Recipes. 5) Install Exception Notification plugin and SiteMeter.
6) Contact model, create a secure RSS feed. Refer Rails Recipes.
2) Change the style.css for the site.
3) How to connect to the database during deployment without using database.yml?
4) How to upgrade if you freeze gems?
This is answered in Rails Recipes. 5) Install Exception Notification plugin and SiteMeter.
6) Contact model, create a secure RSS feed. Refer Rails Recipes.
Deployed Rails App on Staging and Production Environments
1) I looked at the mongrel.log file, the error message said that it
could not find staging.rb. So I created an empty staging.rb file under
config/environments directory.
2) staging configuration for socket value was set to the output of
locate mysql.sock.
3) The staging.log showed that require 'turn' statement in
environment.rb was missing the turn gem. I moved this statement to
development.rb, since it is required only for development.
Missing gem headaches: I also learned about rake freeze gem that allows
taking gems to the deployment environment. But I don't know if I freeze
a gem I will be able to upgrade it later. I will get this clarified from
Rails mailing list.
My emails are being sent, but when I signup I see the link as:
http://localhost.localdomain/activate/7fb260146d37cf5aec957fa0662d94c52a9f2488
http://#{ActionMailer::Base.smtp_settings[:domain]}/activate/#{user.activation_code} line in the rhtml template takes the smtp_settings defined for that environment. So
define the domain in staging.rb to fix this problem
could not find staging.rb. So I created an empty staging.rb file under
config/environments directory.
2) staging configuration for socket value was set to the output of
locate mysql.sock.
3) The staging.log showed that require 'turn' statement in
environment.rb was missing the turn gem. I moved this statement to
development.rb, since it is required only for development.
Missing gem headaches: I also learned about rake freeze gem that allows
taking gems to the deployment environment. But I don't know if I freeze
a gem I will be able to upgrade it later. I will get this clarified from
Rails mailing list.
My emails are being sent, but when I signup I see the link as:
http://localhost.localdomain/activate/7fb260146d37cf5aec957fa0662d94c52a9f2488
http://#{ActionMailer::Base.smtp_settings[:domain]}/activate/#{user.activation_code} line in the rhtml template takes the smtp_settings defined for that environment. So
define the domain in staging.rb to fix this problem
Saturday, June 16, 2007
`No such file or directory – /tmp/mysql.sock`
run `locate mysql.sock` or `locate mysqld.sock` to find where your socket is located, then update database.yml to reflect your system’s configuration. So your entry will be:
socket: /path/to/mysql.sock
socket: /path/to/mysql.sock
Friday, June 15, 2007
Simply Rich Association Plugin Released
I am excited to make my first plugin available for public. You can
checkout the code by doing:
svn checkout http://simply-rich-association.googlecode.com/svn/trunk/
simply-rich-association
Hosted on Google Code: Project home page is http://code.google.com/p/simply-rich-association/
The README file has good explanation of what the plugin can do. http://simply-rich-association.googlecode.com/svn/trunk/README
Enjoy!
checkout the code by doing:
svn checkout http://simply-rich-association.googlecode.com/svn/trunk/
simply-rich-association
Hosted on Google Code: Project home page is http://code.google.com/p/simply-rich-association/
The README file has good explanation of what the plugin can do. http://simply-rich-association.googlecode.com/svn/trunk/README
Enjoy!
Wednesday, June 13, 2007
Komodo IDE 4.1 First Impression
When you run the Komodo it loads all the code intelligence for PHP, Python etc. Very annoying when you want to just work on Ruby. After installation the tutorial instructions tell you to load a certain file. Uhh? Where did it install? It does not know where it installed so you have to manually search to load the tutorial.
There is no way to customize the appearance, no themes. No thanks, I will stick with Textmate for now. Maybe Netbeans might be a good alternative one day.
There is no way to customize the appearance, no themes. No thanks, I will stick with Textmate for now. Maybe Netbeans might be a good alternative one day.
How to convert a name of a class to Class in Ruby
"Foo".constantize will return Foo. Now you can call any methods on Foo.
Attachment_fu - How to display the image
Mike clark's weblog has a good article on how to use attachment_fu to upload images. In my application I did not need any thumbnails. In this case to display the image in the show.rhtml I had to use the image_tag(@person.public_filename) to display the image.
Adding multiple files to Subversion at once
svn st | grep "^?" | awk '{ print $2}' | while read f; do svn add $f; done
If you want all the ? files to be added. Found this tip here http://www.gregwhitescarver.com/blog/2006/05/22/add-multiple-files-in-subversion-at-once/
If you want all the ? files to be added. Found this tip here http://www.gregwhitescarver.com/blog/2006/05/22/add-multiple-files-in-subversion-at-once/
Creating admin accounts using Rake task
Memphisto project by Rick Olson has a Rake task called db:bootstrap that is in bootstrap.rake file. It creates admin accounts from the data specified in the users.yml file. Awesome!!!
How to export data from one database and import into another.
mysqldump -u root -p myapp_staging some_table > mytable.sql
and then
mysql -u root -p myapp_acceptance < mytable.sql
and then
mysql -u root -p myapp_acceptance < mytable.sql
Rails Refactoring to Resources - Using CRUD and REST in Your Rails Application
Nice book from Apress written by Trotter Cashion. I finished reading this book last night. It has a very good coverage of the RESTful goodness in Rails. Short and sweet. Learned a lot from this book. Very well written. I give it 4.5 out of 5 stars. The reason is ActiveResource in the latest Rails is not discussed in the book.
Saturday, June 09, 2007
svn: Out of date: '/trunk' in transaction '2-1
When I commit the changes to the svn, I got:
svn ci .
Sending .
svn: Commit failed (details follow):
svn: Out of date: '/trunk' in transaction '2-1'
svn: Your commit message was left in a temporary file:
svn: '/Users/balaparanj/work/zepho/ard/svn-commit.tmp'
Out of date here means the repository version is not the same as the local version. It works after doing svn up.
svn ci .
Sending .
svn: Commit failed (details follow):
svn: Out of date: '/trunk' in transaction '2-1'
svn: Your commit message was left in a temporary file:
svn: '/Users/balaparanj/work/zepho/ard/svn-commit.tmp'
Out of date here means the repository version is not the same as the local version. It works after doing svn up.
Thursday, June 07, 2007
Monday, May 21, 2007
Filter chain halted as [#] returned false.
Solution to this is Dynamic Session Expiration times with Rails.
Tuesday, May 15, 2007
Rails Performance Screencast notes
Here is the notes I took notes from topfunky's httperf screencast.
Production Log Analyzer is a gem that lets you find out which pages on
your site are dragging you down.
Change one thing at a time and benchmark. Take actual data from
production db, export it and use it for benchmarking. Create a
separate environment for benchmarking.
Install httperf. Need 2 machines one for running httperf client and
the other for running Rails app.
Shut down all unnecessary programs on both machines to reduce CPU
usage. This reduces unpredictable results.
Process for Benchmarking Webapplication using Httperf
1) rake sweep_cache
2) mongrel_rails start -e production (no logging)
3) Hit a particular page once
4) run httperf (with consistent args)
Step 1 and 2 is run on Rails app machine. Go to browser on the client
machine load the page and run:
httperf --server machine_name --port 3000 --ur /page_name --num-conns 1000
The number of connections parameter can be changed. In the output of
the httperf make sure that you get number of replies is same as total
connections. Reply status should not have any errors. If there are any
httperf errors the results must be tossed out.
Copy the "Reply rate" line of the httperf output for different number
of connections and use topfunky's script to generate graphs.
./script/parse_httperf_log log/httperf-sample-log.txt
Tuning Mongrel for Performance
Here are the steps for finding how many requests per second a single
Mongrel process can handle.
httperf --server machine_name --uri /page_name --port 3000 --num-conns
7000 --rate 650 --hog
650 is the requests/sec
If this process hangs for more than 20 secs then we have overloaded
Mongrel. Httperf should have no errors (because it means httperf was
overloaded, in that case data must be tossed out).
Try different values for number of connections and rate, such as 6600,
660, 6700, 670 etc. Till the reply rate reaches a maxium and begins to
drop off.
Production Log Analyzer is a gem that lets you find out which pages on
your site are dragging you down.
Change one thing at a time and benchmark. Take actual data from
production db, export it and use it for benchmarking. Create a
separate environment for benchmarking.
Install httperf. Need 2 machines one for running httperf client and
the other for running Rails app.
Shut down all unnecessary programs on both machines to reduce CPU
usage. This reduces unpredictable results.
Process for Benchmarking Webapplication using Httperf
1) rake sweep_cache
2) mongrel_rails start -e production (no logging)
3) Hit a particular page once
4) run httperf (with consistent args)
Step 1 and 2 is run on Rails app machine. Go to browser on the client
machine load the page and run:
httperf --server machine_name --port 3000 --ur /page_name --num-conns 1000
The number of connections parameter can be changed. In the output of
the httperf make sure that you get number of replies is same as total
connections. Reply status should not have any errors. If there are any
httperf errors the results must be tossed out.
Copy the "Reply rate" line of the httperf output for different number
of connections and use topfunky's script to generate graphs.
./script/parse_httperf_log log/httperf-sample-log.txt
Tuning Mongrel for Performance
Here are the steps for finding how many requests per second a single
Mongrel process can handle.
httperf --server machine_name --uri /page_name --port 3000 --num-conns
7000 --rate 650 --hog
650 is the requests/sec
If this process hangs for more than 20 secs then we have overloaded
Mongrel. Httperf should have no errors (because it means httperf was
overloaded, in that case data must be tossed out).
Try different values for number of connections and rate, such as 6600,
660, 6700, 670 etc. Till the reply rate reaches a maxium and begins to
drop off.
Scaling Rails - Notes from Silicon Valley Ruby on Rails Meetup
Some websites are launched by getting it on TechCrunch, Digg, Reddit
etc. In such cases there is no time to grow organically.
Resources:
1. The Adventures of Scaling Rails -
http://poocs.net/2006/3/13/theadventuresof scalingstage1
2. Stephen Kaes "Performance Rails" - http://railsexpress.de/blog/f
iles/slides/rubyenrails2006.pdf
3. RobotCoop blog and gems -
http://www.robotcoop.com/articles/2006/10/10/thesof
twareandhardwarethatrunsoursites
4. OReilly's book "High Performance MySQL
This presentation's focus is on what's different from previous
writings. For comprehensive overview refer the above resources.
Scribd.com was in launched in march, 07. It is the "YouTube" for
documents and it handles around 1 Million requests per day.
Current Scribd Architecture
1 Web Server
3 Database Servers
3 Document Conversion Servers
Test and Backup machines
Amazon S3
Server Hardware
Dual, dual core woodcrests at 3 Gz
16 GB of memory
4 15K SCSCI hard drives in a RAID 10
Disk speed is important. Don't skimp; you're not Google, and it's
easier to scale up than out.
Hosted by Softlayer.
Software
CentOS
Apache/Mongrel
Memcached, RobotCoop's memcache-client
Stefan Kaes' SQLSessionStore - This is the best way to store peristent sessions.
Monit, Capistrano
Postfix
They ran tests and found out that fragment caching improved
performance for their web app.
How to Use Fragment Caching
Consider only the most frequently accessed pages.
Look for pieces of the page that don't change on every page view and
are expensive to compute
Just wrap them in a
<% cache('keyname') do %>
...
<% end %>
Do timing test before and afterwards; backtrack
unless significant performance gains
Expiring fragments - 1. Time based
Use memcached for storing fragments
It gives better performance
It is easier to scale to multiple servers
Most importantly: It allows timebased expiration
Use plugin http://agilewebdevelopment.com/plugins/memcache_fragments_with_time_e...
Dead easy:
<% cache 'keyname', :expire => 10.minutes do %>
...
<% end %>
Expiring fragments - 2. Manually
No need to serve stale data
Just use: Cache.delete("fragment:/partials/whatever")
Clear fragments whenever data changes
Again, easier with memcached
They also discussed about how to use 2 database servers with Rails
app. For more information you can see the slides at
http://www.scribd.com/doc/49575/Scaling-Rails-Presentation
Q & A
They use SWF open source plugin for uploading documents (it allows
multiple docs to be uploaded simultaneously)
They pay only $100 monthly for Amazon S3 for 5 tera bytes of b/w
usage. Downside of using Amazon S3 is that they cannot generate
analytics for that part of the app.
The uploaded files goes to a queue and is processed in the background.
So the documents don't appear immediately on the site if the load is
high.
Tip from the first presentation on CacheBoard: It uses backgroun drb
plugin by Ezra for exporting documents in XML format.
etc. In such cases there is no time to grow organically.
Resources:
1. The Adventures of Scaling Rails -
http://poocs.net/2006/3/13/theadventuresof scalingstage1
2. Stephen Kaes "Performance Rails" - http://railsexpress.de/blog/f
iles/slides/rubyenrails2006.pdf
3. RobotCoop blog and gems -
http://www.robotcoop.com/articles/2006/10/10/thesof
twareandhardwarethatrunsoursites
4. OReilly's book "High Performance MySQL
This presentation's focus is on what's different from previous
writings. For comprehensive overview refer the above resources.
Scribd.com was in launched in march, 07. It is the "YouTube" for
documents and it handles around 1 Million requests per day.
Current Scribd Architecture
1 Web Server
3 Database Servers
3 Document Conversion Servers
Test and Backup machines
Amazon S3
Server Hardware
Dual, dual core woodcrests at 3 Gz
16 GB of memory
4 15K SCSCI hard drives in a RAID 10
Disk speed is important. Don't skimp; you're not Google, and it's
easier to scale up than out.
Hosted by Softlayer.
Software
CentOS
Apache/Mongrel
Memcached, RobotCoop's memcache-client
Stefan Kaes' SQLSessionStore - This is the best way to store peristent sessions.
Monit, Capistrano
Postfix
They ran tests and found out that fragment caching improved
performance for their web app.
How to Use Fragment Caching
Consider only the most frequently accessed pages.
Look for pieces of the page that don't change on every page view and
are expensive to compute
Just wrap them in a
<% cache('keyname') do %>
...
<% end %>
Do timing test before and afterwards; backtrack
unless significant performance gains
Expiring fragments - 1. Time based
Use memcached for storing fragments
It gives better performance
It is easier to scale to multiple servers
Most importantly: It allows timebased expiration
Use plugin http://agilewebdevelopment.com/plugins/memcache_fragments_with_time_e...
Dead easy:
<% cache 'keyname', :expire => 10.minutes do %>
...
<% end %>
Expiring fragments - 2. Manually
No need to serve stale data
Just use: Cache.delete("fragment:/partials/whatever")
Clear fragments whenever data changes
Again, easier with memcached
They also discussed about how to use 2 database servers with Rails
app. For more information you can see the slides at
http://www.scribd.com/doc/49575/Scaling-Rails-Presentation
Q & A
They use SWF open source plugin for uploading documents (it allows
multiple docs to be uploaded simultaneously)
They pay only $100 monthly for Amazon S3 for 5 tera bytes of b/w
usage. Downside of using Amazon S3 is that they cannot generate
analytics for that part of the app.
The uploaded files goes to a queue and is processed in the background.
So the documents don't appear immediately on the site if the load is
high.
Tip from the first presentation on CacheBoard: It uses backgroun drb
plugin by Ezra for exporting documents in XML format.
Subscribe to:
Posts (Atom)