If I have a singleton class (by using the Singleton mixin), I understand
it’s thread-safe in that it ensures only a single instance of this class
will be created (by putting a mutex around the instance method). BUT
(in theory), the instance methods of my singleton instance could be
accessed concurrently by various threads, thus causing a concurrency
BUT Rails is essentially single-threaded (only a single request
processed at a time), so if I have only a single call to my singleton
instance method per http request, then it should be impossible to get
concurrency problems with it. Right?
If I have a cluster 4 servers, then I could have as many as 4 instances
of my singleton created. But that’s OK – each instance will have its
own io it writes to. What I don’t want is 20 requests coming in at the
same time and all trying to use the singleton to write at the exact same
Are my questions clear enough to answer?