Jonathan Barnes's blog
Ask for Help
"I am having trouble installing Mechaize on CentOS any tips and tricks?"
None from the pivots...
"Any good tips on testing the creation of symlinks from ruby?"
shell out and do an ls -l then parse the string to see if it's target is correct.
Interesting Things
- RubyMine's changes -> repository pane only seems to show the current users changes (SVN) instead of all changes for the repository. Showing history of a file still shows all user changes.
- The JSON gem overrides active supports to_json method. So if you are using the built in rails JSON support and you install the gem be aware that there are differences between them.
- Word is this is better on Edge and the gem no longer conflicts with the built-in version
- We have started moving some of our servers to Engine Yards cloud solution, and while it is still in the early stages it is looking like a promising solution.
Ask for Help
"I have a dependent destroy that is taking 5sec+, What can I do to speed that up?"
- try dependent delete on the leaves of the chain if you don't have any after destroy hooks there that need running.
- try cascade delete in your database (again as long as you don't have any after destroys to worry about)
- try marking the element at the top of the tree as deleted (using acts as paranoid or similar), then run an offline process to look for those records and destroy them and their dependent objects.
- don't worry about orphaned records and manually clean them up every once in a while (unrecommended but least development effort)
Ask for Help
"What are some good ways to merge large business location data sets?"
There was a bunch of input including the following:
- You should create a scoring of how close the matches are.
- Good admin merge tools are worth the effort to create.
- Normalizing the data prior to the merge (i.e. pass the addresses through the USPS API to turn [Av Ave Avenue] => Ave)
- Humans do this best, outsource or Mechanical Turk it.
Interesting Things
The after_commit plugin allows you to hook events to after the transaction commits. This is really useful when kicking off threads that expect to have access to the data in the database. Note: using after_save can cause you to have a race condition if the other thread attempts access to the data before the original thread has a chance to commit the transaction.
If you are storing a marshaled object in the database, you should make that field a blob type, it is smaller to store and if you leave it as a text or varchar you can corrupt the binary data you are storing in there. If you don't have a choice about field types you should at least base64 encode the marshaled data before storing it.
ctrl+z
RE: "NewRelic Side Effects?" from 05/19/2009 Standup
- It seems that NewRelic was not the cause of the problem but helped in exacerbating the problem by holding the transaction open long enough to create a race condition that still shows up when the system is put under enough load. To fix our problem we moved the trigger that launches the background process from and after_save to an after_commit see plugin. We also re-added NewRelic.
Ask for Help
"Who is getting
svn: Server sent unexpected return value (403 Forbidden) in response to PROPFINDin SVN?"
Lots of people! This is a known bug when a SVN project has to traverse the repository using more than one user. Check out subversion: Issue 3242.
"Has anyone gotten ImageMagic to work with Phusion Passenger on CentOS?"
It seems to work with Mongrel, but not Passenger.
"Who is getting
svn: Server sent unexpected return value (403 Forbidden) in response to PROPFINDin SVN?"
Interesting Things
-
- It has some cool new features, such as showing you CSS comments -- handy for SASS debugging! Works in conjunction with enabling SASS line numbers in the CSS output.
- It also supports FireDiff, which "records all of the changes made by firebug and the application itself to CSS and the DOM".
NewRelic Side Effects? We have some background processes that get kicked off from after saves of some of our ActiveRecords. These processes use Active Resource to post back updates to these records. Unfortunately the transaction that creates the record initially doesn't seem to have completed before the first post-backs attempt to update them. (race condition). After trying a bunch of stuff we randomly removed the NewRelic plugin and all of the sudden we had no more race conditions. Is the NewRelic plugin holding the DB transactions open too long?
MySQL index sample size: We discovered that MySQL's
ANALYZE TABLEuses a fixed sample size from the index regardless of the size of the table and thus can have really incorrect cardinality and which could lead to it choosing the wrong index. AlsoANALYZE TABLEgets run often (opening new connections, first read of table) and due to the problem mentioned above can cause the system to switch from using the right index to the wrong index each time you look at it.
Ask for Help
"Does time spent in the C code show up in the ruby-prof output?"
Yes it does -- There are two stats for method time: "Self" [time in method] - [time spent in called children]), "total" [total time in method]. The second should include time spent in the C code
It was also mentioned that it is much more useful to look at the ruby prof output as HTML or even better using KCachegrind (though it was mentioned that it can be a bit of a pain to get it installed see KCachegrind OS X 10.5.6
You have probably noticed that the changes view is unusable in RubyMine because of all the .svn files showing.
Well if you refresh (
) the changes view they go away...Hurray!
Interesting Things
- APIdock.com is a web app that provides a rich and usable interface for searching, perusing and improving the documentation of projects that are included in the app.
Ask for Help
"We are getting 504 Gateway errors and we thing it is because our mongrels are freezing up do to inability to allocate memory, what to do?"
Without more info on the problem a few possibilities were suggested, such as the OS might be swap thrashing or the OS has no more memory to allocate.
One suggestion is to cut down your swap space to 0 in an attempt to verify that your mongrels are asking for too much, basically remove to OS swapping memory to disk from the equation.
Another suggestion is to boost your swap up to some insane size, also to take it out of the equation, the theory being that we know mongrel can leak memory, we trust the OS to keep the used memory in RAM, and we have plenty of disk space, so why put your OS in the position of not grating a mongrel what it is asking for.
Both solutions above don't seem ideal but, whatever, we are pragmatists, and if we combine those with periodic monitoring of the system using top/ps/vmstat, at least your mongrel can keep running and this may give you time to figure out why mongrel may be so memory hungry
Interesting Things
- If your wanting better out-of-the-box error messaging you can use one or both of the following plugins:
active_record_full_messages_should_be_nicervalidates_associated_displaying_associated_errors
If you choose to use both however ORDER DOES MATTER (use the order specified above) otherwise the validates_associated one just doesn't seem to work.
- Hash Iterations is very expensive (this includes my_hash.keys and my_hash.to_a etc...). We think this is related to the way hashes are stored in large, sparsely populated hashtables. If you can, avoid iterating over a hash, and if you must, try using a SequencedHash (which is provided by the collections gem) which solves this by storing hashes as both traditional hashtables and arrays, allowing for fast random access (the hashtable) as well as fast iteration (the array).
Ask for Help
"We want to load a different set of libraries for our selenium test than our regular tests. We tried to create a 'selenium' environment and pass that to the rake:test task but that didn't work, anyone know why?"
You cannot run in non 'test' environment with the rake tasks as the 'test' environment is hard coded into the test task, and passing a different RAILS_ENV seems to only have the effect of telling the 'test' environment what database to base it's schema off of.
Proposed work around - pass a second environment variable e.g. selenium=true and switch on that. (it's not ideal so we are still open to better solutions)
Help
- Edward was wondering if anyone had any experience using XMPP4R or the XMPP protocol in general.
Interesting
- Brown bag today has changed from RR to Lightning Talks. Anyone can present. The focus will be on interesting technology used on the various projects.







