Scaling and class methods

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?

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
[email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)

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
[email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)

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
[email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)