Tags

The following entries are tagged with “rails”:

Revisited: roll your own pagination links with will_paginate and Rails 3

With a final release of Rails 3 edging closer every day it seems like a good time to revisit some of my old articles from the last few years and bring them up to date.

Back in the summer of 2008 I wrote about custom link renderers using will_paginate and, as it is still one of the most popular posts on the blog, it’s the one I’ve decided to refresh first. Don’t worry if you haven’t read the original article as I’ll be covering the same things here. So without further ado, let’s get stuck in!

Read more of this entry

Rails 2.3.8, Rack 1.1 and the curious case of the missing quotes

If you're using Rails 2.3.8 for your application and thought that you were safe after May's comedy of errors produced three point updates in as many days, think again. Unfortunately there's a little bug that can lead to parameters being altered or potentially even truncated without warning.

Read more of this entry

InfiniDB, Infobright and MonetDB - Day 3: MonetDB

Day 3 of my database exploration mission brings me to MonetDB. Binary downloads are available for Debian, Fedora, Ubuntu and (strangely!) Windows! If we still had any Windows users left here at HQ then it'd be a rare treat, but instead (as usual) our platform of choice (Centos 5) isn't directly available in binary form. We downloaded the Fedora source RPMs and built our own - in case they're of any use then i've put them up on a Google Code site for others to download.

After installing the RPMs then you're ready to get started - before you can do anything you have to start the merovingian process (you could either setup an init script, or run the binary manually for now). For information, the instructions say:

merovingian is a daemon process that controls a collection of database servers, i.e. mserver5 processes, each looking after a single physical database. Start this program to gain access to your MonetDB database farm. merovingian is designed to be used in a system initialisation script in production environments.

With merovingian running then you're ready to create a database - for this you use monetdb - and then start the database using the same command for example:

> monetdb create twf
successfully created database 'twf'

> monetdb status
     name        state     
twf            stopped              
  
> monetdb start twf
starting database 'twf'... done

> monetdb status
     name        state     
twf            running

You now have a running database and can connect to it using mclient. This is similar to most command line clients where you can perform changes to your database as well as query for data.

The first step to transferring the database was as usual - inspect the schema on our MySQL database and update it to make the correct use of the supported data types. As with the other systems, there's no support for unsigned values, it also wasn't immediately obvious to me what the maximum length of a varchar is.

With the tables created it was time to try and migrate some data. Given MonetDB has been around for quite a while then there seemed to be pretty scarce resources with any detailed instructions - I couldn't, for example, find any simple migration tools or documentation detailing the best path for migration. I guess this could be because MonetDB is more often tackled by people with bigger brains or with more time to figure things out.

I attempted to use the following to dump data from MySQL:

select * from h into outfile '/dbtmp/tmp/h' fields terminated by "|" enclosed by '"';

And then the following to import into my MonetDB table:

copy 1000000 records into h from '/dbtmp/tmp/h' using delimiters '|','\n', '"'  null as '';

This yielded reasonable results - though I did have to do some tidying up in the middle with sed - in the end I gave up as there were some string values causing me problems, so I decided to rest on it and went to bed!

In the morning I came back to find the merovingian process was dead, and the status of the database was showing as crashed. I started up the processes and took a look at the status - it said the health was 67% so i'm not really sure what's going on with it!

Performance

In the time I had available I was only able to get a 1 million row table imported successfully to play with - a shocking performance I know, but MonetDB was being quite fussy and I wasn't pressing the right buttons! I did run a few tests and also ran them against the same dataset in MySQL for comparison, all are run from cold - i.e. MySQL and MonetDB are both restarted before each query. I don't expect these queries to be representative of real world cases, I was just thinking of some nasty queries that I could throw at a single table in order to cause some pain.

Query 1

MySQL takes 250msec:

sql>select count(*) from h;
+---------+
| L1      |
+=========+
| 1000000 |
+---------+
1 tuple
Timer       1.532 msec 1 rows
Query 2

