# Scaling and class methods

**URL:** <https://www.ruby-forum.com/t/scaling-and-class-methods/74037>\
**Category:** Rails\
**Created:** [October 29, 2006, 11:24am UTC](https://www.ruby-forum.com/t/scaling-and-class-methods/74037 "2006-10-29T11:24:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [October 29, 2006, 11:24am UTC](https://www.ruby-forum.com/t/scaling-and-class-methods/74037/1 "2006-10-29T11:24:44Z")

</div>

This is a generic question but I’ll use Globalize as the example. On  
each page request a class method is called on Locale to set the page  
locale from the url - eg …/en/index… would be en=english. I later  
perform some application specific logic based on the value of the Locale  
class.

Now if two people are hitting the webserver at the same time are their  
Locales going to get intertwined? Or does a seperate class get created  
for every visitor?

---

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [October 29, 2006, 8:57pm UTC](https://www.ruby-forum.com/t/scaling-and-class-methods/74037/2 "2006-10-29T20:57:44Z")

</div>

On Oct 29, 2006, at 2:24 AM, George P. wrote:

> Locales going to get intertwined? Or does a seperate class get  
> created  
> for every visitor?

Hey George-

```
A new controller class is instantiated for each request. But class

```

variables are global for the whole inheritance chain of classes that  
contain them. And rails is not thread safe so there is always a mutex  
that ensures that only one request is ever running through the rails  
dispatcher at once. So as long as you make absolutely certain that  
the @@classvariable gets set on each and every request, you will not  
run into any problems.

Cheers-  
– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [October 29, 2006, 9:12pm UTC](https://www.ruby-forum.com/t/scaling-and-class-methods/74037/3 "2006-10-29T21:12:59Z")

</div>

Awesome thanks Ezra, the class variable is always set on each request.  
If you’re running say 20 FastCGI proccesses do they each run their own  
ruby instance or are they all using one ruby instance with locking as  
you described?

Just checked out your hosting btw - looks pretty good!

Ezra Z. wrote:

> On Oct 29, 2006, at 2:24 AM, George P. wrote:
> 
> > Locales going to get intertwined? Or does a seperate class get  
> > created  
> > for every visitor?
> 
> Hey George-
> 
> A new controller class is instantiated for each request. But class  
> variables are global for the whole inheritance chain of classes that  
> contain them. And rails is not thread safe so there is always a mutex  
> that ensures that only one request is ever running through the rails  
> dispatcher at once. So as long as you make absolutely certain that  
> the @@classvariable gets set on each and every request, you will not  
> run into any problems.
> 
> Cheers-  
> – Ezra Z.  
> – Lead Rails Evangelist  
> – removed\_email\_address@domain.invalid  
> – Engine Y., Serious Rails Hosting  
> – (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [October 29, 2006, 11:26pm UTC](https://www.ruby-forum.com/t/scaling-and-class-methods/74037/4 "2006-10-29T23:26:02Z")

</div>

Hi~

On Oct 29, 2006, at 12:12 PM, George P. wrote:

> Awesome thanks Ezra, the class variable is always set on each request.  
> If you’re running say 20 FastCGI proccesses do they each run their own  
> ruby instance or are they all using one ruby instance with locking as  
> you described?

Yes, each fcgi or mongrel backend runs a copy of rails in its own  
ruby process/interpreter.

> Just checked out your hosting btw - looks pretty good!

Thanks!

– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)
