unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* Memcache reset on rails 2.3 with preload
@ 2011-03-10 17:16 Troex Nevelin
  2011-03-10 20:48 ` Clifton King
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Troex Nevelin @ 2011-03-10 17:16 UTC (permalink / raw)
  To: mongrel-unicorn

What is a right code for resetting memcache connection in after_fork for 
Rails 2.3 with "preload_app true" on REE?

The only configurations about memcache in my app are:

config/initializers/session_store.rb:
ActionController::Base.session_store = :mem_cache_store

config/environment.rb:
config.cache_store = :mem_cache_store


I tried:
Rails.cache.reset

But it fails to start, looks like this code is for Rails3 only
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Memcache reset on rails 2.3 with preload
  2011-03-10 17:16 Memcache reset on rails 2.3 with preload Troex Nevelin
@ 2011-03-10 20:48 ` Clifton King
  2011-03-10 21:23 ` Eric Wong
  2011-03-10 22:01 ` Lawrence Pit
  2 siblings, 0 replies; 6+ messages in thread
From: Clifton King @ 2011-03-10 20:48 UTC (permalink / raw)
  To: unicorn list

I opt to use this gem: https://github.com/fauna/memcached

I use the following settings in my environment:

  $memcached         = Memcached::Rails.new(cache_server,
                                            :namespace       => "os-",
                                            :tcp_nodelay     => true,
  # disable nagle algorithm
                                            :no_block        => true)
  # dont block on writes

ActionController::Base.cache_store                = :mem_cache_store, $memcached
  $session_memcached = Memcached::Rails.new(cache_server,
                                            :namespace       => "os-",
                                            :tcp_nodelay     => true,
  # disable nagle algorithm
                                            :no_block        => true)
  ActionController::Base.cache_store                =
:mem_cache_store, $memcached
  ActionController::Base.session_store              = :mem_cache_store
  ActionController::Base.session_options[:cache]    = $session_memcached


in after_fork i have

$memcached.reset
$session_memcached.reset


Clifton

On Thu, Mar 10, 2011 at 11:16 AM, Troex Nevelin <list@mrtech.ru> wrote:
> What is a right code for resetting memcache connection in after_fork for
> Rails 2.3 with "preload_app true" on REE?
>
> The only configurations about memcache in my app are:
>
> config/initializers/session_store.rb:
> ActionController::Base.session_store = :mem_cache_store
>
> config/environment.rb:
> config.cache_store = :mem_cache_store
>
>
> I tried:
> Rails.cache.reset
>
> But it fails to start, looks like this code is for Rails3 only
> _______________________________________________
> Unicorn mailing list - mongrel-unicorn@rubyforge.org
> http://rubyforge.org/mailman/listinfo/mongrel-unicorn
> Do not quote signatures (like this one) or top post when replying
>
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Memcache reset on rails 2.3 with preload
  2011-03-10 17:16 Memcache reset on rails 2.3 with preload Troex Nevelin
  2011-03-10 20:48 ` Clifton King
@ 2011-03-10 21:23 ` Eric Wong
  2011-03-10 22:14   ` Clifton King
  2011-03-10 22:01 ` Lawrence Pit
  2 siblings, 1 reply; 6+ messages in thread
From: Eric Wong @ 2011-03-10 21:23 UTC (permalink / raw)
  To: unicorn list

Troex Nevelin <list@mrtech.ru> wrote:
> What is a right code for resetting memcache connection in after_fork for  
> Rails 2.3 with "preload_app true" on REE?
>
> The only configurations about memcache in my app are:
>
> config/initializers/session_store.rb:
> ActionController::Base.session_store = :mem_cache_store
>
> config/environment.rb:
> config.cache_store = :mem_cache_store

So that uses the memcache-client gem?  I seem to remember that (and
dalli) only connects when it's needed, but I suppose some apps use
memcached at load time.

The following should work, not the most elegant:

  before_fork do |server,worker|
    ObjectSpace.each_object(MemCache) { |mc| mc.reset }
  end

An after_fork would probably send unnecessary messages to the memcached
servers.

> I tried:
> Rails.cache.reset
>
> But it fails to start, looks like this code is for Rails3 only

Hopefully somebody else knows a more elegant way to handle this.

