Instrumenting ActiveRecord associations

I may have fallen into Knuth's fundamental warning and optimized
prematurely.

My database has various foreign keys which are there to try and speed
things
up but they take time to maintain as well. Now I'm wondering if they
are worth the time to maintain verses the time they save.

Does anyone know of a GEM that instruments ActiveRecord? For example,
it could increment a counter per association each time it is traversed
(used) and a different counter each time it is assigned. And then some
way to cause these counters to be dumped out and reset at the end of
some length of time like a day or a week.

Seems like it would be rather easy to implement and handy to have.

Thank you,
pedz

I may have fallen into Knuth's fundamental warning and optimized
prematurely.

My database has various foreign keys which are there to try and speed
things
up but they take time to maintain as well. Now I'm wondering if they
are worth the time to maintain verses the time they save.

Does anyone know of a GEM that instruments ActiveRecord? For example,
it could increment a counter per association each time it is traversed
(used) and a different counter each time it is assigned. And then some
way to cause these counters to be dumped out and reset at the end of
some length of time like a day or a week.

I don't know of any gem that does that but I think that if you were to do such monitoring you would be better of doing it at the database level than at the active record level - I'd start by looking for profiling tools for your database

If all you've done is add foreign keys to your various _id columns it feels unlikely that you'd have too many indices. Plus, full table scans really really suck unless your tables are really tiny (and if they are that tiny I wouldn't think you'd have performance reasons)
Foreign keys are also there for data integrity reasons, not just speed.

Fred