On Thu, 15 Dec 2005, Mariano K. wrote:
Hi,
I am from a Java background and pretty new to Ruby and Rails.
What I am wondering is how I would shared state accross requests and users
without involving IO, i.e. use memory.
there are several ways, not all related to rails:
- use the database. a good db running on a box with battery backed
ram is
not goint to hit disk that often. even when it does, caching is
the job
of the database.
- use shared memory. using systemvipc in ruby is trivial.
- use memory. if you have fastcgi configured for session affinity
you can
ensure that all request travel to the same fastcgi process which,
just in
case you didn’t know, are persistent. therefore a simple
variable can
persist data between requests.
- use drb. this elimiates the need for session affinity and makes
your data
available even after the web servers has stopped and restarted.
if drb
uses a unix domain socket the data exchange is very fast, adding
only a
small memcopy in kernel space.
My current understanding is that for each request a new process ist spawn
and therefore it gets its own memory. So no sharing can take place between
requests?
nope. fastcgi is persistent - http://fastcgi.com.
Do I understand this right? For those who know Java, let me rephrase that
to prevent missunderstandings?
Is there any equivalent to using the Application Context in J2EE, a
Singleton or static class members to store objects?
the simple answer is that, under fastcgi, ALL classes have this
ability.
kind regards.
-a