-- 
Eric Wong
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Memcache reset on rails 2.3 with preload
  2011-03-10 17:16 Memcache reset on rails 2.3 with preload Troex Nevelin
  2011-03-10 20:48 ` Clifton King
  2011-03-10 21:23 ` Eric Wong
@ 2011-03-10 22:01 ` Lawrence Pit
  2011-03-23 18:25   ` Troex Nevelin
  2 siblings, 1 reply; 6+ messages in thread
From: Lawrence Pit @ 2011-03-10 22:01 UTC (permalink / raw)
  To: unicorn list; +Cc: Troex Nevelin


I use:

if Rails.cache.is_a?(ActiveSupport::Cache::MemCacheStore)
   Rails.cache.instance_variable_get(:@data).reset
end



Cheers,
Lawrence

> What is a right code for resetting memcache connection in after_fork 
> for Rails 2.3 with "preload_app true" on REE?
>
> The only configurations about memcache in my app are:
>
> config/initializers/session_store.rb:
> ActionController::Base.session_store = :mem_cache_store
>
> config/environment.rb:
> config.cache_store = :mem_cache_store
>
>
> I tried:
> Rails.cache.reset
>
> But it fails to start, looks like this code is for Rails3 only
> _______________________________________________
> Unicorn mailing list - mongrel-unicorn@rubyforge.org
> http://rubyforge.org/mailman/listinfo/mongrel-unicorn
> Do not quote signatures (like this one) or top post when replying
>

_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Memcache reset on rails 2.3 with preload
  2011-03-10 21:23 ` Eric Wong
@ 2011-03-10 22:14   ` Clifton King
  0 siblings, 0 replies; 6+ messages in thread
From: Clifton King @ 2011-03-10 22:14 UTC (permalink / raw)
  To: unicorn list

Eric,

No, I'm using the "memcached" gem which has a binding for libmemcached
(and is much faster than the memcache-client gem).

The memcached gem has a compatibility wrapper (Memcached::Rails) which
is made to be backwards compatible with memcache-client.

Clifton

On Thu, Mar 10, 2011 at 3:23 PM, Eric Wong <normalperson@yhbt.net> wrote:
> Troex Nevelin <list@mrtech.ru> wrote:
>> What is a right code for resetting memcache connection in after_fork for
>> Rails 2.3 with "preload_app true" on REE?
>>
>> The only configurations about memcache in my app are:
>>
>> config/initializers/session_store.rb:
>> ActionController::Base.session_store = :mem_cache_store
>>
>> config/environment.rb:
>> config.cache_store = :mem_cache_store
>
> So that uses the memcache-client gem?  I seem to remember that (and
> dalli) only connects when it's needed, but I suppose some apps use
> memcached at load time.
>
> The following should work, not the most elegant:
>
>  before_fork do |server,worker|
>    ObjectSpace.each_object(MemCache) { |mc| mc.reset }
>  end
>
> An after_fork would probably send unnecessary messages to the memcached
> servers.
>
>> I tried:
>> Rails.cache.reset
>>
>> But it fails to start, looks like this code is for Rails3 only
>
> Hopefully somebody else knows a more elegant way to handle this.
>
> --
> Eric Wong
> _______________________________________________
> Unicorn mailing list - mongrel-unicorn@rubyforge.org
> http://rubyforge.org/mailman/listinfo/mongrel-unicorn
> Do not quote signatures (like this one) or top post when replying
>
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Memcache reset on rails 2.3 with preload
  2011-03-10 22:01 ` Lawrence Pit
@ 2011-03-23 18:25   ` Troex Nevelin
  0 siblings, 0 replies; 6+ messages in thread
From: Troex Nevelin @ 2011-03-23 18:25 UTC (permalink / raw)
  Cc: unicorn list

On 03/11/2011 01:01 AM, Lawrence Pit wrote:
> I use:
>
> if Rails.cache.is_a?(ActiveSupport::Cache::MemCacheStore)
> Rails.cache.instance_variable_get(:@data).reset
> end

Thanks a lot, that is exactly what I needed
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-03-23 20:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-10 17:16 Memcache reset on rails 2.3 with preload Troex Nevelin
2011-03-10 20:48 ` Clifton King
2011-03-10 21:23 ` Eric Wong
2011-03-10 22:14   ` Clifton King
2011-03-10 22:01 ` Lawrence Pit
2011-03-23 18:25   ` Troex Nevelin

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).