# Performance with many look-up tables

**URL:** <https://www.ruby-forum.com/t/performance-with-many-look-up-tables/78808>\
**Category:** Rails\
**Created:** [March 9, 2006, 12:27am UTC](https://www.ruby-forum.com/t/performance-with-many-look-up-tables/78808 "2006-03-09T00:27:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [March 9, 2006, 12:27am UTC](https://www.ruby-forum.com/t/performance-with-many-look-up-tables/78808/1 "2006-03-09T00:27:11Z")

</div>

Hi,  
I have an app - a first cut ROR - so it’s a bit of a mess. I’m now  
trying to clean it up. The app relies on a heap of look-up tables that  
are, by and large, static. I’m wondering where and how to initialise  
these collections once - so that I don’t have to keep hitting the  
database every time I start a new action.

Can I initialise the collections at the start of a session - say in the  
application controller - and have them persist for the whole session?

Cheers,  
Eric.

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [March 9, 2006, 4:32am UTC](https://www.ruby-forum.com/t/performance-with-many-look-up-tables/78808/2 "2006-03-09T04:32:10Z")

</div>

Eric S. wrote:

> Hi,  
> I have an app - a first cut ROR - so it’s a bit of a mess. I’m now  
> trying to clean it up. The app relies on a heap of look-up tables that  
> are, by and large, static. I’m wondering where and how to initialise  
> these collections once - so that I don’t have to keep hitting the  
> database every time I start a new action.
> 
> Can I initialise the collections at the start of a session - say in the  
> application controller - and have them persist for the whole session?

If the lookup tables are application-wide (ie, they don’t rely on userA  
being logged in with a  
session) you can stored them in a class variable on your controller.  
During the dispatch.fcgi  
process existance they will exist. For each new dispatch.fcgi process  
that starts up, it will  
require to load the lookup table information. This is probably your  
optimal solution.

You don’t want to store them in an instance variable on the controller  
though because for each new  
request you will be getting new instances of your controllers.

If you have alot of data in your lookup tables and you don’t want to  
have to keep the same data  
around for every dispatch.fcgi process running you can you could create  
a UNIXSocket server where  
you house the data, and have your controller’s communicate to that via  
UNIXSocket Although this may  
be overkill. =) For cross-platform compatibility you could use a TCP  
Server, and connect via a  
TCPSocket, but that up to you!

Zach

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [March 9, 2006, 7:15am UTC](https://www.ruby-forum.com/t/performance-with-many-look-up-tables/78808/3 "2006-03-09T07:15:29Z")

</div>

zdennis wrote:

> If you have alot of data in your lookup tables and you don’t want to  
> have to keep the same data around for every dispatch.fcgi process  
> running you can you could create a UNIXSocket server where you house the  
> data, and have your controller’s communicate to that via UNIXSocket  
> Although this may be overkill. =) For cross-platform compatibility you  
> could use a TCP Server, and connect via a TCPSocket, but that up to you!

Or, as someone on the list pointed out to me a while back, you can use  
DRb[1] to make the  
static data available to all your processes.

b

[1][http://www.chadfowler.com/ruby/drb.html](http://www.chadfowler.com/ruby/drb.html)

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [March 10, 2006, 7:13am UTC](https://www.ruby-forum.com/t/performance-with-many-look-up-tables/78808/4 "2006-03-10T07:13:08Z")

</div>

Thanks Guys for the responses - I kinda assumed this would be a trivial  
question (and probably is) but I obviously have a lot to think through  
here. I’m temptd by the Drb solution, but I wonder if this has  
maintenance implications down the track. If I go with the  
@@class\_variables do I have a load once per session outcome?

I’m a little new at this web programming gig, so forgive my ignorance.  
CHeers,  
Eric.

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [March 10, 2006, 9:29am UTC](https://www.ruby-forum.com/t/performance-with-many-look-up-tables/78808/5 "2006-03-10T09:29:04Z")

</div>

You could also have a look at the enumerations plugin

[http://www.somethinglearned.com/articles/2005/10/25/announcement-new-rails-plugin](http://www.somethinglearned.com/articles/2005/10/25/announcement-new-rails-plugin)

Eric S. wrote:

> Ben M. wrote:
> 
> > 
> 
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Mike G. email : removed\_email\_address@domain.invalid  
Technical Director fax : +353 68 470 01  
XL CRS mobile: +353 87 677 2055  
Lisselton phone : +353 68 470 10  
Listowel  
Co. Kerry MSM : removed\_email\_address@domain.invalid  
Ireland Y!M : removed\_email\_address@domain.invalid