MySQL takes 420msec:

sql>select count(*) from h group by intcolumn;
+-------+
| L2    |
+=======+
+-------+
65 tuples
Timer     142.260 msec 65 rows
Query 3

MySQL takes 44,000msec:

sql>select count(*) from h group by varcharcolumn;
+-------+
| L1    |
+=======+
+-------+
12743 tuples
Timer    1464.389 msec 12743 rows
Query 4

MySQL takes 37,500msec:

sql>select count(*) as total from h group by varcharcolumn order by total;
+-------+
| L1    |
+=======+
+-------+
12743 tuples
Timer    1496.537 msec 12743 rows
Query 5

MySQL takes 373,000msec (not a typo, it's more than 6 minutes):

sql>select count(*) as total from h group by varcharcolumn, anothervarcharcolumn order by total;
+-------+
| L1    |
+=======+
+-------+
69696 tuples
Timer    4170.520 msec 69696 rows

Summary

Obviously this quick trial of each of these is not comprehensive enough to make any solid comparisons of performance - the next step will be for me to go through and come up with a proper test plan in order to be a little more methodical about things. However, it has given me a good grounding in how the 3 systems compare with respect to installing and getting started. I'll be keeping a close eye on InfiniDB - while not stable enough right now, i'm sure they'll keep things rolling and I look forward to taking another look. If I can overcome the import obstacles and also the different 'feel' of MonetDB then the basic query results make a compelling case for taking a further look - there's also more to learn here with respect to architecture, deployment techniques, monitoring, etc. Finally, Infobright - it would make my life easier if we could use it on an insert/update/delete basis - as it is I think we'd have a tough time getting clients to pay the license fee - perhaps if bundled with something like EC2 instances with a smaller incremental cost then it may be more palletable and help to increase adoption (it may be that Infobright have lots of customers with open wallets - in which case please share them!). In terms of immediate ease of use, with some visible performance improvements, Infobright fits the bill - but until i've had a chance to compare MonetDB and Infobright in a bit more detail then i'll reserve my final judgement!

Discuss this entry

InfiniDB, Infobright and MonetDB - Day 2: Infobright

Day 2 of my tour of column based storage brings me on to Infobright Community Edition (ICE). The first impressive point was that based on my blog post of yesterday then I already had an email from Mark in Community Relations at Infobright offering help and advice - despite me calling him the wrong name (I was having a bad day!) then he was immediately helpful and also offered to get some of his team to look into my queries.

As an aside, John from Calpont was also kind enough to drop by to respond to some of my points - to me this gives me a warm fuzzy feeling that both Infobright and Calpont are taking the community seriously - I guess for these products to gain traction they need to make sure people can get motoring with them to improve adoption.

Read more of this entry

InfiniDB, Infobright and MonetDB - Day 1: InfiniDB

We're taking a whistlestop tour of some of the column based storage systems out there for a project we're working on (where the use case seems to fit better with this form of storage rather than straight MySQL). After reading through the series of articles on the MySQL Performance Blog then we chose to look at InfiniDB, Infobright and MonetDB - with the two that talk MySQL coming first for ease of integration right now. I'm also going to do this as a three parter - so first up is InfiniDB.

Read more of this entry

Protecting your Paperclip downloads

Way back last November when I first blogged about Paperclip I included a brief mention of hiding files behind a controller rather than simply putting them in the public directory for all to see. Since then I’ve noticed that the question of how to actually do this has come up regularly over on Rails Forum and a couple of weeks ago I had to figure out how to update some of our code to protect assets that we had migrated from local file system to Amazon S3 storage. So I figured it’s probably a worthwhile technique to share.

Read more of this entry

Bugmash!

Picture of a masher mashing a bugWell it’s day two of the first ever Rails BugMash and so far I’ve managed to score a sneaky 1,000 points just by updating my one-line binary fixtures test patch. Meanwhile Matt Duncan and Rizwan Reza are on fire with 4,350 and 4,000 points at the time of writing.

Unfortunately the event has coincided with what may be the only nice weekend of the Great British summer, so I’ve been torn between the chance to mash bugs or to enjoy the sunshine. I’m currently trying to combine the two sat out in the garden squinting to see my laptop screen in the glare of the sun!

My next attempt to score some points is an updated patch, now improved and including a test case, for a lack of quoting of aliased table names in SQL joins which has been (too eagerly) marked as resolved even though it’s still broken. If you get the opportunity please do take a look and comment on the ticket as it’d be nice to get it fixed.

After that, I’m hoping to try and sneak my patch for anonymous extension modules for belongs_to and has_one associations into the bugmash as it has been sat on Lighthouse since March and already has three +1s. Even if it isn’t eligible for the bugmash, I still think it’s a worthy patch so again please take a look and comment on the ticket if you get chance.

And of course there are still plenty more tickets tagged with bugmash to be looked at so even if you’ve never contributed to Rails before, now is a pretty good time to start!

Discuss this entry

Thin, Rails 1.2.3/1.2.6 and ActionController::Dispatcher (NameError)

Please note: This patch has now been applied to the Thin master repository so will be fixed in all future releases.

Whilst trying to get an old Rails app up and running with Thin (Gem version 1.2.2) then I encountered a spot of bother:

load_missing_constant: uninitialized constant ActionController::Dispatcher (NameError)

Read more of this entry

Using SQLite3 and MySQL on Windows

Way back in 2007, Rails 2.0.2 changed the default database from MySQL to SQLite3, making it easier for newcomers to get up and running with Rails quickly without having to worry about setting up a database. Unfortunately for Windows users, trying to install the SQLite3 gem with gem install sqlite3-ruby will result in the following error:

Building native extensions.  This could take a while…
ERROR:  Error installing sqlite3-ruby:
        ERROR: Failed to build gem native extension.

Read more of this entry

Accessing column information with ActiveRecord

A quick tip - ActiveRecord provides a number of methods that allow you to access information about the underlying table columns for a model.

Read more of this entry

Recent entries

Archives

  1. August 2010
  2. July 2010
  3. April 2010
  4. January 2010
  5. November 2009
  6. September 2009
  7. August 2009
  8. July 2009
  9. June 2009
  10. May 2009
  11. April 2009
  12. March 2009
  13. February 2009
  14. December 2008
  15. November 2008
  16. September 2008
  17. August 2008
  18. July 2008
  19. June 2008
  20. May 2008
  21. April 2008
  22. March 2008
  23. February 2008
  24. January 2008
  25. December 2007
  26. November 2007

Tags

  1. actioncontrollerdispatcher (nameerror)
  2. actionview
  3. active messaging
  4. activerecord
  5. activesupport
  6. actverecord
  7. aes
  8. aggregation
  9. ajax
  10. akismet
  11. amazon
  12. amazon sqs
  13. ami
  14. apache
  15. api
  16. apple
  17. apr
  18. apr-util
  19. async
  20. attachments
  21. attachment_fu
  22. attr_accessible
  23. auto scaling
  24. autotest
  25. availability
  26. aws
  27. backgroundrb
  28. beanstalkd
  29. bindings
  30. bj
  31. block
  32. branding
  33. buckets
  34. bug
  35. bugmash
  36. cache
  37. caching
  38. callbacks
  39. cancer research uk
  40. cdn
  41. centos
  42. charity
  43. cloud
  44. cloudfront
  45. clusters
  46. column information
  47. columns
  48. community
  49. company name
  50. compatibility
  51. compiler
  52. composed_of
  53. consultancy
  54. content
  55. content delivery
  56. controller
  57. convert
  58. cookies
  59. csrf
  60. css
  61. data warehouse
  62. database
  63. dates
  64. defensio
  65. deployment
  66. design
  67. development
  68. dhtml
  69. docrails
  70. documentation
  71. donations
  72. drdb
  73. duplicate key
  74. ebs
  75. ec2
  76. elastic
  77. elastic block store
  78. elastic load balancing
  79. encoding
  80. encryption
  81. erb
  82. error
  83. european
  84. events
  85. ezcrypto
  86. facebook
  87. fckeditor
  88. feedburner
  89. feeds
  90. ffmpeg
  91. filter
  92. fixes
  93. flash
  94. flickr
  95. flickr api
  96. flickr_fu
  97. fuse
  98. geekup
  99. gems
  100. geocode
  101. git
  102. github
  103. god
  104. great south run
  105. greenplum
  106. growl
  107. hacker
  108. haml
  109. haproxy
  110. helper
  111. hmac
  112. holiday
  113. hooks
  114. hosting
  115. howto
  116. hpricot
  117. html
  118. identity
  119. imagemagick
  120. imagescience
  121. infinidb
  122. infiniteftp
  123. infobright
  124. init.d
  125. insert
  126. invalid authenticity token
  127. italy
  128. javascript
  129. jquery
  130. json
  131. leeds media
  132. limit
  133. linkrenderer
  134. linux
  135. load balancing
  136. logo
  137. mac
  138. markaby
  139. mass-assignment
  140. memcached
  141. mephisto
  142. messaging
  143. middleware
  144. migrate
  145. migration
  146. model
  147. mod_rails
  148. mod_ruby
  149. monetdb
  150. mongrel
  151. mongrel_cluster
  152. monit
  153. monitoring
  154. mootools
  155. mp3
  156. mq
  157. multiple gems
  158. multiselect
  159. mysql
  160. neon
  161. new site
  162. nginx
  163. observer
  164. offset
  165. open source
  166. opensolaris
  167. openssl
  168. optimisation
  169. pagination
  170. paperclip
  171. parameters
  172. params
  173. passenger
  174. patch
  175. performance
  176. permanentredirect
  177. persistence
  178. persistent storage
  179. persistentfs
  180. php
  181. phusion
  182. plugin
  183. plugins
  184. post commit
  185. post-commit
  186. protomultiselect
  187. prototype
  188. query
  189. queues
  190. quotes
  191. race for life
  192. rack
  193. rails
  194. rails development
  195. rails patch
  196. rails plugin
  197. rails-doc
  198. rails3
  199. rake
  200. refresh
  201. renderer
  202. respond_to
  203. rich text editor
  204. rmagick
  205. ruby
  206. ruby on rails
  207. rubyinline
  208. running
  209. rvideo
  210. s3
  211. s3fs. elasticdrive
  212. scaling
  213. schema
  214. schwarzenegger
  215. scm
  216. security
  217. services
  218. session
  219. shorthand
  220. snarl
  221. social
  222. solaris
  223. spam filter
  224. sparrow
  225. specify
  226. sponsorship
  227. sql
  228. sqlite3
  229. sql_logging
  230. starling
  231. starter kit
  232. storage
  233. streaming
  234. subversion
  235. sue ryder care
  236. survey
  237. svn
  238. swfupload
  239. swig
  240. sysadmin
  241. tables
  242. tamper
  243. templates
  244. the webfellas
  245. thewebfellas
  246. thin
  247. thumbnail
  248. time zone
  249. tinymce
  250. tip
  251. tips
  252. to-done
  253. training
  254. transcoding
  255. twitter
  256. tzinfo
  257. uk
  258. uk rails
  259. unsigned
  260. update
  261. uploads
  262. url
  263. validation
  264. version
  265. video
  266. view
  267. vmdk
  268. vmware
  269. webfellas
  270. webfellows
  271. wedding
  272. welcome
  273. widgeditor
  274. will_paginate
  275. win32
  276. windows
  277. wysiwyg
  278. xen
  279. xhtml
  280. xvm
  281. youtube
  282. zenoss
  283. zentest
  284. zfs

Flickr snaps